A.2 Functions, Operators and Instruction Execution
Main functions and simulated operators are not directly bound to a particular
instance of erric_t; rather, they operate on the single copy of the erric_t structure
that is passed to them via parameter. There are also some helper functions, like
those that unify similar instructions in one code block to remove redundant code.
All execution functions first call parse_instruction() routine, that fetches and
decodes instruction pointed to by the PC register. Then, the instruction represented
by the instruction_t structure, Fig. 20.4, format is passed to the execute()
function, which executes it using attached operator function.
Apparently, this structure closely resembles one of the ERRIC instruction,
described in specifications.
format_t enumeration type represents instruction format, as described in the
ERRIC specification. They are named after their function in mathematical operations. Note that due to 10 format being reserved, only 3 formats are listed
(Fig. 20.5).
A.3 Source Files and Their Contents
erric_types.h describes data types used throughout the ERRIC interpreter.
erric_t structure, defined in erric_struct.h, represents the ERRIC machine
(as explained above). Its main parts are memory, registers, and machine status code.
*_operators.h files describe operators that ERRIC CPU can perform, and their
helper functions.
erric_interpreter.c contains mapping from operation instructions to the
function that executes given instruction, and also functions to fetch instruction in
instruction_t structure and parse the instruction.
erric_util.h contains helper functions, for example functions that can make
memory access easier.
struct instruction_t
{
enum format_t format;
sword_t code;
sword_t i;
sword_t j;
};
Fig. 20.4 Instruction routine
300
20 ERRIC Machine Code Simulator
Précédent

- 307/315

Suivant