bx lr vs ret

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

bx lr vs ret

2,629 Views
hajianik
Senior Contributor I

Hi,

Target is S32K148,Compiler is Green Hills

I've written the following C function:

void launch_flsh_com(void)
 {
#if 1
#pragma asm
  ;ldr     r1, =0x40020000    
   movw    r1,0x0000
   movt    r1,0x4002
  movs    r0, #128        ; 0x80
  strb    r0, [r1, #0]
  L1:
  ldrb    r0, [r1, #0]
  lsls    r0, r0, #24
  bpl     L1
  ;bx      lr
#pragma endasm
#endif

{

I looked at the list file for this and I notice there is a "ret" instruction at the end.AS you see I had to comment  "bx lr"

otherwise It generates an exception(I believe a hard fault) why do I need to comment that out?

is not true that PC(Return address) is pushed on the stack and pops back into PC?

if so why LR registered is used in the first place.

Has it to do something with the Thumb bit?

and why when I use it here it generates a hard fault exception?

when the "ret" is executed and PC is restored , isn't the thumb bit set?

Thanks,

Koorosh Hajiani  

Labels (1)
Tags (1)
0 Kudos
Reply
1 Reply

2,521 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi hajianik@gmail.com,

BX LR is the Return from function call.

What is the EXC_RETURN value in the LR?

What exception do you get (Fault Status Register (CSFR))?

But since there is the "ret instruction" which is not a Cortex M4F instruction, I would recommend contacting Green Hills.

BR, Daniel

0 Kudos
Reply