-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstructionControl.v
74 lines (56 loc) · 1.51 KB
/
InstructionControl.v
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
module InstructionControl (
input [31:0] instruction,
output reg [4:0] op_code,
output reg num_op_code,
output reg [4:0] reg1, reg2, reg3,
output reg [24:0] immediate
);
always @ (*)
begin
if (instruction[31] == 0) // Reg-Reg/Reg-I type
begin
op_code = instruction[31:27];
num_op_code = instruction[26];
reg1 = instruction[25:21];
reg2 = instruction[20:16];
reg3 = instruction[15:11];
immediate = instruction[15:0];
end
else if (instruction[31:27] == 5'b10000) // Not type
begin
op_code = instruction[31:27];
num_op_code = 0;
reg1 = instruction[25:21];
reg2 = instruction[20:16];
reg3 = 0;
immediate = 0;
end
else if (instruction[31:27] == 5'b10001) // NOP type
begin
op_code = instruction[31:27];
num_op_code = 0;
reg1 = 0;
reg2 = 0;
reg3 = 0;
immediate = 0;
end
else if (instruction[31:27] >= 5'b10010 & instruction[31:27] <= 5'b10101) // jump-branch type
begin
op_code = instruction[31:27];
num_op_code = 0;
reg1 = 0; // dont write in any reg
reg2 = 5'b10011;// reg num 20 from set instruction
reg3 = 0;
immediate = instruction[24:0];//addr to jump
end
else if (instruction[31:27] >= 5'b11000 ) // memory type
begin
op_code = instruction[31:27];
num_op_code = 0;
reg1 = instruction[25:21]; // reg addr (to write in bank)
reg2 = instruction[20:16]; // reg with addr to write/read
reg3 = instruction[15:11]; // reg with data to write
immediate = 0;
end
end
endmodule