Instructions:
You are encouraged to work on the problem set in groups and turn
in one problem set for the entire group. Remember to put all
your names on the solution sheet. Also, remember to put the name
of the TA and the time for the discussion section you would like
the problem set turned back to you. Show your work.
Suppose that an instruction cycle of the LC-3 has just finished and another one is about to begin. The following table describes the values in select LC-3 registers and memory locations:
Register | Value |
---|---|
IR | x3001 |
PC | x3003 |
R0 | x3000 |
R1 | x3000 |
R2 | x3002 |
R3 | x3000 |
R4 | x3000 |
R5 | x3000 |
R6 | x3000 |
R7 | x3000 |
Memory Location | Value |
x3000 | x62BF |
x3001 | x3000 |
x3002 | x3001 |
x3003 | x62BE |
For each phase of the new instruction cycle, specify the values that PC
, IR
, MAR
, MDR
, R1
, and R2
will have at the end of the phase in the following table:
PC | IR | MAR | MDR | R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Fetch | ||||||||||||
Decode | ||||||||||||
Fetch Operands | ||||||||||||
Execute | ||||||||||||
Store Result |
Hint: Example 4.2 illustrates the LDR
instruction of the LC-3. Notice that values of memory locations x3000
, 3002
, and 3003
can be interpreted as LDR
instructions.
PC | IR | MAR | MDR | R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Fetch | x3004 | x62BE | x3003 | x62BE | x3000 | x3000 | x3002 | x3000 | x3000 | x3000 | x3000 | x3000 |
Decode | x3004 | x62BE | x3003 | x62BE | x3000 | x3000 | x3002 | x3000 | x3000 | x3000 | x3000 | x3000 |
Fetch Operands | x3004 | x62BE | x3000 | x62BF | x3000 | x3000 | x3002 | x3000 | x3000 | x3000 | x3000 | x3000 |
Execute | x3004 | x62BE | x3000 | x62BF | x3000 | x3000 | x3002 | x3000 | x3000 | x3000 | x3000 | x3000 |
Store Result | x3004 | x62BE | x3000 | x62BF | x3000 | x62BF | x3002 | x3000 | x3000 | x3000 | x3000 | x3000 |
OPCODE | DR | SR1 | SR2 | UNUSED |
If there are 255 opcodes and 120 registers, and every register is available as a source or destination for every opcode,
OPCODE
?DR
)?UNUSED
bits in the instruction encoding?(Adapted from 5.31)
The following diagram shows a snapshot of the 8 registers of the LC-3 before
and after the instruction at location x1000 is executed. Fill in the bits of
the instruction at location x1000.
Register | Before | After |
---|---|---|
R0 | x0000 | x0000 |
R1 | x1111 | x1111 |
R2 | x2222 | x2222 |
R3 | x3333 | x3333 |
R4 | x4444 | x4444 |
R5 | x5555 | xFFF8 |
R6 | x6666 | x6666 |
R7 | x7777 | x7777 |
Memory Location | Value |
---|---|
x1000 | 0001 101 000 1 11000 |
Memory Location | Value |
---|---|
X3000 | 0101000000100000 |
X3001 | 0001000000100101 |
X3002 | 0010001000000100 |
X3003 | 0001000000000000 |
X3004 | 0001001001111111 |
X3005 | 0000001111111101 |
X3006 | 1111000000100101 |
X3007 | 0000000000000100 |
PC | x3006 |
R0 | x0050 |
R1 | x0000 |
R2 | x0000 |
R3 | x0000 |
R4 | x0000 |
R5 | x0000 |
R6 | x0000 |
R7 | x0000 |
N | 0 |
Z | 1 |
P | 0 |
Memory Location | Value | Instruction | Cycles takes to exectue once | number of times executed | Total Cycles for instruction |
---|---|---|---|---|---|
X3000 | 0101000000100000 | AND | 9 | 1 | 9 |
X3001 | 0001000000100101 | ADD | 9 | 1 | 9 |
X3002 | 0010001000000100 | LD | 15 | 1 | 15 |
X3003 | 0001000000000000 | ADD | 9 | 4 | 36 |
X3004 | 0001001001111111 | ADD | 9 | 4 | 36 |
X3005 | 0000001111111101 | Branch | 9 if not taken 10 if taken | 3 times taken 1 time not taken | 39 |
What does the following program do (in 15 words or fewer)? The PC is initially at x3000.
Memory Location | Value |
---|---|
x3000 | 0101 000 000 1 00000 |
x3001 | 0010 001 011111110 |
x3002 | 0000 010 000000100 |
x3003 | 0000 011 000000001 |
x3004 | 0001 000 000 1 00001 |
x3005 | 0001 001 001 000 001 |
x3006 | 0000 111 111111011 |
x3007 | 1111 0000 0010 0101 |
Prior to executing the following program, memory locations x3100 through x4000 are initialized to random values, exactly one of which is negative. The following program finds the address of the negative value, and stores that address into memory location x3050. Two instructions are missing. Fill in the missing instructions to complete the program. The PC is initially at x3000.
Memory Location | Value |
---|---|
x3000 | 1110 000 011111111 |
x3001 | 0110 001 000 000000 |
x3002 | 0000 100 000000010 |
x3003 | 0001 000 000 1 00001 |
x3004 | 0000 111 111111100 |
x3005 | 0011 000 001001010 |
x3006 | 1111 0000 0010 0101 |
The LC-3 has just finished executing a large program. A careful
examination of each clock cycle reveals that the number of executed
store instructions (ST
, STR
, and STI
) is greater than the number of executed load instructions (LD
, LDR
, and LDI
). However, the number of memory write accesses is less than the number of memory read accesses, excluding instruction fetches. How can that be? Be sure to specify which instructions may account for the discrepancy.
A large number of LDI instructions (two read accesses) and STI instructions (one read access and one write access) could account for this discrepancy.
  ASCII       LD R1, ASCII
The symbol table entry for ASCII is x4F08. If this instruction is executed during the running of the program, what will be contained in R1 immediately after the instruction is executed? R1 <-- M[ASCII]
R1 = 0010 001 1 1111 1111
          LD   R1,     #-1
  | ADD R3, R3, #30 |     The immediate value is too large. |
  | ST R3, A | |
  | HALT | |
A   | .BLKW 1 |
The error will be detected by the assembler since it will not be able to form the 16 bits of the instruction which performs the addition.
One possible solution is to seperate the addition to two add instruction with immediate of #15.
  | ADD R3, R3, #15 | |
  | ADD R3, R3, #15 | |
  | ST R3, A | |
  | HALT | |
A   | .BLKW 1 |