-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopcode.java
More file actions
85 lines (82 loc) · 3.08 KB
/
opcode.java
File metadata and controls
85 lines (82 loc) · 3.08 KB
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
import java.util.ArrayList;
public class opcode {
private ArrayList<opcode> instructionSet = new ArrayList<>(32);
private String mnemonic;
private String opcode;
private int format;
public String getMnemonic() {
return mnemonic;
}
public String getOpcode() {
return opcode;
}
public int getFormat() {
return format;
}
public opcode(){
addInstructionsToTable();
}
public opcode(String mnemonic, String opcode, int format){
this.mnemonic = mnemonic;
this.opcode = opcode;
this.format = format;
}
//INSTRUCTION SET
public void addInstructionsToTable(){
instructionSet.add(new opcode("ADD ","18",3));
instructionSet.add(new opcode("AND ","40",3));
instructionSet.add(new opcode("COMP ","28",3));
instructionSet.add(new opcode("DIV ","24",3));
instructionSet.add(new opcode("J ","3C",3));
instructionSet.add(new opcode("JEQ ","30",3));
instructionSet.add(new opcode("JGT ","34",3));
instructionSet.add(new opcode("JLT ","38",3));
instructionSet.add(new opcode("JSUB ","48",3));
instructionSet.add(new opcode("LDA ","00",3));
instructionSet.add(new opcode("LDCH ","50",3));
instructionSet.add(new opcode("LDL ","08",3));
instructionSet.add(new opcode("LDX ","04",3));
instructionSet.add(new opcode("MUL ","20",3));
instructionSet.add(new opcode("OR ","44",3));
instructionSet.add(new opcode("RD ","D8",3));
instructionSet.add(new opcode("RSUB ","4C",3));
instructionSet.add(new opcode("STA ","0C",3));
instructionSet.add(new opcode("STCH ","54",3));
instructionSet.add(new opcode("STL ","14",3));
instructionSet.add(new opcode("STSW ","E8",3));
instructionSet.add(new opcode("STX ","10",3));
instructionSet.add(new opcode("SUB ","1C",3));
instructionSet.add(new opcode("TD ","E0",3));
instructionSet.add(new opcode("TIX ","2C",3));
instructionSet.add(new opcode("WD ","DC",3));
instructionSet.add(new opcode("FIX ","C4",1));
instructionSet.add(new opcode("FLOAT","C0",1));
instructionSet.add(new opcode("HIO ","F4",1));
instructionSet.add(new opcode("NORM ","C8",1));
instructionSet.add(new opcode("SIO ","F0",1));
instructionSet.add(new opcode("TIO ","F8",1));
}
// Getting Opcode
public String getOpOpcode(String mnemonic){
for (opcode op : instructionSet){
if (op.getMnemonic().equals(mnemonic))
return op.getOpcode();
}
return null;
}
// Getting Opcode format
public int getOpFormat(String opcode){
for(opcode op : instructionSet){
if(op.getOpcode().equals(opcode))
return op.getFormat();
}
return 0;
}
public int getOpInstFormat(String mnemonic){
for(opcode op : instructionSet){
if(op.getMnemonic().equals(mnemonic))
return op.getFormat();
}
return 0;
}
}