-
Notifications
You must be signed in to change notification settings - Fork 1
/
Load_and_Store.cpp
executable file
·207 lines (197 loc) · 3.48 KB
/
Load_and_Store.cpp
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <bits/stdc++.h>
using namespace std;
void MOV(string &user_instruction)
{
int tmp;
switch (user_instruction[7])
{
case 'A':
tmp = A;
break;
case 'B':
tmp = B;
break;
case 'C':
tmp = C;
break;
case 'D':
tmp = D;
break;
case 'E':
tmp = E;
break;
case 'H':
tmp = H;
break;
case 'L':
tmp = L;
break;
default:
error = 1;
cout << "You found a bug!\n";
}
switch (user_instruction[4])
{
case 'A':
A = tmp;
break;
case 'B':
B = tmp;
break;
case 'C':
C = tmp;
break;
case 'D':
D = tmp;
break;
case 'E':
E = tmp;
break;
case 'H':
H = tmp;
break;
case 'L':
L = tmp;
break;
default:
error = 1;
cout << "You found a bug!\n";
}
}
void MVI(string &user_instruction)
{
string hex_number = "";
hex_number.push_back(user_instruction[7]);
hex_number.push_back(user_instruction[8]);
int tmp = hex_to_dec(hex_number);
switch (user_instruction[4])
{
case 'A':
A = tmp;
break;
case 'B':
B = tmp;
break;
case 'C':
C = tmp;
break;
case 'D':
D = tmp;
break;
case 'E':
E = tmp;
break;
case 'H':
H = tmp;
break;
case 'L':
L = tmp;
break;
default:
error = 1;
cout << "You found a bug!\n";
}
}
void LDA(string &user_instruction)
{
string address = "";
for (int i = 4; i <= 7; ++i)
address.push_back(user_instruction[i]);
A = address_data[hex_to_dec(address)];
}
void STA(string &user_instruction)
{
string address = "";
for (int i = 4; i <= 7; ++i)
address.push_back(user_instruction[i]);
address_data[hex_to_dec(address)] = A;
}
void SET(string &user_instruction)
{
string address = "";
string str_data = "";
for (int i = 4; i <= 7; ++i)
address.push_back(user_instruction[i]);
if (hex_to_dec(address) >= hex_to_dec(starting_address) && hex_to_dec(address) <= hex_to_dec("FFFF"))
{
for (int i = 11; i <= 12; ++i)
str_data.push_back(user_instruction[i]);
int int_data = hex_to_dec(str_data);
address_data[hex_to_dec(address)] = int_data;
}
else
cout << "Invalid address or data\n";
}
void SHLD(string &user_instruction)
{
string address = "";
for (int i = 5; i <= 8; ++i)
address.push_back(user_instruction[i]);
address_data[hex_to_dec(address)] = L;
int temp = hex_to_dec(address);
++temp;
address_data[temp] = H;
}
void LHLD(string &user_instruction)
{
string address = "";
for (int i = 5; i <= 8; ++i)
address.push_back(user_instruction[i]);
L = address_data[hex_to_dec(address)];
int temp = hex_to_dec(address);
++temp;
H = address_data[temp];
}
void XCHG()
{
swap(H, D);
swap(L, E);
}
void LXI(string &user_instruction)
{
string address1 = "", address2 = "";
for (int i = 7; i <= 8; ++i)
address1.push_back(user_instruction[i]);
for (int i = 9; i <= 10; ++i)
address2.push_back(user_instruction[i]);
switch (user_instruction[4])
{
case 'B':
C = hex_to_dec(address2);
B = hex_to_dec(address1);
break;
case 'D':
E = hex_to_dec(address2);
D = hex_to_dec(address1);
break;
case 'H':
L = hex_to_dec(address2);
H = hex_to_dec(address1);
break;
default:
error = 1;
cout << "You found a bug!\n";
}
}
void STAX(string &user_instruction)
{
string address = "";
switch (user_instruction[5])
{
case 'B':
address = dec_to_hex(B) + dec_to_hex(C);
address_data[hex_to_dec(address)] = A;
break;
case 'D':
address = dec_to_hex(D) + dec_to_hex(E);
address_data[hex_to_dec(address)] = A;
break;
case 'H':
address = dec_to_hex(H) + dec_to_hex(L);
address_data[hex_to_dec(address)] = A;
break;
default:
error = 1;
cout << "You found a bug!\n";
}
}