-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPass2.h
71 lines (69 loc) · 1.32 KB
/
Pass2.h
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
#include<bits/stdc++.h>
using namespace std;
void generate_machine_code()
{
string size = decToHex(hexToDec(arr[arr.size()-2].first) - hexToDec(starting_address));
cout << "H " << program_name << " " << starting_address << " " << size << endl;
int i = 0, save = 0, eternal_flag = 0;
string firstExecutable;
while(1)
{
int flag = 0, length = 0, codes = 0;
i = save;
while(i < arr.size()-1 && object_code[i] != "\t" && codes < 30)
{
length++;
if(!flag && get_opcode(arr[i].second.second.first) != "-1")
{
cout << "T ";
flag = 1;
cout << arr[i].first << " ";
if(!eternal_flag)
{
firstExecutable = arr[i].first;
eternal_flag = 1;
}
}
if(object_code[i] != "\t")
{
codes += (object_code[i].size() / 2);
if(codes > 30)
{
codes -= (object_code[i].size() / 2);
break;
}
}
i++;
}
if(!flag)
{
save++;
continue;
}
cout << decToHex(codes) << " ";
i = save;
codes = 0;
for(; codes < 30; i++)
{
if(i >= arr.size() - 1)
break;
if(object_code[i] != "\t")
{
codes += (object_code[i].size() / 2);
if(codes > 30)
break;
cout << object_code[i] << " ";
}
else
{
i++;
break;
}
}
save = i;
if(i >= arr.size()-1)
break;
cout << endl;
}
cout << endl << "E " << firstExecutable << endl;
}