bx lr vs ret

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

bx lr vs ret

2,709件の閲覧回数
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  

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 返信

2,601件の閲覧回数
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 件の賞賛
返信