|
bl label Effect: (1) Save the Program Counter (PC) in the Link Register (LR) (2) Branch to memory location marked by the label "label" |
Explanation:
|
main: mov r0, #4 mov r1, #4 bl myMethod mov r2, #4 mov r3, #4 myMethod: mov r10, #4 mov r9, #4 |
I will use EGTAPI in class to show you the executing.
I have taken some snapshot of the execution for my notes.
The content of the registers at the moment the ARM processor executes the bl instruction is as follows:
Notice that PC = 33280 which is the location of the "bl myMethod" instruction
The "bl myMethod" instruction will call (= run, jump) the myMethod function which is located at address 33292 as given by EGTAPI:
When we click STEP and execute the "bl myMethod" in EGTAPI, we will see these values in the registers:
Notice that:
|
mov pc, lr Effect: Copy the return address saved by the bl instruction into the Program Counter (PC) |
Memory Instruction Address: in the memory address: --------- ----------------------- 2244: BSR label 2246: MOVE.L #0, Dummy1 4012: label: MOVE.L #0, Dummy2 4014: RTS |
PC = 4012 +---------------+ A7 = 9996 | | +---------------+ | | +---------------+ A7 --> 9996 | 2246 | +---------------+ 10000 | xxxxxxxx | |
Suppose the CPU fetched "RTS" and executes it...
AFTER the CPU finishes executing "RTS", the stack will be changed to:
PC = 2246 +---------------+ A7 = 10000 | | +---------------+ | | +---------------+ 9996 | 2246 | <- NOT part of the stack ! +---------------+ A7 -->10000 | xxxxxxxx | |
Note that the value 2246 which was at the top of the stack is now in the PC !!!
Note also that the value 2246 is the location AFTER the BSR instruction !!!
Becasue PC = 2246, the next instruction that the CPU will fetch and execute is the one after the BSR instruction !!
That is exactly the location where you want to be when you return from the called function !!!!
FuncName: ...... ...... (assembler instructions that comprise ...... the body of the function) ...... RTS |
Example:
public int myMethod ( int p1, int p2 ) { ... } |
You can see the method name and the curly braces { .. } that denote the start and the end of the method clearly
Methods (or subroutines) in assembler are nothing more than a series of instructions marked by a label
Example:
myMethod: ... ... (assembler instructions) ... |
It's very hard to tell in assembler program which label to mark a method start location !!!