-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataTypesHandler.h
More file actions
88 lines (74 loc) · 2.28 KB
/
dataTypesHandler.h
File metadata and controls
88 lines (74 loc) · 2.28 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Created by walid on 5/27/20.
//
#include <utility>
#include "bits/stdc++.h"
using namespace std;
#ifndef ASSEMBLER_DATATYPESHANDLER_H
#define ASSEMBLER_DATATYPESHANDLER_H
#endif //ASSEMBLER_DATATYPESHANDLER_H
string decToHexa2(int n) {
// char array to store hexadecimal number
string hexaDeciNum = "";
// counter for hexadecimal number array
int i = 0;
while (n != 0) {
// temporary variable to store remainder
int temp = 0;
// storing remainder in temp variable.
temp = n % 16;
// check if temp < 10
if (temp < 10) {
hexaDeciNum += temp + 48;
i++;
} else {
hexaDeciNum += temp + 55;
i++;
}
n = n / 16;
}
// printing hexadecimal number array in reverse order
reverse(hexaDeciNum.begin(), hexaDeciNum.end());
return hexaDeciNum;
}
class dataTypesHandler {
public:
unordered_map<string, string> symbolicTable;
unordered_map<string, vector<string>> needs_Updates;
pair<string, int> handleDataType(vector<string> line, string location) {
symbolicTable[line[0]] = std::move(location);
int length;
string result;
bool wordOrByte = true;
if (line[1] == "word") {
result = decToHexa2(stoi(line[2]));
length = 6;
} else if (line[1] == "resw") {
length = 6 * stoi(line[2]);
wordOrByte = false;
} else if (line[1] == "byte") {
if (line[2][0] == 'c') {
for (int i = 2; line[2][i] != '\''; ++i) {
char c = line[2][i];
result += decToHexa2((int) c);
}
length = result.length() * 2;
} else if (line[2][0] == 'x') {
for (int i = 2; line[2][i] != '\''; ++i) {
result += line[2][i];
}
length = result.length();
} else {
result = decToHexa2(stoi(line[2]));
}
} else {
length = 2 * stoi(line[2]);
wordOrByte = false;
}
while (result.size() < length && wordOrByte) {
result.insert(0, "0");
}
pair<string, int> out(result, length / 2);
return out;
}
};