|
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, #1111 mov r1, #1111 bl myMethod mov r2, #2222 mov r3, #2222 myMethod: mov r8, #4444 mov r9, #4444 |
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:
|
How to run the program:
|
mov pc, lr Effect: Copy the return address saved by the bl instruction into the Program Counter (PC) |
Explanation:
|
main: mov r0, #4 mov r1, #4 bl myMethod mov r2, #4 mov r3, #4 bl myMethod mov r4, #4 mov r5, #4 myMethod: mov r10, #4 mov r9, #4 mov pc, lr // Return to caller !!! |
The main program calls the method myMethod twice.
In each call, the return address is saved in the lr register
So the mov pc, lr instruction in the myMethod function is able to jump back to the location where the function call took place !!!
How to run the program:
|
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) ... mov pc, lr |
The labels used to mark the beginning of functions/methods in assembler code are no different from the labels you used in if and while statements !!!
It's very hard to tell in assembler program which label to mark a method start location !!!
So it's a good practice to use comments, e.g.:
/* ************************************************** myMethod: this method wil do the following .... bla bla bla ... ************************************************** */ myMethod: ... ... (assembler instructions) ... mov pc, lr |