-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime.c
64 lines (52 loc) · 1.02 KB
/
runtime.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
#include <stdio.h>
#include <stdlib.h>
#include "opcodes.h"
#include "machine.h"
int main(int argc, char *argv[]) {
// initalize the machine
FILE *input_asm = fopen(argv[1], "r+");
Machine m;
load_instructions(&m, input_asm);
init(&m);
int OPCODE;
int arg;
while (OPCODE != HALT){
OPCODE = next_instruction(&m);
switch(OPCODE){
case LOAD: ;
arg = next_instruction(&m);
load(&m, arg);
break;
case LOADI: ;
arg = next_instruction(&m);
loadi(&m, arg);
break;
case STORE: ;
arg = next_instruction(&m);
store(&m, arg);
break;
case ADD: ;
arg = next_instruction(&m);
add(&m, arg);
break;
case SUB: ;
arg = next_instruction(&m);
subtract(&m, arg);
break;
case JUMP: ;
arg = next_instruction(&m);
jump(&m, arg);
break;
case JMPZ: ;
arg = next_instruction(&m);
jump_if_zero(&m, arg);
case JNZ: ;
arg = next_instruction(&m);
jump_if_not_zero(&m, arg);
case OUTPUT: ;
output(&m);
break;
}
}
return 0;
}