-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecodeLine.h
263 lines (236 loc) · 6.43 KB
/
decodeLine.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#if !defined(DECODE_LINE_HEADER)
#define DECODE_LINE_HEADER
#include "symbol.h"
#include "binaryLine.h"
#define MAX_OPPERAND_LENGTH 30
#define MAX_COMMAND_NAME_LENGTH 20
#define MAX_VARIABLE_NAME_LENGTH 20
#define MAX_LABEL_LENGTH 20
#define SPACE_SYMBOL " "
#define COMMENT_LINE_SYMBOL ';'
#define COMMENT_LINE_STRING ";"
#define INSTRUCTION_LINE_SYMBOL '.'
#define COMMA_SYMBOL ","
#define QUOTATION_SYMBOL "\""
#define LABEL_SYMBOL ":"
#define HASHTAG_SYMBOL "#"
#define LEFT_SQUARE_BRACKET "["
#define RIGHT_SQUARE_BRACKET "]"
#define REGISTER_R_SYMBOL "r"
#define COMMAND_MOV "mov"
#define COMMAND_CMP "cmp"
#define COMMAND_ADD "add"
#define COMMAND_SUB "sub"
#define COMMAND_LEA "lea"
#define COMMAND_CLR "clr"
#define COMMAND_NOT "not"
#define COMMAND_INC "inc"
#define COMMAND_DEC "dec"
#define COMMAND_JMP "jmp"
#define COMMAND_BNE "bne"
#define COMMAND_JSR "jsr"
#define COMMAND_RED "red"
#define COMMAND_PRN "prn"
#define COMMAND_RTS "rts"
#define COMMAND_STOP "stop"
#define MACHINE_CODE_A 2
#define MACHINE_CODE_R 1
#define MACHINE_CODE_E 0
/**
* @brief decode a single line from the file and return a number of lines to be added to the file
*
* @param line current line from file for errors
* @param inputLine the input line to be decode
* @param command destination for command name
* @param src destination for source opperand
* @param dest destination for destination opperand
* @param srcAddressing destination for type of addressing for source
* @param destAddressing destination for type of addressing for destination
* @param numberOfOpperands destination for number of opperands for command name
* @return int number of lines to be written
*/
int lineDecode(int, char *, char *, char *, char *, int *, int *, int *);
/**
* @brief return the number of opperands in a single input line
*
* @param inputLine input line to be decoded
* @param command destination for command name
* @param src destination for source opperand
* @param dest destination for destination opperand
* @param line number of line for error output
* @return int number of opperands
*/
int decodeInstructionLine(char *, char *, char *, char *, int);
/**
* @brief check the opperand type of a given opperand
* 0 - number
* 1 - symbol and register
* 2 - register
* 3 - symbol
* -1 - invalid
*
* @param opperand the opperand to be checked
* @return int
*/
int checkOpperandType(char *);
/**
* @brief return true if an opperand is a number
*
* @param opperand the opperand to be checked
* @return int
*/
int isNumber(char *);
/**
* @brief returns true if an opperand is a register without checking if the register number is valid (0 to 15)
*
* @param opperand the opperand to be checked
* @return int
*/
int isRegister(char *);
/**
* @brief returns true if an opperand is a symbol and register
*
* @param opperand the opperand to be checked
* @return int
*/
int isIndexOpperand(char *);
/**
* @brief Get the Number Of Opperands from a command name, returns -1 for wrong command name
*
* @param command the command name to be checked
* @return int
*/
int getNumberOfOpperands(char *);
/**
* @brief checks if a command with two opperands is valid
*
* @param command command name
* @param src source opperand
* @param srcAddressing destination for source addressing
* @param dest destination opperand
* @param destAddressing destination for destination addressing
* @return int 0 - FALSE
*/
int checkValidCommandTwoOpperands(char *, char *, int *, char *, int *);
/**
* @brief checks if a command with one opperand is valid
*
* @param command comamnd name
* @param dest destination opperand
* @param destAddressing destination for destination addressing
* @return int
*/
int checkValidCommandOneOpperand(char *, char *, int *);
/**
* @brief Get the Funct of a command name
*
* @param command command name to be checked
* @return int FUNCT of command
*/
int getFunct(char *);
/**
* @brief Get the Opcode of a command name
*
* @param command command name to be checked
* @return int OPCODE of command
*/
int getOpcode(char *);
/**
* @brief creates binary lines according to the type of command, a symbol line doesnt get a value
*
* @param linesCounter number of line in file for errors
* @param lines binary lines
* @param command name of command
* @param arguments number of arguments
* @param ...
* @return int
*/
int buildMachineCodeLines(int, BinaryLine *, char *, int, ...);
/**
* @brief Get the Number From an Opperand
*
* @param opperand the opperand to be checked
* @return int
*/
int getNumberFromOpperand(char *);
/**
* @brief Get the Reg From an opperand
*
* @param opperand the opperand to be checked
* @return int
*/
int getRegFromOpperand(char *);
/**
* @brief checks if a symbol is valid (alpha numeric characters only)
*
* @param symbol thr symbol to be checked
* @return int
*/
int checkValidSymbol(char *);
/**
* @brief returns true if an inputline is a symbol decleration
*
* @param inputLine inputline to be checked
* @return int
*/
int isSymbolDecleration(char *);
/**
* @brief returns true if an inputline is a data decleration
*
* @param inputLine inputline to be checked
* @return int
*/
int isDataDecleration(char *);
/**
* @brief returns true if an inputline is an extern decleration
*
* @param inputLine inputline to be checked
* @return int
*/
int isExternDecleration(char *);
/**
* @brief skip a symbol in the beggining of an inputline
*
* @param inputLine inputline to be checked
* @return int
*/
int skipSymbol(char *);
/**
* @brief checks if a decleration string is in the inputline
*
* @param inputLine inputline to be checked
* @param decleration type of decleration to be in inputline
* @return int
*/
int checkDecleration(char *, char *);
/**
* @brief returns true if a symbol is in the symbol table
*
* @param table symbole table
* @param tableSize size of symbol table
* @param symbolName name of symbol to be found
* @return int
*/
int findSymbolInTable(Symbol *, int, char *);
/**
* @brief returns true if an inputline is an empty line
*
* @param inputLine inputline to be checked
* @return int
*/
int isEmptyLine(char *);
/**
* @brief returns true if a line is a comment line
*
* @param inputLine inputline to be checked
* @return int
*/
int isCommentLine(char *);
/**
* @brief returns true if an inputline is an entry decleration line
*
* @param inputLine inputline to be checked
* @return int
*/
int isEntryDecleration(char *);
#endif