-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (56 loc) · 1.31 KB
/
main.cpp
File metadata and controls
70 lines (56 loc) · 1.31 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
// reading a text file
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <iomanip>
#include <assert.h>
#include "ins.h"
#include "map_tbl.h"
using namespace std;
ifstream infile("in_file.s");
ofstream outfile ("example.txt");
/*
void get_tbl_code(map<string,op_fp> M ,string str)
{
iter = M.find(str);
if(iter != M.end())
return iter->second;
else
return str;
}
*/
int main () {
tbl_init();
assert(infile.is_open());
string line;
static int line_counter = 0;
char *pch;
while( getline (infile,line) )
{
char str[64];
strcpy(str,line.c_str());
pch = strtok (str," \t,");
int arg_cnt = 0;
string mnem;
char* oprand[2];
while (pch != NULL)
{
//outfile<< setfill('0') << setw(4)<<hex<<line_counter<<"\t";
if(arg_cnt==0)
mnem = pch;
else
oprand[arg_cnt-1] = pch;
//pch = strtok (NULL, " \t,$");
pch = strtok (NULL, " \t,");
arg_cnt++;
}
cout<<line_counter<<"\t";
op_tbl[mnem](oprand[0],oprand[1]);
cout<<endl;
line_counter++;
}
//cout<<"Done,output file to example.txt";
infile.close();
}