-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path8086simu.cpp
62 lines (55 loc) · 1.31 KB
/
8086simu.cpp
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
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include "instruction.h"
#include "register.h"
using namespace std;
const unsigned memory_size = 64*1024; // because 64K is enough for every thing
int regs[14];
vector<char> memory(memory_size);
bool runing = true;
#include "cpu_run.h"
void run_file(const char * file_name)
{
ifstream is;
is.open(file_name, ifstream::in);
if (is.bad())
{
printf("not good file: %s\n", file_name);
exit(1);
}
char c;
printf("load:\n");
int i = 0;
while (is.good()) {
if (is.get(c))
{
if (is.good())
{
memory.push_back(c);
if (i % 2)
printf("|%02X|\n",c&0xFF);
else
printf("|%02X",c&0xFF);
} else {
break;
}
}
i++;
};
// return;
regs[IP] = 0;
regs[CS] = 0;
cpu_run();
}
int main(int argc, char const *argv[])
{
static_assert(sizeof(char) == 1, "char is 8 bit");
static_assert(sizeof(int) >= 2, "int bigger than 16 bit");
static_assert((int)(char)0xFF == -1, "char to int");
run_file(argv[1]);
return 0;
}