In this assignment, you will write a simulator for a machine called the LC-1, using LC-3 assembly language instructions.
The LC-1 ISA specifies eight instructions, described below. Three bits in the instruction, bits <15:13>, are used to represent the opcode. The remaining 13 bits, bits <12:0>, may be used to represent a 13-bit address.
The memory space being simulated contains 2^^13 locations, and the addressibility is 16 bits. The addressing mode is direct. (So, for example, if an instruction contains the bits 0 0000 0000 1100 in its address field, word 12 (decimal) of the program would be accessed.)
The LC-1 ISA has one condition register which is modified by three of the eight instructions: ADD, SUBTRACT, and LOAD. The condition register is set when a negative value is stored in the accumulator, otherwise, it is cleared.
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. Finally, 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 .ENDOnce you can identify each opcode, tackle each of the LC-1 instructions one at a time. Test each LC-1 instruction with an appropriate test program before going on to the next instruction (we wrote some LC-1 test programs in class - you can use those test programs for some of your tests). You should load both the LC-1 program and the main simulator program into memory before running your simulation.
simulator.asm
. Turn in your file using
web-based
turnin.