-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.h
120 lines (105 loc) · 3.19 KB
/
global.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* LC-3 Simulator
* Final Project (Project #6)
* TCSS 372 - Computer Architecture
* Spring 2018
*
* Global Module Header File
*
* This is a simulator of the LC-3 (Little Computer) machine using an
* object-oriented approach in C. The simulator includes all standard LC-3
* functionality based on the finite state machine approach and the corresponding
* opcode tables for the machine, with an additional push-pop stack feature utilized
* on the previously reserved (1101) opcode.
*
* Group Members:
* Michael Fulton
* Enoch Chan
* Logan Stafford
*
* Base Code Contributors:
* Sam Brendel
* Michael Josten
* Sam Anderson
* Tyler Schupack
*/
#ifndef GLOBAL_H
#define GLOBAL_H
/** Constants for representing boolean value */
#define FALSE 0
#define TRUE 1
/** Configuration constants */
#define REGISTER_SIZE 8
#define MEMORY_SIZE 512
#define MEMORY_ADDRESS_MIN 0x3000
/** Register address indicies */
#define R0 0
#define R1 1
#define R2 2
#define R3 3
#define R4 4
#define R5 5
#define R6 6
#define R7 7
#define MASK_CC_Z 2 /* 010 */
#define MASK_CC_P 1 /* 001 */
#define BITSHIFT_CC_N 2
#define BITSHIFT_CC_Z 1
/** Define the data types used by LC-3. Each LC-3 data type is assigned the smallest and most
* appropriate C data type here. */
typedef unsigned short word_t;
typedef unsigned char bool_t;
typedef unsigned char state_t;
typedef unsigned char opcode_t;
typedef unsigned char cc_t;
typedef signed char imm_5_t;
typedef signed char pc_offset_6_t;
typedef signed short pc_offset_9_t;
typedef signed short pc_offset_11_t;
typedef unsigned char trap_vector_t;
typedef unsigned char reg_addr_t;
/** Snapshot of the CPU. See LC3 snapshot comment */
typedef struct cpu_snapshot_t cpu_snapshot_t;
struct cpu_snapshot_t {
word_t registers[REGISTER_SIZE];
bool_t cc_n;
bool_t cc_z;
bool_t cc_p;
word_t ir;
word_t pc;
word_t mar;
word_t mdr;
};
/** Snapshot of the ALU. See LC3 snapshot comment */
typedef struct alu_snapshot_t alu_snapshot_t;
struct alu_snapshot_t {
word_t a;
word_t b;
word_t result;
};
/** Snapshot of the memory. See LC3 snapshot comment */
typedef struct memory_snapshot_t memory_snapshot_t;
struct memory_snapshot_t {
word_t data[MEMORY_SIZE];
};
/** The LC3 snapshot contains all the data for the LC3 at a specific moment in time. This
* compilation of data allows for debugging and/or displaying of the LC3 contents at specific
* moments in time. It may also be useful for recreating the state of the LC3 if it needed to
* be interrupted, cleared, then restored, or put to sleep and awoken later */
typedef struct lc3_snapshot_t lc3_snapshot_t;
struct lc3_snapshot_t {
word_t starting_address;
bool_t file_loaded;
bool_t is_halted;
cpu_snapshot_t cpu_snapshot;
alu_snapshot_t alu_snapshot;
memory_snapshot_t memory_snapshot;
};
/** Converts to a 16-bit LC3 memory address from a 0-based array index. Based on the LC3
* minimum address */
word_t get_address_from_index(int);
/** Convert to a 0-based array index from a 16-bit LC3 memory address */
int get_index_from_address(word_t);
/** Returns a 16 bit LC3 word parsed from the specified string */
word_t get_word_from_string(char *);
#endif