0

This is an example assembly code:

     function0()
 0x0.mov r0, #1
 0x8.mov r1, #20
0x10.mov r2, #6
0x18.cmp r1, #16
0x20.b function1

     function1()
0x28.cmp r0, #1
0x30.b functionX

     functionX()
0x38.bx lr

As far as I know, function0 moved those values into the first 3 registers. In function1 no values were moved into registers.

What I don't understand is:

  1. after branching to function1 do registers r1 and r2 still have those values or those registers have been zeroed out?

  2. After branching to functionX, is the link register still the same as the one in function0?

1 Answer 1

0

It looks like you confuse between functions and blocks. It looks like what you call function0, function1 and functionX are in fact parts of the same function, and just different basic blocks within the function.

To your specific questions:

  1. Nothing changes r0, r1, and r2 between 0x20.b function1 and 0x28.cmp r0 #1. So yes, they still hold the values from what you called function0. There is nothing in the code, or in assembly as general that implicitly zero out all registers.

  2. This is the place where the lr is fetched, and jumped to - it is supposed to hold the value of the caller function - The instruction after the call to what you called function0. the lr didn't change between what you called function0, function1 and functionX.

2
  • Since you mentioned functions an blocks, would there be a difference if those functions were actually 3 different functions and not blocks from the same function?
    – Silent
    Oct 7, 2021 at 14:37
  • About the first question - there will be no difference. About the second - the lr will change on each call (assuming call instruction is used, instead of b) Oct 7, 2021 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.