EECS 284 - Winter 2000

Homework 4 Solutions

Problem 1.
 
LABEL
ADDRESS
TEST
x3004
FINISH
x300E
SAVE3
x300F
SAVE1
x3010
HELLO
X3011
ZERO
x3018
NINE
x3019
DIGIT
x301A
 

Problem 2.

a) calling
b) called
c) calling
d) called
e) calling

Problem 3.

a) x0020 (note: must be zero-extended and shown as 16-bits).
b) x0400
c) x3002 TRAP PUTS (or PUTS or TRAP x23) R1 = x0045
d) 50 words
e) 13 words
f) The desired offset in the subroutine's activation record is added to the total size of main's activation record to get the offset.

Problem 4.
 

a) No. The call to SR2 in SR1 erases the value of R7 that would have allowed a return to main. The solution is to save and restore R7 in SR1.

b)

return value
0
return address
1
dynamic link
2
i
3
j
4
 
c)
LDR R2, R6, #3
STR R2, R6, #8
STR R6, R6, #7
ADD R6, R6, #5
JSR SR1
LDR R6, R6, #2
LDR R3, R6, #5
STR R3, R6, #4

Note: Instead of R2 and R3 you can use any general purpose register except R6 and R7

The part before the JSR instruction, could be done as:

LDR R2, R6, #3
STR R6, R6, #7
ADD R6, R6, #5
STR R2, R6, #3

And the instruction that stores R6 can be anywhere before the ADD instruction.

The lines after the JSR, they could be done instead as :

LDR R3, R6, #0
LDR R6, R6, #2
STR R3, R6, #4