defines interface to code simulating hardware (do not modify) More...
Go to the source code of this file.
Macros | |
#define | HARDWARE_VAR extern |
Functions | |
void | hardware_reset (void) |
void | hardware_load_MAR (void) |
void | hardware_load_MDR (void) |
void | hardware_gate_MDR (void) |
void | hardware_gate_PC (void) |
void | hardware_set_PC (LC3_WORD addr) |
void | hardware_load_IR (void) |
LC3_WORD | hardware_get_IR (void) |
void | hardware_load_REG (int regNum) |
LC3_WORD | hardware_get_REG (int regNum) |
void | hardware_memory_enable (int rw) |
void | hardware_set_mode (int mode) |
int | hardware_get_CC (void) |
void | hardware_set_CC (int val) |
int | hardware_step (instruction_t *inst) |
Variables | |
HARDWARE_VAR LC3_WORD * | lc3_BUS |
This defines the interface to the code simulating the hardware contained in hardware.c. There are a variety of routines corresponding to actions the control logic of the LC3 can perform. For example, it can gate various values onto the bus and transfer values to registers from the bus. It is expected that the student will encapsulate many of these routines to give a cleaner interface to the hardware. This code will be in logic.c. With the exception of the bus, all hardware data structures are hidden behind accessor functions.
Not all of the interface mirrors the LC3 hardware. The differences were designed to simplify the code.
#define HARDWARE_VAR extern |
This controls whether variable is extern or not
void hardware_gate_MDR | ( | void | ) |
The value of the memory data register (MDR) is put "on" the bus.
void hardware_gate_PC | ( | void | ) |
The value of the program counter (PC) is put "on" the bus.
int hardware_get_CC | ( | void | ) |
Return the current value of the condition code.
LC3_WORD hardware_get_IR | ( | void | ) |
Return the current value of the instruction register (IR).
LC3_WORD hardware_get_REG | ( | int | regNum | ) |
Return the value of a register (0-7).
regNum | - register to get value from |
void hardware_load_IR | ( | void | ) |
The instruction register (IR) is loaded from the bus.
void hardware_load_MAR | ( | void | ) |
The memory address register (MAR) is loaded from the bus.
void hardware_load_MDR | ( | void | ) |
The memory data register (MDR) is loaded from the bus.
void hardware_load_REG | ( | int | regNum | ) |
Copy the value "on" the LC3 bus into the designated register (0-7).
regNum | - register to load |
void hardware_memory_enable | ( | int | rw | ) |
This is the low level memory access function. It controls whether a read or write is performed. Is assumes that the MAR and possibly the MDR have been set appropriately by calls to other functions.
rw | - if non zero, a write is performed by trasfering the contents of the MDR to memory the address contained in the MAR. If it is 0, a read is performed and the contents of memory at the address contained in the MAR are copied to the MDR. |
void hardware_reset | ( | void | ) |
Reset all the hardware variables in the machine to a known state.
void hardware_set_CC | ( | int | val | ) |
Set the condition code
val | - new value for condition code |
void hardware_set_mode | ( | int | mode | ) |
Toggle between user and system mode. For future use.
mode | - 0 is system mode, 1 is user mode |
void hardware_set_PC | ( | LC3_WORD | addr | ) |
The program counter (PC) is set to the parameter.
addr | - new value for the PC |
int hardware_step | ( | instruction_t * | inst | ) |
This is the basis for doing single stepping durring debugging. It encapsulates the basic instruction cycle by making calls to three external routines, normally written by students as part of the simulator assignment. The routines are:
inst | - storage for info of the instruction |
HARDWARE_VAR LC3_WORD* lc3_BUS |
The LC3 bus is modeled as a pointer. Reading from the bus (dereferencing the pointer) is getting the value from whatever source is currently "driving" the bus. Similarly, writing on the bus invloves setting the pointer value. The bus is a global that can be accessed outside of this code.