Homework #4 solution
1. We want to increase the number of registers that we can specify in the LC3 AND
instruction to 16. Do you see any problem with that? Explain.
Ans) YES, there’s a problem. Not enough bits in the instruction to have 4 bit registers.
2. Implement a XOR gate (A XOR B) using the LC3 instruction set.
Assume that the 2 numbers are given at R0 and R1. (Hint: Use DeMorgan’s Laws. LC3
doesn’t have an OR function)
A XOR B =
( AB’ + A’B) = (( AB’ + A’B)’)’ = ((AB’)’ * (A’B)’)’
A is in R0 and B is in R1
NOT R2,R0
; A’
NOT R3, R1
; B’
AND R4,R0,R3
; AB’
AND R5,R2,R1
;
A’B
NOT R4,R4
;(AB’)’
NOT R5,R5
; (A’B)’
AND R6,R4,R5
; (AB’)’ * (A’B)’
NOT R6,R6
; ((AB’)’ * (A’B)’)’
3. Write the condition code at the end of each instruction (assume the program starts
at memory location x3000):
Instruction
N
Z
P
Initial case 0 0 1
0
0
1
LEA R2, #100
0
0
1
LD R2, #0
You are loading
“ADD R3, R2,0x5”
into R2, so it should
be possitive
0
0
1
ADD R3, R2,0x5
0
0
1
ADD R4,R2,#11
0
0
1
AND R5,R5,#0
0
1
0
NOT R6, R5
R6 has 111111
1
0
0
ST R6, #200
1
0
0
Do the condition codes depend on the NZP values of the previous instructions?
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Yes.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '07
 Ambler
 SEPTA Regional Rail, #, Jaguar Racing, 3 bits, 4 bit, 6 bits

Click to edit the document details