CS33 -- Lab 3
Due 11:59pm Thursday, Sept 16
email to me at: cfk@cs.swarthmore.edu a message in
text form (no word, html or any other format than
plain text) that contains labeled solutions to
the exercises below. Make the subject of the email:
cs33lab3. Make sure it is posted to me before
11:59 pm on Thursday, 16 Sep. Some of the solutions
will just be binary, hex, or decimal. Others may require
prose explanations.
For this lab assignment, feel free to work
with a partner.
Complete the following exercises from the textbook:
- 3.34
- 4.1
- 4.5
- 4.8
- 4.12 (with P&P phases)
- 5.4
- 5.8
- 5.12
- 5.14
- 5.15
- In class, we will write (or did write,
depending on when you read this) a little LC3
machine language program
to add the contents of memory location x3020 to the
contents of memory loc x3021 and put the result into
memory loc x3022. We used R4 as a base register and
put x3020 into R4 before executing our instructions
The program looked like:
;; before executing this program, put x3020 in R4
loc instruction comment
x3004 x6700 ;; R3 <-- M[R4+0]
x3005 x6501 ;; R2 <-- M[R4+1]
x3006 x1083 ;; R0 <-- R2+R3
x3007 x7102 ;; M[R4+2] <-- R0
I want you to write an LC3 machine language program
that subtracts the contents of memory loc x3021 from
the contents of memloc x3020 and puts the difference
in memloc x3022. Present it with comments as in
my little adding example above.
Hint: The LC3 does not have a subtract
instruction, nor does it have a 2's complement
instruction. It does, however, have a not and the
ability to add 1, so your program can compute the
2's complement of the subtrahend and then use the
ordinary add to get the difference in a register.