Question: 1. (10 pts) Implement the following C code in MIPS assembly. Show the contents of the stack after the function call to the function compare


1. (10 pts) Implement the following C code in MIPS assembly. Show the contents of the stack after the function call to the function "compare" is made. Assume that the stack pointer is originally at address Ox7FFFFFFc. int compare (int a, int b) f if (sub (a, b) 0) return 1; else return 0 int sub (int a, int b) return a - b; 2. (10 pts) Implement the following C code in the table in MIPS assembly. Suppose that fib iter was called with n-4, show the contents of the stack after the function call to the function "fib iter" is made. Assume that the stack pointer is originally at address 0x7fffffc. int fib iter(int a, int b, int n) i if (n 0) return b; else return fib iter(atb, a, n-1); 3. (15 points) The following problems refer to a function f that calls another function func. The function declaration for func is "int func(int a, int b);". The code for function f is as follows: int f(int a, int b, int c) return func (func (a, b), c) a) Translate function f into MIPS assembly code, using the MIPS calling convention. If you need to use register $tO through $t7, use the lower-numbered registers first. b) Right before your function f of Problem 3 returns, what do you know about contents of registers Sra, and $sp? Keep in mind that we know what the entire function f looks like, but for function func we only know its declaration. 4. (15 points) The following problems refer to a function f that calls another function func. The function declaration for func is "int func(int a, int b);". The code for function f is as follows int f(int a, int b, int c) return func (a, b) + func (b, c) a) Translate function f into MIPS assembly code, using the MIPS calling convention. If you need to use register $tO through $t7, use the lower-numbered registers first. b) Right before your function f of Problem 4 returns, what do you know about contents of registers Sra, and $sp? Keep in mind that we know what the entire function f looks like, but for function func we only know its declaration. 5. (20 points) Write a program in MIPS assembly language to convert a positive integer decimal string to an integer. Your program should expect register Sa0 to hold the address of a null-terminated string containing some combination of the digits 0 though 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $vO. If a nondigit character appears anywhere in the string, your program should stop with the value -1 in register $vO 6. (20 points) Repeat problem 5 with convert a string of hexadecimal digits to an integer 1. (10 pts) Implement the following C code in MIPS assembly. Show the contents of the stack after the function call to the function "compare" is made. Assume that the stack pointer is originally at address Ox7FFFFFFc. int compare (int a, int b) f if (sub (a, b) 0) return 1; else return 0 int sub (int a, int b) return a - b; 2. (10 pts) Implement the following C code in the table in MIPS assembly. Suppose that fib iter was called with n-4, show the contents of the stack after the function call to the function "fib iter" is made. Assume that the stack pointer is originally at address 0x7fffffc. int fib iter(int a, int b, int n) i if (n 0) return b; else return fib iter(atb, a, n-1); 3. (15 points) The following problems refer to a function f that calls another function func. The function declaration for func is "int func(int a, int b);". The code for function f is as follows: int f(int a, int b, int c) return func (func (a, b), c) a) Translate function f into MIPS assembly code, using the MIPS calling convention. If you need to use register $tO through $t7, use the lower-numbered registers first. b) Right before your function f of Problem 3 returns, what do you know about contents of registers Sra, and $sp? Keep in mind that we know what the entire function f looks like, but for function func we only know its declaration. 4. (15 points) The following problems refer to a function f that calls another function func. The function declaration for func is "int func(int a, int b);". The code for function f is as follows int f(int a, int b, int c) return func (a, b) + func (b, c) a) Translate function f into MIPS assembly code, using the MIPS calling convention. If you need to use register $tO through $t7, use the lower-numbered registers first. b) Right before your function f of Problem 4 returns, what do you know about contents of registers Sra, and $sp? Keep in mind that we know what the entire function f looks like, but for function func we only know its declaration. 5. (20 points) Write a program in MIPS assembly language to convert a positive integer decimal string to an integer. Your program should expect register Sa0 to hold the address of a null-terminated string containing some combination of the digits 0 though 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $vO. If a nondigit character appears anywhere in the string, your program should stop with the value -1 in register $vO 6. (20 points) Repeat problem 5 with convert a string of hexadecimal digits to an integer
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
