Академический Документы
Профессиональный Документы
Культура Документы
Problem 1
25 points
_______________________________
Problem 2
30 points
_______________________________
Problem 3
20 points
_______________________________
Problem 4
25 points
_______________________________
Total
100 points
_______________________________
Page 2
Name: ____________________________________________
Part C (5 points): Explain why R7 must be caller-saved for any LC-3 subroutine.
(Recall that caller-saved implies that the subroutine can change the value.)
AND
R1, R1,
ADD
R0, R0,
BRn
DONE
ADD
R0, R0,
ADD
R1, R1,
BRnzp LOOP
HALT
#0
#0
R0
#1
Part D (5 points): For what value or values of register R0 does the code not reach the
HALT instruction?
Page 3
Name: ____________________________________________
Content
x3015
x1DBF
x3016
x7180
x3017
xF020
x3018
x6F80
x3019
x7180
x301A
x11E0
RTL
Part B (10 points): The table below shows the values in certain registers before
execution of the code in Part A. Fill in the values for all registers after the six
instructions execute. Do NOT leave blank entries; you may write unknown if the
contents of a register cannot be known.
Register
Before
PC
x3015
MAR
unknown
MDR
unknown
R0
x5678
R1
x2345
R6
xC234
R7
xABCD
After
Part C (10 points): In 25 words or less, explain what the code in Part A does.
Page 4
Name: ____________________________________________
R7,SAVE_R7
R1,SAVE_R1
R1,NEG_0
R0,R0,R1
MAYBE_OK
R0,R0,#0
R0,R0,#-1
DONE
R1,R0,#-10
DONE
R1,DIFF0A
R0,R0,R1
BAD_KEY
R1,R0,#-6
BAD_KEY
R0,R0,#10
R1,SAVE_R1
R7,SAVE_R7
1
1
xFFD0
xFFEF
Part A (5 points): Explain why the value in R7 is saved to memory and later copied back
into R7.
Part B (5 points): The subroutine returns a value in R0. What value is returned in R0 if
the user presses the letter A during the GETC trap?
Part C (5 points): How many different values can be returned in R0? (For example, if
R0 were always either 3 or 10 when the subroutine returned, the answer would be 2.)
Page 5
Name: ____________________________________________
Part B (10 points): What is the value of x right before main returns?
0001
DR
SR1
0 00
SR2
LD
0001
DR
0101
DR
SR1
imm5
LDI
0101
DR
SR1
0 00
SR2
LDR
0000
n z p
SR1
imm5
LEA
1100
000
PCoffset9
BaseR
BR{nzp} PCoffset9
NOT
0100
000000
JMP BaseR
ST
1111
PCoffset11
0000
PCoffset9
0110
DR
BaseR
offset6
1110
DR
PCoffset9
1001
DR
SR
111111
NOT DR, SR
0011
SR
PCoffset9
ST SR, PCoffset9
M[PC + SEXT(PCoffset9)] SR
JSR PCoffset11
STI
R7 PC, PC PC + SEXT(PCoffset11)
TRAP
DR
PC BaseR
JSR
1010
DR PC + SEXT(PCoffset9), Setcc
LD DR, PCoffset9
PCoffset9
DR
0010
trapvect8
R7 PC, PC M[ZEXT(trapvect8)]
1011
SR
PCoffset9
M[M[PC + SEXT(PCoffset9)]] SR
TRAP trapvect8
STR
0111
SR
BaseR
offset6
M[BaseR + SEXT(offset6)] SR