Home Work Assignment 10 (due 18 Nov 2004)

In this programming assignment you will write a simulator for the LC-1 ISA in the LC-3 assembly language. You will use the simulator that you write to simulate a program written in the LC-1 machine language. The LC-1 is an accumulator based architecture. There is only one register. This register is called the accumulator. [Read McCabe 4.1 - 4.2.] Since there is only one register, there is no need to explicitly specify the accumulator in an LC-1 instruction.

The LC-1 ISA speicifes seven instructions. They are Call, Return, Add, Brn, Load, Store, and Stop. Three bits in the instruction, bits [15:13], are used to represent the opcode. The rest of the bits in the instruction, bits [12:0], may be used to represent a 13-bit address.

The addressing mode is direct. The memory space being simulated contains 213 locations, and the addressiblity is 16 bits. The LC-1 ISA has one condition register which is modified by two of the seven instructions: Add and Load. It is set when a negative value is stored into the accumulator, otherwise it is cleared.

LC-1 Instruction Set

Call

Description: Push the PC onto the stack and load the address13 into the PC.

Operation: Push PC; PC = address13

15141312 111098 7654 3210
0 0 0 address13

Return

Description: Pop a value from the stack and store the value into the PC.

Operation: Pop PC

15141312 111098 7654 3210
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

Add+

Description: The content of memory location address13 is added to the accumulator. The result is stored back into the accumulator.

Operation: Acc = Acc + mem [ address13 ]

15141312 111098 7654 3210
0 1 0 address13

Brn

Description: If the n condition bit is set, address13 is stored into the PC.

Operation: If (n) PC = address13

15141312 111098 7654 3210
0 1 1 address13

Load+

Description: The content of memory location address13 is stored into the accumulator.

Operation: Acc = mem [ address13 ]

15141312 111098 7654 3210
1 0 0 address13

Store

Description: The content of the accumulator is stored into the memory location address13.

Operation: mem [ address13 ] = Acc

15141312 111098 7654 3210
1 0 1 address13

Stop

Description: Print the message "Stopping the LC-1 simulator" to the console and stop the execution.

15141312 111098 7654 3210
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0

+ Sets the n condition register.

Program Details

The simulator that you write in LC-3 assembly language should be placed starting at memory location x3000. The program that you write in LC-1 machine language should be placed starting at memory location x6000. Since an address specified in LC-1 is 13-bits and an address specified in LC-3 is 16-bits, we cannot simply use an LC-3 load/store instruction to simulate and LC-1 load/store instruction. To get around this problem, we apply a simple workaround. Append the 3-bit pattern, 011, to the front of all LC-1 addresses. For example, suppose you have the following LC-1 instruction:
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, prepend 011 to the address specified in the LC-1 Load instruction. This produces the address 011 0 0001 0000 0010. Next, put this value into one of the LC-3 registers, for example, R2. The LC-3 instructions 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.

The LC-1 simulator that you write must follow the following guidelines. The PC should be stored in memory location x4000. The accumulator should be stored in memory location x4001. Each time the PC or the accumulator changes during the simulation of the LC-1 program, memory location x4000 or x4001 should be updated to reflect this change. The n condition code register should be in x4002. Store the stack pointer at x4003.

The stack for the Call and Return instructions should begin at memory location x4010 (i.e. the stack pointer should be initialized to x400F). The stack grows downwards, i.e. to higher memory addresses.

You do not have to check for invalid instructions. You may assume that the LC-1 machine language program contains only valid instructions.

To begin writing the simulator start with the code template shown below. The majority of the work is performed in the subroutine DECODE. The main loop of the simulator calls FETCH and DECODE subroutines for each LC-1 instruction to simulate.

      .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

LC-1 Program

In a separate file, you should write the LC-1 program using the .FILL pseudo-op. The LC-1 program begins with the line .ORIG x6000 indicating where this program is to be loaded into memory.
    .ORIG x6000 ; LC-1 program that starts at x6000
    .FILL x8003 ; Load #10 into the accumulator
    .FILL x4004 ; Add #20 to the accumulator
    .FILL xC000 ; Stop the LC-1 simulator
    .FILL #10   ;
    .FILL #20
    .END
After loading the main simulator program you have written in LC-3 assembly language, you should load the LC-1 program. Doing so allows you to initialize memory with two programs.

Additional Hints for the Program

The program that you will write will be called LC1Simulator.asm. Use the Style Guide to write your program.

Use the turnin program to submit your home work before 11 PM Thursday, 18 November 2004.