The following two problems in this exercise refer to a function f that calls ano
ID: 3924509 • Letter: T
Question
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);
}
Preserved on call? no no yes no yes yes n.a Name Register number al-a2 a3-a4 v1-v8 Usage 0-1 2-3 4-11 12 13 14 15 Argument return result scratch register Argument/ scratch register Variables for local routine Intra-procedure-call scratch register Stack pointer Link Register (Return address) Program Counter FIGURE 2.14 ARM register conventions.Explanation / Answer
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}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.