bx lr vs ret

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

bx lr vs ret

4,896 次查看
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 回复

4,788 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi [email protected],

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 项奖励
回复