18 points Suppose Bar has been called so that the state of the stack is as

# 18 points suppose bar has been called so that the

This preview shows page 4 - 6 out of 6 pages.

(18 points) Suppose Bar has been called so that the state of the stack is as shown below. Describe the state of the stack just before Foo deallocates locals and returns to Bar . Fill in the unshaded boxes to show Bar's and Foo's activation frames. Include a symbolic description and the actual value (in decimal) if known. For return addresses, show only the symbolic description; do not include a value. Label the frame pointer and stack pointer . Assume a 32-bit system and maintain word alignment. address description Value 9900 RA of Bar’s caller 9896 FP of Bar’s caller SP, Bar’s FP 9892 RV 9888 9884 9880 9876 9872 9868 9864 9860 9856 9852 9848 9844 9840 FP: ________ 9836 SP: ________ 9832 9828
5 ECE 2035 Programming HW/SW Systems Fall 2017 3 problems, 6 pages Exam Two 23 October 2017 Part B (22 points) Write MIPS code fragments to implement the subroutine Foo by following the steps below. Do not use absolute addresses in your code; instead, access variables relative to the frame pointer. Assume no parameters are present in registers (i.e., access all parameters from Foo ’s activation frame). You may not need to use all the blank lines provided. label instruction Comment Foo : # set Foo’s FP # allocate space for locals # initialize locals # if S[n] == 0 branch to End.   Be sure to use load/store byte for values of type char. # otherwise, do Then clauses: S[n] = *c; # n++; # return(n); (store return value, deallocate locals, and return) End:
6 ECE 2035 Programming HW/SW Systems Fall 2017 3 problems, 6 pages Exam Two 23 October 2017 MIPS Instruction Set (core) instruction example meaning arithmetic add add \$1,\$2,\$3 \$1 = \$2 + \$3 subtract sub \$1,\$2,\$3 \$1 = \$2 - \$3 add immediate addi \$1,\$2,100 \$1 = \$2 + sign_extend(100) add unsigned addu \$1,\$2,\$3 \$1 = \$2 + \$3 subtract unsigned subu \$1,\$2,\$3 \$1 = \$2 - \$3 add immediate unsigned addiu \$1,\$2,100 \$1 = \$2 + zero_extend(100) set if less than slt \$1, \$2, \$3 if (\$2 < \$3), \$1 = 1 else \$1 = 0 set if less than immediate slti \$1, \$2, 100 if (\$2 < 100), \$1 = 1 else \$1 = 0 set if less than unsigned sltu \$1, \$2, \$3 if (\$2 < \$3), \$1 = 1 else \$1 = 0 set if < immediate unsigned sltui \$1, \$2, 100 if (\$2 < 100), \$1 = 1 else \$1 = 0 multiply mult \$2,\$3 Hi, Lo = \$2 * \$3, 64-bit signed product multiply unsigned multu \$2,\$3 Hi, Lo = \$2 * \$3, 64-bit unsigned product

#### You've reached the end of your free preview.

Want to read all 6 pages?

• Spring '13
• Willis
• Lo, Arithmetic shift, Logical shift