Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following high-level function. // C code int f(int n, int k) { int b; b = k + 2; if (n == 0)

image text in transcribedConsider the following high-level function.

// C code int f(int n, int k) { int b;

b = k + 2;

if (n == 0) b = 10;

else b = b + (n * n) + f(n 1, k + 1);

return b * k;

}

Translate the high-level function f into ARM assembly language. Pay particular attention to properly saving and restoring registers across function calls and using the ARM preserved register conventions. Clearly comment your code. You can use the ARM MUL instruction. The function starts at instruction address 0x00008100. Keep local variable b in R4.

Step through your function from part (a) by hand for the case of f(2, 4).

Draw a picture of the stack similar to the one in Figure 6.14, and assume that SP is equal to 0xBFF00100 when f is called. Write the register name and data value stored at each location in the stack and keep track of the stack pointer value (SP). Clearly mark each stack frame. You might also find it useful to keep track of the values in R0, R1, and R4 throughout execution. Assume that when f is called, R4 = 0xABCD and LR = 0x00008010. What is the final value of R0?

Exercise 6.34 Consider the following high-level function. I C code int f(intn, intk) int b if (n0) b 10; else b b (n * n)f(n-1, k+1); return b*k; 380 CHAPTER SIx Architecture (a) Translate the high-level function f into ARM assembly language. Pay parti- cular attention to properly saving and restoring registers across function calls and using the ARM preserved register conventions. Clearly comment your code. You can use the ARM MUL instruction. The function starts at instruc- tion address 0x00008100. Keep local variable b in R4. (b) Step through your function from part (a) by hand for the case of f(2, 4). Draw a picture of the stack similar to the one in Figure 6.14, and assume that SP is equal to 0xBFF00100 when f is called. Write the register name and data value stored at each location in the stack and keep track of the stack pointer value (SP). Clearly mark each stack frame. You might also find it useful to keep track of the values in RO, R1, and R4 throughout execution. Assume that when f is called, R4 = 0xABCD and LR 0x00008010. What is the final value of RO? Exercise 6.34 Consider the following high-level function. I C code int f(intn, intk) int b if (n0) b 10; else b b (n * n)f(n-1, k+1); return b*k; 380 CHAPTER SIx Architecture (a) Translate the high-level function f into ARM assembly language. Pay parti- cular attention to properly saving and restoring registers across function calls and using the ARM preserved register conventions. Clearly comment your code. You can use the ARM MUL instruction. The function starts at instruc- tion address 0x00008100. Keep local variable b in R4. (b) Step through your function from part (a) by hand for the case of f(2, 4). Draw a picture of the stack similar to the one in Figure 6.14, and assume that SP is equal to 0xBFF00100 when f is called. Write the register name and data value stored at each location in the stack and keep track of the stack pointer value (SP). Clearly mark each stack frame. You might also find it useful to keep track of the values in RO, R1, and R4 throughout execution. Assume that when f is called, R4 = 0xABCD and LR 0x00008010. What is the final value of RO

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions