0
I need some help about arm assembly
Hi, Can anyone help me, about lr? I understand the other think, but the lr is dont understandable for me. I think the I need to someone explain me all thing about functions And I dont understand the .balign 4 Why should I need to write 4? Because 32/8 = 4?
1 ответ
+ 2
about LR,
it stores the return address of a subroutine (function).
when you branch to a function its return address is stored in LR. if in that function you branch to another function, LR will be modified and you can't return to the execution after the first function because the first return address is modified by the second one.
example :
bl myfun1
<--- the return from myfun1 returns here
myfun1:
"do something"
branch to another function inside myfun1 . so you need to save the first LR value.
stmdb sp!,{rxx,rx,lr} //save 1st LR
bl myfun2 <-- this modifies LR, if you didnt save LR you wouldn't be able to return from myfun1.
<---- myfun2 returns here
after myfun2 is done restore LR to be able to return from myfun1
mov pc,lr
other implementation would just store the return address on the stack instead of a register.
but using a register is more efficient than accessing the stack.