-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.h
156 lines (135 loc) · 3.09 KB
/
structs.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* project structs
*/
#ifndef C_ASSEMBLER_STRUCTS_H
#define C_ASSEMBLER_STRUCTS_H
#include "consts.h"
/**
* boolean enum
* (for readability)
*/
typedef enum { false, true } bool; /* boolean */
/**
* file status
* contains the name of the file, current line processed
* and errors flag
*/
typedef struct status { /* file status */
char *file_name;
int line_number;
bool errors_flag;
} status;
/**
* macro declaration
*/
typedef struct macro {
char * macro_id; /* macro id */
char * macro_code; /* macro content */
/* pointer to the next macro */
struct macro * next;
} macro;
/**
* machine directive (op code func and etc..)
*/
typedef struct machine_directive {
char * name; /* op code name */
int opcode; /* op code */
int funct; /* funct */
int amount_of_operands; /*amount of needed operands*/
} machine_directive;
/**
* symbol declaration
* the symbol contains the name of the symbol, its value
* and the attributes as flags
* also, it contains pointer to the next symbol on the list
*/
typedef struct symbol {
char symbol_id[SYMBOL_MAX_LENGTH];
int value;
/* attributes flags */
bool is_external;
bool is_code;
bool is_entry;
bool is_data;
/* pointer to the next symbol */
struct symbol * next;
} symbol;
/**
* data declaration
* data contains the data dc (then updated to final address)
* the data value and pointer to the next data object in the list
*/
typedef struct data {
int dc;
int value: 16;
struct data *next;
} data;
/**
* addressing mode enum
*/
typedef enum addressing_mode {
NONE,
IMMEDIATE,
DIRECT,
INDEX,
REGISTER_DIRECT
} addressing_mode;
/**
* machine directive line contains the md line parsed for
* easier usage
*/
typedef struct machine_directive_line {
machine_directive *md;
char *source_operand;
char *destination_operand;
} machine_directive_line;
/**
* op code word
*/
typedef struct op_code_word {
unsigned int op_code: 16;
} op_code_word;
/**
* second word of line with operand
* holds the addressing mode of the operands and registries
* (if provided)
*/
typedef struct funct_details_word {
unsigned int funct : 4;
unsigned int source_registry :4;
unsigned int source_addressing_mode :2;
unsigned int destination_registry :4;
unsigned int destination_addressing_mode :2;
} funct_details_word;
typedef struct data_word {
unsigned int are : 3;
signed int data: 16;
char *symbol_need_to_be_filled;
bool is_base;
bool is_offset;
} data_word;
typedef struct word {
int address;
op_code_word *ocw;
funct_details_word *fdw;
data_word *dlw;
struct word *next;
} word;
typedef enum data_word_type {
BASE = 0,
OFFSET = 1
} data_word_type;
typedef struct entry {
char symbol_id[SYMBOL_MAX_LENGTH];
bool checked;
unsigned int base;
unsigned int offset;
struct entry *next;
} entry;
typedef struct external {
char symbol_name[SYMBOL_MAX_LENGTH];
unsigned int base;
unsigned int offset;
struct external * next;
} external;
#endif /*C_ASSEMBLER_STRUCTS_H */