-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjmp.cpp
More file actions
48 lines (39 loc) · 845 Bytes
/
jmp.cpp
File metadata and controls
48 lines (39 loc) · 845 Bytes
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
#include "headers.h"
#include "methods.h"
/*#include<bits/stdc++.h>
using namespace std;
struct elements {
string pc;
string start;
string registers[7];
map<string, string> memory;
int flags[8];
};*/
int jmp(elements *e) {
map<string, string> :: iterator it;
string inst = e->memory[e->pc];
string address = "";
int i;
int p = inst.find(' ');
for(i = p+1;i<inst.length();i++) {
address += inst[i];
}
if(e->memory.find(address) != e->memory.end())
e->pc = address;
else
updatePc(e);
return 0;
}
/*int main() {
elements e;
e.memory["2000"] = "MOV A,B";
e.memory["2001"] = "LDA 2050";
e.memory["2004"] = "JMP 2007";
e.memory["2007"] = "HLT";
e.pc = "2004";
if(jmp(&e))
cout << e.pc << " " << e.memory[e.pc] << endl;
else
cout << "Invalid address" << endl;
return 0;
}*/