-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecondPassCmdCoding.c
89 lines (72 loc) · 2.18 KB
/
SecondPassCmdCoding.c
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
#include "declarationsHeader.h"
extern paramsPtr paramsListHead;
extern symPtr symTableHead;
extern insPtr insListHead;
extPtr extListHead;
extern struct keyWords keys[];
void preCode(Word machWord) {
/*Putting the info we know for sure*/
machWord->ERA = 0;
machWord->isCmd = TRUE;
machWord->isReg = FALSE;
machWord->isAdd = FALSE;
}
/*
* Codes the command.
*/
void codeCommand() {
char cmd[CMD_LENGTH];
paramsPtr ptr = paramsListHead;
Word machWord = (Word) malloc(sizeof(struct machWord));
MEMORY_ERROR(machWord)
getCommand(cmd);
syncParametersToLine(&ptr);
if (nothingToCode(ptr, cmd))
return;
preCode(machWord);
findOpCode(machWord, cmd);
if (specialTypeAction(cmd))
specialActionCoding(&machWord, ptr);
else
regActionCoding(&machWord, ptr);
checkForErrors(cmd, machWord);
}
/*
* Codes the memory word with the first method setting.
*/
void paramIsANumberSetting(Word *machWord, char *param, int notImmediate) {
double temp;
int compare = 0;
(*machWord)->isAdd = TRUE;
(*machWord)->isCmd = FALSE;
(*machWord)->isReg = FALSE;
temp = !notImmediate ? atoi(param + 1) : atoi(param);
/*Testing its not a floating parameter.*/
compare = (int) temp;
if (temp > compare) {/*Checking if the number is a floating point data type.*/
printErrorWithComment(float_err, param);
return;
}
/*Sets the address to the value of the int.*/
if (temp != 0)
(*machWord)->address = (unsigned) temp;
else
printErrorWithComment(undef_parameter, param);
}
/*
*Codes the memory word with the second method setting.
*/
void paramIsALabelSetting(Word *machWord, symPtr *sPtr) {
const int relocatable = 2, ext = 1, exSymbol = -1;
(*machWord)->isAdd = TRUE;
(*machWord)->isCmd = FALSE;
(*machWord)->isReg = FALSE;
(*machWord)->ERAforAdd = relocatable;
/*Testing if the parameter is defined as extern for later use.*/
if ((*sPtr)->data == exSymbol) {
(*machWord)->address = FICTIVE_ADDRESS;
(*machWord)->ERAforAdd = ext;
addToExtList((*sPtr)->symName);
} else
(*machWord)->address = ((*sPtr)->data);
}