Primary contact for this homework: Rebecca Lam [rjlam@cs.wisc.edu]
You should work in groups of two for this homework. Please write the full name (as it appears on Learn@UW) and the student ID of each group member on every page and staple multiple pages together.
Problem 1 (2 points)
Suppose we increase the number of registers in the LC-3 to 64 and keep the instruction size at 16 bits. Will this cause any problems with the ADD (non-immediate) instruction? Explain.
Problem 2 (2 points)
- (1 point) Write a single LC-3 instruction in hex to move the value of R2 into R3.
- (1 point) Write a single LC-3 instruction in hex for clearing (zeroing) the contents of R1.
Problem 3 (4 points)
Suppose that we have a memory consisting of 128 locations and each location contains 32 bits.
- (2 points) How many bits are required for the address?
- (2 points) If we use the PC-relative addressing mode and want to allow control transfer to instructions 10 locations away (in either direction), how many bits of a branch instruction are needed to specify the PC-relative offset?
Problem 4 (4 points)
We are about to execute the following code snippet. Assume that before execution R0 = 0x3030 and that the value stored at 0x300A is 0x3020. Complete each of the below LC-3 machine instructions so that each instruction loads the data at address 0x3020 into R1, or indicate that it is not possible and why.
Address | Instruction |
0x3000 | 0010 ____ ____ ____ |
0x3001 | 1010 ____ ____ ____ |
0x3002 | 0110 ____ ____ ____ |
0x3003 | 1110 ____ ____ ____ |
Problem 5 (4 points)
Write the LC-3 machine instructions in hex that will implement the following. Give a solution that is 1-2 instructions long and uses a minimal number of registers.
- (2 points) Suppose PC = 0x3000 and R0 = 0x5000. Store the 1's complement of the value at memory address 0x5004 into R1 without overwriting R0.
- (2 points) Assume PC = 0x4000 and the value at memory address 0x400A is 0x8000. Store the most significant bit of R2 into R0.
Problem 6 (3 points)
What are the values of R0 in terms of R1 and R2 (e.g. R0 = R1 * R2) after execution of the following code snippet? Show all work by translating each instruction. The first instruction has been translated for you. Note: #0 is the value 0, not register 0.
0101 0000 0010 0000 AND R0, R0, #0
0101 0110 1110 0000
0001 0110 1110 0011
0001 0010 0100 0001
0001 0000 0000 0010
0001 0110 1111 1111
0000 0011 1111 1100
0101 0000 0000 0001
Problem 7 (5 points)
We are about to execute the program below. Assume the condition codes before execution are N=0, Z=0, P=1.
Address | Instruction |
0x3000 | 0011 0000 0000 1011 |
0x3001 | 0000 0010 0000 0011 |
0x3002 | 1001 0000 0011 1111 |
0x3003 | 0001 0000 0010 0001 |
0x3004 | 1111 0000 0010 0101 |
0x3005 | 1010 0010 0000 0111 |
0x3006 | 1111 0000 0010 0101 |
Suppose a section in memory before execution of the program is as follows:
Address | Value |
0x300A | 0xABCD |
0x300B | 0xFEED |
0x300C | 0xBEEF |
0x300D | 0x300C |
0x300E | 0x300A |
0x300F | 0xBABE |
Given the initial values of the below registers, fill in the values after the program has completed execution (reached a HALT). Give your answers in hex.
Register | Initial Value | Final Value |
MAR | 0x300E | |
MDR | 0xDEAD | |
R0 | 0x0000 | |
R1 | 0x4321 | |
R2 | 0x1234 | |
Problem 8 (2 points)
If R0=0 and the condition codes have the values N=0, Z=0, P=1 before execution of the following three instructions, what are the values of R0 and the condition codes after execution of the instructions?
x3050 0000 0010 0000 0001
x3051 0101 0000 0010 0000
x3052 0001 0000 0010 0001
Problem 9 (2 points)
The following LC-3 branch instruction is located at memory address 0x5F55:
0000 1011 0000 0000
If the branch is taken, what does that imply about the values of the condition codes before the instruction executed?
Problem 10 (2 points)
List four LC-3 operations that do not cause the condition codes to change.