AnsweredAssumed Answered

bx  lr vs ret

Question asked by Koorosh Hajiani on Feb 7, 2020
Latest reply on Feb 11, 2020 by Daniel Martynek


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]
  ldrb    r0, [r1, #0]
  lsls    r0, r0, #24
  bpl     L1
  ;bx      lr
#pragma endasm


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?



Koorosh Hajiani