-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryCodeHandler.c
More file actions
51 lines (39 loc) · 1.08 KB
/
Copy pathbinaryCodeHandler.c
File metadata and controls
51 lines (39 loc) · 1.08 KB
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
#include "binaryCodeHandler.h"
short opWordToBinary(OpWord *word) {
int binaryWord;
binaryWord = 0;
binaryWord = binaryWord | (word->op_code << 6);
binaryWord = binaryWord | (word->source_op << 4);
binaryWord = binaryWord | (word->target_op << 2);
binaryWord = binaryWord | word->alloc;
return (short) binaryWord;
}
OpWord *addCommandOpcode(OpWord *word, char *command) {
short i;
for (i = 0; i < NUMBER_OF_INSTRUCTIONS; i++)
if (!strcmp(command, instructions[i])) {
word->op_code = i;
return word;
}
return word;
}
OpWord *addSourceOp(OpWord *word, short addressing) {
word->source_op = addressing;
return word;
}
OpWord *addTargetOp(OpWord *word, short addressing) {
word->target_op = addressing;
return word;
}
OpWord *initializeOpWord() {
OpWord *newOpWord;
newOpWord= (OpWord *) malloc(sizeof(OpWord));
newOpWord->op_code = 0;
newOpWord->source_op = 0;
newOpWord->target_op = 0;
newOpWord->alloc = 0;
return newOpWord;
}
void freeOpWord(OpWord *word) {
free(word);
}