The following two problems in this exercise refer to a funct
The following two problems in this exercise refer to a function f that calls another function func. The code for C function func is already compiled in another module using the ARM calling convention from Figure 2.14. The function declaration for func is “int func(int a, int b);” and you can refer to “func” in your assembly code.
The code for function f is as follows:
a.
int f(int a, int b, int c){
return func(func(a,b),c);
}
b.
int f(int a, int b, int c){
return func(a,b)+func(b,c);
}
Translate function f into ARM assembler, also using the ARM calling convention from fig 2.14. If you need to use registers r4 to r11, use the lower-numbered registers first.
| a. | int f(int a, int b, int c){ return func(func(a,b),c); } |
| b. | int f(int a, int b, int c){ return func(a,b)+func(b,c); } |
Solution
a.
f:
push {r4,lr}
bl func
push {r3, lr}
bl func
pop {r4,pc}
b.
f:
push {r4, lr}
bl func
push {r3, lr}
bl func
add r4, r3
pop {r4,pc}

