In this assignment, you will write a simulator for a new "machine", the LC-1, in LC-3 assembly language. You will use the simulator you write to simulate the execution of a program written in LC-1 machine language.
opcode |
bits <12:0> |
| 000 | address13 |
Description: PC is pushed on the stack
PC <- address13
opcode |
bits <12:0> |
| 001 | 0000000000000 |
Description: The stack is popped into PC
opcode |
bits <12:0> |
| 010 | address13 |
Description: Acc <- Acc + mem[address13] (The content of memory location address13 is added to the accumulator. The result is stored back in the accumulator.)
opcode |
bits <12:0> |
| 011 | address13 |
Description: If (n), PC <- address13 (If the n condition bit is set, address13 is stored into the PC.)
opcode |
bits <12:0> |
| 100 | address13 |
Description: Acc <- mem[address13] (The content of memory location address13 is loaded into the accumulator.)
opcode |
bits <12:0> |
| 101 | address13 |
Description: mem[address13] <- Acc (The accumulator is stored into memory location address13.)
opcode |
bits <12:0> |
| 110 | 0000000000000 |
Description: Prints the message "Stopping the LC-1 simulator" to the console and stops execution
opcode |
bits <12:0> |
| 111 | address13 |
Description: Acc <- Acc - mem[address13] (The content of memory location address13 is subtracted from the accumulator. The result is stored back in the accumulator.)
100 0 0001 0000 0010 ; Load from address 0 0001 0000 0010
You can emulate this LC-1 instruction using the LC-3 LDR instruction. First, concatenate 011 to the address specified in the the LC-1 LOAD instruction. This produces the address
0110 0001 0000 0010.
Next, put this value into one of the LC-3 registers, for example, R2. The LC-3 instruction LDR R1, R2, #0 will perform the load, and the result will be stored into R1. Last, R1 should be stored into the accumulator to complete the simulation of the LC-1 LOAD instruction.
.ORIG x3000
;=========================
; initialization block
;=========================
; ...
;=======================
; fetch the instruction
;=======================
AGAIN JSR FETCH
;=======================
; decode the instruction
;=======================
JSR DECODE
BRnzp AGAIN
;===============================
; subroutine to perform fetch
;===============================
FETCH ; ...
; ...
RET
;===============================
; subroutine to perform decode
; and the rest of the
; instruction cycle
;===============================
DECODE ; ...
; ...
RET
.END
Once you can identify each opcode, tackle each of the
LC-1 instructions one at a time. Thoroughly test each LC-1 instruction
before going on to the next.
.ORIG x6000 ; An LC-1 program which starts at location x6000
.FILL x8003 ; Load #10 into the accumulator
.FILL x4004 ; Add #20 to the accumulator
.FILL xC000 ; Stop the LC-1 simulator
; (location x3200 should contain #30)
.FILL #10 ;
.FILL #20 ;
.END
You should load both the LC-1 program and the main simulator program into
memory before running your simulation.
You will be asked to turn in your LC-1 test program(s) along with the simulator program. Your LC-1 programs should demonstrate the full functionality of your simulator.
Each instruction in the LC-1 test program(s) should be commented.
simulator.asm
contains the assembly language code for your simulator. The remaining file(s)
contain sample LC-1 machine code program(s) you used to test your simulator.
You may choose the names for these files, but make sure they end in
.asm.
You must use web-based
turnin
to submit your source files.