-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcompile.cpp
More file actions
44 lines (40 loc) · 812 Bytes
/
compile.cpp
File metadata and controls
44 lines (40 loc) · 812 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
#include <vector>
#include <map>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <tuple>
#include "instruction.h"
#include "register.h"
#include "parse_ins.h"
using namespace std;
void put16(ofstream &ofs, unsigned i)
{
char a, b;
a = i>>8;
// printf("store (%4X) %4X\n", i, a);
ofs.put((char)a);
ofs.put((char)i);
}
int main(int argc, char const *argv[])
{
ifstream ifs(argv[1]);
ofstream ofs(argv[2]);
string line;
while (ifs.good()) {
getline(ifs, line);
printf("----------\n%s\n", line.c_str());
if (line[0] == ';') {
continue;
}
int in, pi;
auto v = parse_ins(line);
printf("@ %4X|%4X\n", v[0], v[1]);
put16(ofs, v[0]);
put16(ofs, v[1]);
}
return 0;
}