-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlUnitSequencer.java
More file actions
170 lines (148 loc) · 5.26 KB
/
ControlUnitSequencer.java
File metadata and controls
170 lines (148 loc) · 5.26 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
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
public class ControlUnitSequencer{
// Attributes that store data instructions from InstructionRegister
private Bit4 data;
// Attribute that stores the value of [ Cp , Ep , Lm ' CE ' ] , [ Li ' Ei ' , La ' , Ea ] , [ Su , Eu , Lb ' Lo '] on the last condition
private int[] bits;
// The constant that stores the initial value Control Unit ( at T0 )
private final static int[] INITIAL_STATE={0,0,1,1,1,1,1,0,0,0,1,1};
//Constants that you store the value of the Control Unit on the condition T1 ( state address )
private final static int[] ADDRESS_STATE={0,1,0,1,1,1,1,0,0,0,1,1};
// The constant that holds the value of the Control Unit on the condition T2 ( increment state )
private final static int[] INCREMENT_STATE={1,0,1,1,1,1,1,0,0,0,1,1};
// The constant that holds the value of the Control Unit in the T3 condition (memory state)
private final static int[] MEMORY_STATE={0,0,1,0,0,1,1,0,0,0,1,1};
// The constant that holds the value of the Control Unit at T4 condition for LDA , ADD and SUB
private final static int[] GET_RAM_VALUE={0,0,0,1,1,0,1,0,0,0,1,1};
// The constant that holds the value of the Control Unit at T4 condition for OUT
private final static int[] ACC_TO_OR={0,0,1,1,1,1,1,1,0,0,1,0};
// The constant that holds the value of the Control Unit on the conditions of T5 to LDA
private final static int[] RAM_TO_ACC={0,0,1,0,1,1,0,0,0,0,1,1};
// The constant that holds the value of the Control Unit on the of T5 for ADD and SUB
private final static int[] RAM_TO_BREG={0,0,1,0,1,1,1,0,0,0,0,1};
// The constant that holds the value of the Control Unit in the T6 condition for ADD
private final static int[] ADD_STATE={0,0,1,1,1,1,0,0,0,1,1,1};
// The constant that holds the value of the Control Unit in the T6 condition for SUB
private final static int[] SUB_STATE={0,0,1,1,1,1,0,0,1,1,1,1};
public ControlUnitSequencer(Bit4 data) {
this.data = data;
// first value bits = 0011 1110 0011
int[] values = {0,0,1,1,1,1,1,0,0,0,1,1};
bits = values;
}
public ControlUnitSequencer() {
// first value bits = 0011 1110 0011
int[] values = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1};
bits = values;
}
/**
* Method for get value from atribut bits
* @param index of position search
* @return value from index-...
*/
public int getBitsAt(int index) {
return bits[index];
}
/**
* Method for change value from atribut bits
* @param value position index want to change
* @return void
*/
private void changeValueAt(int index) {
switch(getBitsAt(index)) {
case 0:
setValueAt(index,1);
break;
case 1:
setValueAt(index,0);
break;
}
}
/**
* Method for set a value from atribut bits
* @param alue position index want to set and input for bit.
*/
private void setValueAt(int index, int input) {
bits[index] = input;
}
@Override
public String toString() {
String result = "";
for (int i=0; i<bits.length; i++){
result+= bits[i]+"";
}
return result;
}
public Bit4 getData() {
return data;
}
public void setData(Bit4 data) {
this.data = data;
}
public void setState(int tx){
switch(tx){
case 0:
bits=INITIAL_STATE;
break;
case 1:
bits=ADDRESS_STATE;
break;
case 2:
bits=INCREMENT_STATE;
break;
case 3:
bits=MEMORY_STATE;
break;
case 4:
if(this.data.toDecimal()==0){// instruksi LDA
bits=GET_RAM_VALUE;
}
else if(this.data.toDecimal()==1){// instruksi ADD
bits=GET_RAM_VALUE;
}
else if(this.data.toDecimal()==2){// instruksi SUB
bits=GET_RAM_VALUE;
}
else if(this.data.toDecimal()==14){// instruksi OUT
bits=ACC_TO_OR;
}
else{// instruksi HLT
bits=INITIAL_STATE;
}
break;
case 5:
if(this.data.toDecimal()==0){// instruksi LDA
bits=RAM_TO_ACC;
}
else if(this.data.toDecimal()==1){// instruksi ADD
bits=RAM_TO_BREG;
}
else if(this.data.toDecimal()==2){// instruksi SUB
bits=RAM_TO_BREG;
}
else if(this.data.toDecimal()==14){// instruksi OUT
bits=INITIAL_STATE;
}
else{// instruksi HLT
bits=INITIAL_STATE;
}
break;
case 6:
if(this.data.toDecimal()==0){// instruksi LDA
bits=INITIAL_STATE;
}
else if(this.data.toDecimal()==1){// instruksi ADD
bits=ADD_STATE;
}
else if(this.data.toDecimal()==2){// instruksi SUB
bits=SUB_STATE;
}
else if(this.data.toDecimal()==14){// instruksi OUT
bits=INITIAL_STATE;
}
else{// instruksi HLT
bits=INITIAL_STATE;
}
break;
}
}
}