-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstructionFactory.cs
82 lines (81 loc) · 3.41 KB
/
InstructionFactory.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
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace armsimGUI
{
public class InstructionFactory
{
public Instruction Create(uint data)
{
byte operationType = Instruction.GetOperationType(data);
bool bit4 = Memory.TestFlagInData(data, 4);
switch (operationType)
{
case 0x0: // 000
if (Memory.ExtractBits(data, 21, 24) == 0 && (Memory.ExtractBits(data, 4, 7) >> 4) == 0x09) // instruction is a MUL
{
Data dInstr = new Data(data);
dInstr.DataMul();
dInstr.ExecuteInstruction(true);
return dInstr;
}
else if (bit4 == false) // Data Register, Immediate-shifted Register
{
Data dInstr = new Data(data);
dInstr.DataRegImmShiftedReg();
dInstr.ExecuteInstruction(true);
return dInstr;
}
else if (bit4 == true && Memory.ExtractBits(data, 20, 24) >> 20 == 0x12) // BX instruction
{
Branch bInstr = new Branch(data);
bInstr.Branch();
bInstr.ExecuteInstruction(true);
return bInstr;
}
else // Data Register-shifted Immediate
{
Data dInstr = new Data(data);
dInstr.DataRegShiftedReg();
dInstr.ExecuteInstruction(true);
return dInstr;
}
case 0x1: // 001 - Data Immediate
Data dataInstr = new Data(data);
dataInstr.DataImmediate();
dataInstr.ExecuteInstruction(true); // generate disassembly
return dataInstr;
case 0x2: // 010 - Load/Store Immediate
LdStore ldstrInstr = new LdStore(data);
ldstrInstr.LdStrImmediate();
ldstrInstr.ExecuteInstruction(true);
return ldstrInstr;
case 0x3: // 011 - Load/Store Immediate-shifted Register
LdStore ldstInstr = new LdStore(data);
ldstInstr.LdStrImmShiftedReg();
ldstInstr.ExecuteInstruction(true);
return ldstInstr;
case 0x4: // 100 - Load/Store Multiple
LoadStoreMultiple ldstrMul = new LoadStoreMultiple(data);
ldstrMul.LdStrMultiple();
ldstrMul.ExecuteInstruction(true);
return ldstrMul;
case 0x5: // 101 - Branch
Branch b = new Branch(data);
b.Branch();
b.ExecuteInstruction(true);
return b;
case 0x07: // 111 - SWI
SWI swiInstr = new SWI(data);
swiInstr.LoadDataSWI();
swiInstr.ExecuteInstruction(true);
return swiInstr;
default:
// an unsupported instruction was provided
Instruction i = new Instruction();
return i;
}
}
}
}