-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstructions.h
289 lines (244 loc) · 6.83 KB
/
instructions.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#ifndef _INSTRUCTIONS_
#define _INSTRUCTIONS_
#include <iostream>
enum Registers : int
{
HeapArrayRegister = 0, /* Low Registers */
AcumulatorRegister,
TemporaryRegister,
SecondRegister,
FramePointer,
GlobalPointer,
UserSPKeeper,
SystemCallRegister, /* Low registers*/
StoredSpecReg, /* High Registers */
LinkRegister = 12,
PCKeeper,
StackPointer,
ProgramCounter /* High Registers */
};
enum ConditionCodes
{
EQ = 0, //Equal
NE, //NOT EQUAL
HS, //Unsigned Greater than or equal
LO, //Unsigned less then
MI, //Negative
PL, //Positive or zero
VS, //Overflow (V set)
VC, //No overflow (V Clear)
HI, //Unsigned greater than
LS, //Unsgined less than or equal
GE, //Signed greater than or equal
LT, //Signed less than
GT, //Signed greater than
LE, //Signed less than or equal
AL, //Always
CS = 2, //Unsigned Greater than or equal
CC = 3 //Unsigned less THan
};
enum SystemCalls
{
StandardPreemptionFlow = 0,
IORequest,
ProgramCompletion,
UserPreemption,
BiosCompletion
};
std::string printRegister(int reg);
class Instruction
{
public:
int id;
std::string name, label, debugname;
int regm, regn, regd, condition, immediate, offset;
virtual std::string to_string() = 0;
virtual std::string to_binary()
{
return getOpCode(id);
};
bool isLabel = false;
void setlabel(std::string newLabel);
std::string to_string_with_label();
int relativeAddress;
int debugAddress;
static std::string getOpCode(int id);
static std::string getOpBit(int id);
static std::string getFunct2(int id);
static std::string getFunct1(int id);
static std::string getConditionString(ConditionCodes condition);
};
Instruction *nop();
Instruction *loadImmediateToRegister(Registers regis, int number);
Instruction *pushAcumulator();
Instruction *pushRegister(Registers reg);
Instruction *pushMultiple(int count);
Instruction *popMultiple(int count);
Instruction *popRegister(Registers reg);
Instruction *jumpToRegister(Registers reg);
Instruction *moveLowToLowRegister(Registers origin, Registers destination);
Instruction *subImeditateFromRegister(int value, Registers destination);
Instruction *sumWithPC(Registers reg, int number);
Instruction *sumRegisters(Registers ra, Registers rb); // A = A + B
Instruction *lsl(Registers ld, Registers ls);
Instruction *lslImmediate(Registers ld, int immediate);
Instruction *lsr(Registers ld, Registers ls);
Instruction *lsrImmediate(Registers ld, int immediate);
Instruction *andBitwise(Registers ld, Registers lb);
Instruction *orBitwise(Registers ld, Registers lb);
Instruction *xorBitwise(Registers ld, Registers lb);
Instruction *copySP(Registers reg);
Instruction *extendZero(Registers reg);
Instruction *rightShiftImmediate(Registers, int);
Instruction *branchImmediate(ConditionCodes, int);
Instruction *branchLink(Registers reg);
Instruction *relativeBranch(ConditionCodes cond, Registers reg);
Instruction *leftShiftImmediate(Registers, int);
Instruction *addImmediate(Registers, int);
Instruction *subtractImmediate(Registers, int);
Instruction *signExtendHW(Registers);
Instruction *interrupt(SystemCalls systemCall);
Instruction *compare(Registers a, Registers b);
Instruction *compareWithImmediate(Registers reg, int immediate);
Instruction *storeWithImmediate(Registers content, Registers baseAddr, int offset);
Instruction *storeWithRegister(Registers content, Registers baseAddr, Registers offset);
Instruction *loadWithImmediate(Registers target, Registers baseAddr, int offset);
Instruction *loadWithRegister(Registers target, Registers baseAddr, Registers offset);
Instruction *moveLowToHigh(Registers low, Registers high);
Instruction *moveHighToLow(Registers low, Registers high);
Instruction *outputRegister(Registers reg);
Instruction *halt();
Instruction *pause();
class BranchLabel;
class TypeDInstruction;
class TypeAInstruction : public Instruction
{
public:
TypeAInstruction(
int identity,
std::string instructionName,
int instructionImmediate,
int RegisterM,
int RegisterD);
std::string to_string();
std::string to_binary();
};
class TypeBInstruction : public Instruction
{
public:
TypeBInstruction(
int identity,
std::string instructionName,
int RegisterM,
int RegisterN,
int RegisterD);
std::string to_string();
std::string to_binary();
};
class TypeCInstruction : public Instruction
{
public:
TypeCInstruction(
int identity,
std::string instructionName,
int instructionImmediate,
int RegisterN,
int RegisterD);
std::string to_string();
std::string to_binary();
};
class TypeDInstruction : public Instruction
{
public:
TypeDInstruction(
int identity,
std::string instructionName,
int RegisterD,
int instructionImmediate);
std::string to_string();
std::string to_binary();
};
class TypeEInstruction : public Instruction
{
public:
TypeEInstruction(
int identity,
std::string instructionName,
int RegisterM,
int RegisterD);
std::string to_string();
std::string to_binary();
};
class TypeFInstruction : public Instruction
{
public:
TypeFInstruction(
int identity,
std::string instructionName,
int conditionCode,
int RegisterD);
std::string to_string();
std::string to_binary();
};
class TypeGInstruction : public Instruction
{
public:
TypeGInstruction(
int identity,
std::string instructionName,
int conditionCode,
int offsetSize);
std::string to_string();
std::string to_binary();
};
class TypeHInstruction : public Instruction
{
public:
TypeHInstruction(
int identity,
std::string instructionName,
int RegisterD);
std::string to_string();
std::string to_binary();
};
class TypeIInstruction : public Instruction
{
public:
TypeIInstruction(
int identity,
std::string instructionName,
int value);
std::string to_string();
std::string to_binary();
};
class TypeJInstruction : public Instruction
{
public:
TypeJInstruction(
int identity,
std::string instructionName,
int regd);
std::string to_string();
std::string to_binary();
};
class TypeKInstruction : public Instruction
{
public:
TypeKInstruction(
int identity,
std::string instructionName,
int regd);
std::string to_string();
std::string to_binary();
};
class BranchLabel
{
std::string tolabel;
public:
Instruction *firstByte;
Instruction *secondByte;
Instruction *branch;
BranchLabel(std::string gotolabe, ConditionCodes condition, bool isJumpAndLink);
std::string to_string();
};
#endif