-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstruction.cpp
60 lines (44 loc) · 1.43 KB
/
Instruction.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
#include "Instruction.h"
Instruction::Instruction()
// Creates a default instruction that has the opcode UNDEFINED
{
myOpcode = UNDEFINED;
myRS = myRT = myRD = NumRegisters;
}
Instruction::Instruction(Opcode op, Register rs, Register rt, Register rd, int imm)
// Constructs new instruction and initializes fields according to arguments:
// opcode, first source register, second source register, destination
// register, and immediate value
{
setValues(op, rs, rt, rd, imm);
}
void Instruction::setValues(Opcode op, Register rs, Register rt, Register rd, int imm)
// Allows you to set all the fields of the Instruction:
// opcode, first source register, second source register, destination
// register, and immediate value
{
myOpcode = op;
if(op < 0 || op >= UNDEFINED)
myOpcode = UNDEFINED;
myRS = rs;
if(rs < 0 || rs >= NumRegisters)
myRS = NumRegisters;
myRT = rt;
if(rt < 0 || rt >= NumRegisters)
myRT = NumRegisters;
myRD = rd;
if(rd < 0 || rd >= NumRegisters)
myRD = NumRegisters;
myImmediate = imm;
// if(!( (imm & 0xFFFF0000) << 1)) // make sure it has nothing in upper 16 bits
// myImmediate = imm;
}
string Instruction::getString()
// Returns a string which represents all of the fields
{
stringstream s ;
s << "OP: \t" << myOpcode << "\t" << "RD: " << myRD << "\t" <<
"RS: " << myRS << "\t" << "RT: " << "\t" << myRT << "\t" <<
"Imm: " << myImmediate;
return s.str();
}