mov r0, #smallNumber // Store smallNumber into register r0 |
mov r0, r1 // Copy r1 to r0 // I.e.: assign r0 = r1 |
You can use any register for r0 and r1.
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 |