Homework 7 // Due at Lecture Wed April 25
You may do this homework in a group of two students from the same 252 section and
turn in one solution at lecture with BOTH students names at the top.
First contact for questions is TA Sanghamitra Roy at: roy1@wisc.edu
The following homework requires you to use the LC-3
simulator. Please follow instructions from HW #5 problem 8 for opening the LC-3
simulator and instructions from HW #6 for submitting screenshots of your code.
1.
An assembly language program is given below:
.ORIG X3000
LD R2, ZERO
LD R0, M0
LD R1, M1
LOOP BRz DONE
ADD R2, R2, R0
ADD R1, R1, -1
BR LOOP
DONE ST R2,
RESULT
HALT
RESULT .FILL X0000
ZERO .FILL X0000
M0 .FILL X0500
M1 .FILL X0005
.END
a.
Run the given program in the LC-3 simulator and
describe what the program does.
b.
How many times does the program loop?
c.
What is the value contained in RESULT after the
program runs to completion?
(No screenshots required for this
problem.)
2.
Problem 7.13 on page 193 of ItCS.
3.
Write an LC-3 assembly language program that
finds out whether the value stored in R0 is divisible by the decimal number 3. If divisible, the program stores
a 1 in R1, otherwise it stores a 0 in R1. Your solution should use a looping construct. A simple algorithm for
this problem would be to subtract 3 repeatedly from R0 and check whether the result is zero.
a.
Use x12FF as the value in R0 and submit a
screenshot of your executed code in the LC-3 simulator showing the value in R1.
b.
Also submit a printout of your commented code in
assembly language (.asm file)
4.
Create a symbol table for the following LC-3
program:
.ORIG X3000
LD R0, NUMBERS
LD R2,
MASK
LOOP LDR R1, R0, #0
BRz DONE
AND R5, R1, R2
BRz L1
BRnzp NEXT
L1 ADD R1, R1, R1
STR R1, R0, #0
NEXT ADD R0, R0, #1
BRnzp LOOP
DONE HALT
NUMBERS .FILL x4000
MASK .FILL x8000
.END
|