|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
0
|
|
1
|
|
2
|
|
3
|
|
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, #4Note: 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, #3And 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