- LC – 2 SIMULATOR
LC-2 Simulator is used to run the Assembly Code of LC-2 Microprocessor. This software simulates the execution of instructions coded by the user and displays the instruction execution step by step. The simulation includes,
- Display of how registers R0 to R7, Program Counter, Positive, Negative, Zero flag are getting affected.
- Simulation of Data flow path for every micro instruction that constitutes an instruction.
- Summary of all the micro instructions that are getting executed.
LC-2 is a Reduced Instruction Set Computer.
It has:
- 8 Registers starting from R0 to R7,
- Program Counter,
- Flags (Positive, Negative, Zero)
Registers are of size 16 bits.
Total Addressable memory is 1 MB.
Memory is divided into Segments. Every segment can address up to 256 memory locations. So there are 52 segments.
Following are the Instruction types support by LC-2
The Operate instructions include:
- Arithmetic Operations ADD, SUB, MUL and DIV
- Logical Operations AND, OR, NOT, XOR
These instructions include:
- 80LD (Load), LDR (Load Register), LDI (Load Indirect), LEA (Load Effective Address), ST (Store), STR (Store Register), STI (Store Indirect).
- Different modes of addressing includes,
- Immediate mode
- Direct Mode
- Indirect Mode
- Base + Offset Mode
Control Instructions change the sequence of the instructions that are executed.
These include:
- BR (Break based on P, Z, N flag conditions)
- JMP (Jump)
- JSR (Jump Subroutine)
- JMPR (Jump Register)
- JSRR (Jump Subroutine Register)
- RET (Return)
- TRAP
- The instruction cycle starts with FETCH phase. The instruction is obtained by accessing memory with the address contained in the PC.
- In the first cycle, the contents of the PC are loaded via the global bus into the MAR, and the PC is incremented and loaded into the PC. At the end of this cycle, the PC contains location.
- In the next cycle, the memory is read, and the instruction is loaded into the MDR (Memory Data Register).
- In the next cycle, the contents of the MDR are loaded into the Instruction Register (IR), completing the FETCH phase.
In the next cycle, the contents of the IR are decoded, resulting in the control logic providing the correct control signals to control the processing of the rest of this instruction. The opcode is identified.
In the next cycle, the address of location is evaluated using ZERO Extension or SIGN Extension.
In the next cycle the data at the address is loaded into the MDR
The instruction is executed.
The last cycle in which the results are stored.
The data path reveals how the data is sent and manipulated among various components of the Microprocessor.
The basic components of Data path includes,
- Global bus
- Memory
- ALU and Register File
- PC and PCMUX (PC Multiplexer)
- MARMUX (Memory Address Register Multiplexer)
The Figure shows the EDITOR part of the SIMULATOR. This editor is used to write LC-2 Code. The editor has following components.
- Mnemonics Pad
- Number Pad
- Register Pad
- Program Area
- Segment Selector
- Instruction Help
- Bitwise Instruction Indicator
- Tool Bar
- File Information
Registers pad is used to select Source, Destination or Base Register as a part of the instruction to be coded. |
This panel shows the help about what is the next step that the user has to do so as to complete coding the instruction |
This Instruction Indicator panel shows the BITWISE value of the 16 bit instruction being coded by the user. |
This option is used to create a NEW file for coding the program. If the previous program is not saved, message will be displayed asking whether to save the previous program or not. |
This option is to SAVE the file. If the file with extension .LC2 or .lc2 is given it will be saved as such, else extension will be added and saved. |
This option is to set the program under execution in RUN mode. In RUN mode the user cannot edit the values of REGISTER and Program Counter. |
This option is to set the program under execution in STEP mode. In STEP mode the user can edit the values of REGISTER and Program Counter. |
This option is to STOP the program under execution. |
This option shows the Summary of Output, which includes all the contents of REGISTER, PC, and Flag for every instruction that was executed. |
The SIMULATION Panel consists of
- Data Flow Path Panel
- Registers Panel
- Instruction Summary Panel
Data Flow Path Panel represents the flow of data among various components of the Microprocessor including
- Registers (R0 – R7)
- ALU (Arithmetic and Logic Unit)
- Global Bus
- Control Logic
- Instruction Register (IR)
- Memory
- Memory Address Register (MAR)
- Memory Data Register (MDR)
- Program Counter (PC)
- MARMUX (Memory Address Register Multiplexer)
- PCMUX (Program Counter Multiplexer)
- SEXT (Sign Extension)
- ZEXT (Zero Extension)
- Logic
- Zero, Negative, Positive Flag
- Registers Panel is used to display the _contents _of **_Registers, PC, Zero, Negative, Positive Flags _**during the execution of every instruction.
- If the program is in STEP MODE, then user can modify the contents of Registers, PC after every instruction if he desires.
- The value that can be given ranges from 0 to FFFF (Hexadecimal). If invalid data is given, _error message _will be displayed and values will not be set.
The Instruction Summary Panel shows the summary of execution of every instruction that was executed in the program. The summary shows the contents of
- Registers (R0 – R7)
- Program Counter,
- Positive flag,
- Negative flag,
- Zero flag.
- mvn clean install
- java -jar $PROJECT_HOME/target/lc2-simulator-$PROJECT_VERSION.jar
- Once the simulator starts, use any of the files from
src/main/resources
having.LC2
extension for samples. - Once a ".LC2" file is chosen, a dialog prompt states where the
code instructions
are present i.e., thesegment number
.- From the drop down
Current Segment
, pick the segment that hasinstructions
- In the
Execute
panel, provide theAddress
from where the code execution should begin from. - Press
Run
orStep
to start the simulation.
- From the drop down
- Once the code execution starts, simulation pane will start showing the instruction execution in
graphical
format.- If
Step
mode of execution was chosen, press theDebug
icon on the tool bar to continue execution step by step or chooseRun
icon to finish executing all instructions.
- If