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);

}

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.

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}

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
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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site