-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
75 lines (56 loc) · 1.23 KB
/
util.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
#ifndef UTIL_H
#define UTIL_H
#include "header.h"
using namespace std;
string getAddressFromRegPair(string reg1, string reg2, map<string, string> registers) {
return (registers[reg1] + registers[reg2]);
}
string hexAddition(string n1, string n2) {
stringstream ss1, ss2, ss3;
int x, y;
string result;
ss1 << hex << n1;
ss1 >> x;
ss2 << hex << n2;
ss2 >> y;
x += y;
ss3 << hex << x;
result = ss3.str();
for(int i=0; i<2; i++) {
if(result[i] >= 'a' & result[i] <= 'f') {
result[i] -= 32;
}
}
return result;
}
string hexSubtraction(string n1, string n2) {
stringstream ss1, ss2, ss3;
int x, y;
string result;
ss1 << hex << n1;
ss1 >> x;
ss2 << hex << n2;
ss2 >> y;
x -= y;
ss3 << hex << x;
result = ss3.str();
for(int i=0; i<2; i++) {
if(result[i] >= 'a' & result[i] <= 'f') {
result[i] -= 32;
}
}
return result;
}
int compareData(string num1, string num2) {
if(num1 == num2)
return 0;
int n1 = stoul(num1, nullptr, 16);
int n2 = stoul(num2, nullptr, 16);
if(n1 < n2) {
return 1;
}
else {
return -1;
}
}
#endif