interface to the control logic of the simulator (do not modify) More...
Go to the source code of this file.
Data Structures | |
struct | inst_fields |
Macros | |
#define | OK 0 |
#define | SR DR |
#define | BaseR SR1 |
#define | nzp DR |
#define | SelNotUsed 0 |
#define | SelImm 1 |
#define | SelReg 0 |
#define | SelBaseR 0 |
#define | SelPC 1 |
#define | SelSEXT11 0 |
#define | SelSEXT9 1 |
#define | SelSEXT6 2 |
#define | SelZero 3 |
Typedefs | |
typedef struct inst_fields | instruction_t |
Functions | |
LC3_WORD | logic_read_reg (int regNum) |
void | logic_write_reg (int regNum, LC3_WORD val) |
LC3_WORD | logic_read_memory (LC3_WORD addr) |
void | logic_write_memory (LC3_WORD addr, LC3_WORD value) |
void | logic_fetch_instruction (instruction_t *inst) |
int | logic_decode_instruction (instruction_t *inst) |
int | logic_execute_instruction (instruction_t *inst) |
LC3_WORD | logic_MARMUX (instruction_t *inst, int ADDRMUX1sel, int ADDRMUX2sel) |
This is the interface to the code (in logic.c) that simulates the control logic of the LC3 machine. Students will typically write the implementation as part of an assignment to complete an LC3 simulator. The implementation will depend on a previous assignment where they wrote methods for bit extraction/mainpulation. See the field.h file for details.
#define OK 0 |
value denoting successful operation
#define SelBaseR 0 |
ADDR1MUX selector
#define SelImm 1 |
SR2MUX selector
#define SelNotUsed 0 |
selector not used
#define SelPC 1 |
ADDR1MUX selector
#define SelReg 0 |
SR2MUX selector
#define SelSEXT11 0 |
ADDR2MUX selector
#define SelSEXT6 2 |
ADDR2MUX selector
#define SelSEXT9 1 |
ADDR2MUX selector
#define SelZero 3 |
ADDR2MUX selector
#define SR DR |
These aliases let you use the "name" of a field as shown in the LC3 IS. Thus, you may use DR in the ADD instruction and SR for the ST instruction. Both refer to the same set of bits in the instruction word.
typedef struct inst_fields instruction_t |
This structure holds all the fields that occur in an instruction. Conceptually, all of these fields are computed in parallel in the combinational logic of the LC3 and the control logic selects the values to use depending on the actual instruction. In hardware, there is "no" cost to computing things you might not use. In the implementation, you may choose to precompute all the fields, or simply get values from the instruction itself as they are needed. This structure is used as the parameter for logic_fetch_instruction(), logic_decode_instruction(), and logic_execute_instruction(), ... .
int logic_decode_instruction | ( | instruction_t * | inst | ) |
This function decodes the instruction. This involves setting fields of the structure that is the parameter of the method. At a minimum, it must set the opcode field. Setting the other fields is optional, but will simplify the code for executing the instruction. The return value follows the common C pattern of 0 meaning success (i.e. instruction is valid), and any non-zero value indicating the type of error. For this implementation, only zero and non-zero are tested.
int logic_execute_instruction | ( | instruction_t * | inst | ) |
This function executes the instruction. At completion, the state of the LC3 hardware reflects the result of the instruction. The return value follows the common C pattern of 0 meaning success (i.e. instruction is valid), and any non-zero value indicating the type of error. For this implementation, only zero and non-zero are tested.
void logic_fetch_instruction | ( | instruction_t * | inst | ) |
This method encapsulates the details of an instruction fetch. Upon return the IR contains the instruction and the PC has been incremented, and the addr and bits fields of the structure have been set appropriately. The addr field in the structure is the address of the instruction, not the incremented PC. It must deal with getting the MAR set correctly, peforming a read, and setting the IR. This involves accessing the resources described in hardware.h.
LC3_WORD logic_MARMUX | ( | instruction_t * | inst, |
int | ADDRMUX1sel, | ||
int | ADDRMUX2sel | ||
) |
This recommended helper function should return the value of the MARMUX. This method is only used internally, but is declared non-static so the documentation can be in the header file.
inst | - a pointer to the instruction structure. |
ADDRMUX1sel- | an integer defining which of the two inputs of the ADDR1MUX to use (see various defines SelXXX). |
ADDRMUX2sel- | an integer defining which of the four inputs of the ADDR2MUX to use (see various defines SelXXX). |
This function encapsulates the details of how memory is actually read. It must deal with getting the MAR set correctly, peforming the read, and returning a value. This involve accessing the resources described in the hardware.h file.
LC3_WORD logic_read_reg | ( | int | regNum | ) |
This function encapsulates the details of how to get the value of a register. While it is nothing more than a direct call to a function described in hardware.h, it means that the programmer need only understand this set of methods. Only the implementor of this code will need to deal with the hardware interface.
This method encapsulates the details of how memory is actually written. It must deal with getting the MAR and MDR set correctly, and performing the write. This involves accessing the resources described in hardware.h.
void logic_write_reg | ( | int | regNum, |
LC3_WORD | val | ||
) |
This method encapsulates the details of how a value is put in one of the LC3 general purpose registers. It deals with the resources described in hardware.h to perform its work. The clean interface of this method hides the details from the programmer and only the implementor of this code will need to deal with the hardware interface. The method does NOT set the condition codes.