-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
149 lines (127 loc) · 2.71 KB
/
utils.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <bits/stdc++.h>
#include "convert.h"
using namespace std;
extern string PROGADDR, CSADDR, CSLTH;
typedef map<string, vector<string>> estab;
extern estab ESTAB;
vector<string> sym;
vector<string> address;
string get_program_address_from_os()
{
cout << "Enter Load Address \n";
string add;
cin >> add;
return add;
}
void read(string op)
{
if (op[0] == 'H')
{
CSLTH = op.substr(16, 6);
}
}
string csect_name(string op)
{
return op.substr(2, 6);
}
bool search_estab(string csect_name)
{
estab::iterator itr;
for (itr = ESTAB.begin(); itr != ESTAB.end(); itr++)
{
if (itr->second[0] == csect_name)
{
return true;
}
}
return false;
}
char record_type(string op)
{
if (op[0] == 'E')
{
return 'E';
}
else if (op[0] == 'D')
{
return 'D';
}
else if (op[0] == 'R')
{
return 'R';
}
}
bool search_estab_for_symbol(string sym)
{
estab::iterator itr;
for (itr = ESTAB.begin(); itr != ESTAB.end(); itr++)
{
if (itr->second[1] == sym)
{
return true;
}
}
return false;
}
void process(string op)
{
for (int i = 2; i < op.size(); i = i + 14)
{
string symb;
symb = op.substr(i, 6);
sym.push_back(symb);
}
for (int i = 9; i < op.size(); i = i + 14)
{
string add;
add = op.substr(i, 6);
address.push_back(add);
}
for (int i = 0; i < sym.size(); i++)
{
bool found = search_estab_for_symbol(sym[i]);
if (found)
{
cout << "Error duplicate symbols found! \n";
}
else
{
string caddr = int_to_hex(hex_to_int(CSADDR) + hex_to_int(address[i]));
vector<string> field;
field.push_back(" ");
field.push_back(sym[i]);
field.push_back(caddr);
field.push_back(" ");
ESTAB[caddr] = field;
}
}
sym.clear();
address.clear();
}
void enter_control_section_name_into_ESTAB_with_value_CSADDR(string op)
{
vector<string> field;
field.push_back(csect_name(op));
field.push_back(" ");
field.push_back(CSADDR);
field.push_back(CSLTH);
ESTAB[CSADDR] = field;
}
void display_ESTAB(){
estab::iterator itr;
cout << "ESTAB contents :- \n";
cout << "control "
<< "symbol "
<< "addr "
<< "len " << endl;
cout << "section "
<< "name " << endl;
for (itr = ESTAB.begin(); itr != ESTAB.end(); itr++)
{
for (int i = 0; i < itr->second.size(); i++)
{
cout << itr->second[i] + " ";
}
cout << "\n";
}
}