forked from FanOfWolves/ISA-Decoder_16Bit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUBoperation.cs
80 lines (63 loc) · 2.53 KB
/
SUBoperation.cs
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
namespace ISA_Decoder_16Bit {
class SUBoperation : Operation {
string verb = "Subtract";
int operandOneEndBit = 8;
int operandOneStartBit = 5;
int operandOneValue;
string operandOneMeaning;
int operandTwoEndBit = 4;
int operandTwoStartBit = 1;
int operandTwoValue;
string operandTwoMeaning;
int immediateSwitchStartBit = 9;
int immediateSwitchEndBit = 9;
int immediateSwitchValue;
public SUBoperation() {
}
public override string DecodeOperation(int inputBits) {
// Decode Immediate
DecodeImmediateSwitch(inputBits);
// Decode Operand One
DecodeFirstOperand(inputBits);
// Decode Operand Two
DecodeSecondOperand(inputBits);
// Get readable text
return GetHumanText();
}
private void DecodeFirstOperand(int inputBits) {
operandOneValue = inputBits & BitUtilities.CreateBitMask(operandOneStartBit, operandOneEndBit);
if (operandOneValue < 0 || operandOneValue > 15) {
operandTwoMeaning = $"OP1: Ya fucke* up";
}
else {
operandOneMeaning = $"r{operandOneValue}";
}
}
private void DecodeSecondOperand(int inputBits) {
operandTwoValue = inputBits & BitUtilities.CreateBitMask(operandTwoStartBit, operandTwoEndBit);
// Immediate or Register?
if (immediateSwitchValue == 0) { // if register
if (operandTwoValue < 0 || operandTwoValue > 15) {
operandTwoMeaning = $"OP2: Ya fucke* up";
}
operandTwoMeaning = $"r{operandTwoValue}";
}
else { // else is an immediate
operandTwoMeaning = $"#{operandTwoValue}";
}
}
/// <summary>
/// Decode value of the immediateSwitch
/// </summary>
/// <param name="inputBits">our instruction</param>
private void DecodeImmediateSwitch(int inputBits) {
immediateSwitchValue = inputBits & BitUtilities.CreateBitMask(immediateSwitchStartBit, immediateSwitchEndBit);
}
/// <summary>
/// This bitch looks through ALL our available fields and constructs an English sentence.
/// </summary>
private string GetHumanText() {
return $"{verb} {operandOneMeaning} from {operandTwoMeaning}, store result in {operandOneMeaning}";
}
}
}