Homework 5 // Due at the BEGINNING of lecture Mon, Mar 28
Primary contact for this homework: Peter Ohmann [ohmann at cs dot wisc dot edu]
You may do this homework with one other person from your section.
You must put both names on the assignment. Please staple multiple pages together.
Problem 1 (2 points)
A memory has 512 distinct memory locations and an addressability of 4 bits.
Can we determine the size of the MAR and/or the MDR (i.e. the number of bits
in each) based on this? If not, what other information would we need? If so,
what is the size of each?
The MAR size is determined by the total memory locations in
the memory. 512 = 29, so the MAR is 9 bits.
The MDR size is determined by the addressability. The MDR is 4 bits.
Problem 2 (3 points)
What does the following LC-3 instruction do? (Be specific; that is, give specific
register numbers or memory locations.)
Address | Binary | Hex |
0x450A | 0011 0110 0000 0111 | 0x3607 |
The instruction is:
ST R3
PC+7. So, specifically, the value
currently in R3 would be stored at address 0x450B + 7 = 0x4512.
Problem 3 (3 points)
We wish to execute a single instruction which subtracts the decimal number 30
from R1 and stores the result in R2. Can we do this? If yes, give the
instruction. If not, explain why not.
No, we cannot perform this operation in a single instruction.
The ADD instruction only has an immediate field of 5 bits. Therefore, the most
negative number we can represent is -16.
Problem 4 (6 points)
-
Give a single LC-3 instruction which moves the value in R1 into R5.
Instruction | Binary | Hex |
ADD R5 R1 0x0 | 0001 1010 0110 0000 | 0x1A60 |
Instruction | Binary | Hex |
AND R5 R1 0x01F | 0101 1010 0111 1111 | 0x5A7F |
Instruction | Binary | Hex |
AND R5 R1 R1 | 0101 1010 0100 0001 | 0x5A41 |
-
Give a single LC-3 instruction for:
R1 ← 0
Instruction | Binary | Hex |
AND R1 R1 0x0 | 0101 001X XX10 0000 | ~0x5260 |
-
The LC-3 has no subtract instruction, but we can perform subtraction on the
LC-3, nevertheless. Give a set of three LC-3 instructions to
compute:
R3 ← R2 - R1
Instruction | Binary | Hex |
NOT R1 R1 | 1001 0010 0111 1111 | 0x927F |
ADD R1 R1 0x1 | 0001 0010 0100 0001 | 0x1241 |
ADD R3 R2 R1 | 0001 0110 1000 0001 | 0x1681 |
Instruction | Binary | Hex |
NOT RX R1 | 1001 001X XX11 1111 | ~0x927F |
ADD RY RX 0x1 | 0001 YYYX XX00 0001 | ~0x1241 |
ADD R3 R2 RY | 0001 0110 1000 0YYY | ~0x1681 |
-
The LC-3 has no OR instruction, but we can perform the or operation on the
LC-3, nevertheless. Give a set of four LC-3 instructions to
compute:
R3 ← R2 | R1
Instruction | Binary | Hex |
NOT R2 R2 | 1001 0100 1011 1111 | 0x94BF |
NOT R1 R1 | 1001 0010 0111 1111 | 0x927F |
AND R3 R2 R1 | 0101 0110 1000 0001 | 0x5681 |
NOT R3 R3 | 1001 0110 1111 1111 | 0x96FF |
Problem 5 (5 points)
Write an LC-3 program to perform the following operation:
R3 ← |R1 + R2|
That is, the program should add R1 to R2, take the absolute value
of the sum, and then halt.
Note: Your program should start at memory address 0x3000. The instructions for
your answer may be in either binary or hex, but please also include your
set of instructions in the book's assembly-style format
(e.g. R1 ← R2 + R3).
Of course, there are a number of ways to do this, and the
following is just one example:
Address | Binary | Hex | Instruction |
0x3000 |
0001 0110 0100 0010 | 0x1642 | R3 ← R1 + R2 |
0x3001 |
0000 0110 0000 0010 | 0x0602 | BRzp 0x3004 |
0x3002 |
1001 0110 1111 1111 | 0x96FF | R3 ← NOT (R3) |
0x3003 |
0001 0110 1110 0001 | 0x16E1 | R3 ← R3 + 1 |
0x3004 |
1111 0000 0010 0101 | 0xF025 | HALT |
Problem 6 (5 points)
Given the program below:
Address | Binary | Hex | Instruction |
0x3000 | 0010 0010 0000 0111 | 0x2207 | R1 ← M[0x3008] |
0x3001 | 0010 0100 0000 0111 | 0x2407 | R2 ← M[0x3009] |
0x3002 | 0101 0110 1110 0000 | 0x56E0 | R3 ← R3 & 0x0 |
0x3003 | 0001 0110 1100 0001 | 0x16C1 | R3 ← R3 + R1 |
0x3004 | 0001 0100 1011 1111 | 0x14BF | R2 ← R2 - 0x1 |
0x3005 | 0000 0011 1111 1101 | 0x03FD | BRP 0x3003 |
0x3006 | 1111 0000 0010 0101 | 0xF025 | HALT |
0x3007 | 1100 0000 1100 0000 | 0xC0C0 | RET (N/A) |
0x3008 | 0000 0000 0000 0101 | 0x0005 | DATA (5) |
0x3009 | 0000 0000 0000 0100 | 0x0004 | DATA (4) |
0x300A | 1100 0000 1100 0000 | 0xC0C0 | RET (N/A) |
-
Write out each instruction in the book's assembly-style format
(e.g. R1 ← R2 + R3). Label each line in your answer by its address in
memory (as above).
(see above)
-
What are the values in R1, R2, and R3 when the program halts? If the program
does not halt, state this.
Register | Value |
R1 | 5 |
R2 | 0 |
R3 | 20 |
-
What operation does this program implement?
Multiply
-
This program is not particularly useful (despite the fact that it does perform
some operation). What new instruction should be inserted just prior to address
0x3006 so that we could actually use the result in the future?
Any sort of ST operation so that the value is retained in
memory somewhere.
Problem 7 (3 points)
The purpose of this problem is to get you set up with the LC-3 PennSim
simulator, which will be important for subsequent homework. You can get the
LC-3 simulator from the
PennSim link in the sidebar.
If you need additional help getting set up with the PennSim simulator, try
this page.
After opening the LC-3 PennSim simulator, please report the following:
-
The names of the LC-3 registers that can be seen in the simulator window, and
their corresponding values.
Register | Value |
R0 | x0000 |
R1 | x0000 |
R2 | x0000 |
R3 | x0000 |
R4 | x0000 |
R5 | x0000 |
R6 | x0000 |
R7 | x0000 |
PC | x0200 |
MPR | x0000 |
PSR | x8002 |
-
The starting memory address, as shown by the highlighted row.
0x0200
-
The "CC" value by the registers is clearly not a register. What is it?
NZP
|