-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.cpp
More file actions
98 lines (88 loc) · 1.73 KB
/
execute.cpp
File metadata and controls
98 lines (88 loc) · 1.73 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
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
#include "headers.h"
#include "methods.h"
int execute(elements *e) {
string inst, str;
int p;
map<string, string>::iterator it;
it = e->memory.end();
it--;
e->pc = e->start;
// for(it = (e->memory).begin();it != (e->memory).end();it++) {
while(e->pc != it->first) {
str = e->memory[e->pc];
inst = "";
p = str.find(' ');
if(p == -1)
inst = str;
else
for(int i=0;i<p;i++)
inst += str[i];
if(inst == "MOV")
mov(e);
else if(inst == "XCHG")
xchg(e);
else if(inst == "ADD")
addSub(e);
else if(inst == "SUB")
addSub(e);
else if(inst == "INR")
inrDcr(e);
else if(inst == "DCR")
inrDcr(e);
else if(inst == "INX")
inxDcx(e);
else if(inst == "DCX")
inxDcx(e);
else if(inst == "DAD")
dad(e);
else if(inst == "CMA")
cma(e);
else if(inst == "CMP")
cmp(e);
else if(inst == "MVI")
mvi(e);
else if(inst == "LXI")
lxi(e);
else if(inst == "ADI")
adiSui(e);
else if(inst == "SUI")
adiSui(e);
else if(inst == "JMP")
jmp(e);
else if(inst == "JC")
jc(e);
else if(inst == "JNC")
jnc(e);
else if(inst == "JZ")
jz(e);
else if(inst == "JNZ")
jnz(e);
else if(inst == "LDA")
lda(e);
else if(inst == "STA")
sta(e);
else if(inst == "LHLD")
lhld(e);
else if(inst == "SHLD")
shld(e);
else if(inst == "SET")
sett(e);
else if(inst == "HLT")
return 0;
if(!(inst == "JMP" || inst == "JC" || inst == "JNC" || inst == "JZ" || inst == "JNZ")) {
updatePc(e);
}
}
return 0;
}
/*int main() {
elements e;
e.memory["2000"] = "MOV A,B";
e.memory["2001"] = "LDA 2050";
e.memory["2004"] = "JMP 2001";
e.memory["2007"] = "HLT";
for(i=0;i<8;i++)
(e.flags)[i] = 0;
for(i=0;i<7;i++)
(e.registers)[i] = "NULL";
}*/