Macros | Functions | Variables
hardware.h File Reference

defines interface to code simulating hardware (do not modify) More...

#include "lc3.h"
#include "logic.h"

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_WORDlc3_BUS
 

Detailed Description

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.

Author
Fritz Sieker

Macro Definition Documentation

#define HARDWARE_VAR   extern

This controls whether variable is extern or not

Function Documentation

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).

Parameters
regNum- register to get value from
Returns
- value contained in designated registerget value from register R0-R7
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).

Parameters
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.

Parameters
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

Parameters
val- new value for condition code
void hardware_set_mode ( int  mode)

Toggle between user and system mode. For future use.

Parameters
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.

Parameters
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:

  1. logic_fetch_instruction()
  2. logic_decode_instruction()
  3. logic_execute_instruction()
Parameters
inst- storage for info of the instruction
Returns
0 on success, non-zero on failure

Variable Documentation

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.