-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcoder2.v
98 lines (88 loc) · 2.75 KB
/
dcoder2.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
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
module dcoder2(
input [3:0] opcode, op1,
input [15:0] op2, memdatr, aluout,
input rst, clk,
output reg [15:0] aluop1, aluop2, memdatw,
output reg [3:0] aluopcode, address,
output reg rw, cs, done, aludo
);
reg [2:0] state;
/*
state 0: init
state 1: fetch op1 data
state 2: fetch op2 data
state 3: aluopcode <= opcode -> alu executes
state 4: write back to register (op1)
*/
always @ (posedge clk) begin
if (rst) begin
state <= 0;
cs <= 0;
aluop1 <= 0;
aluop2 <= 0;
aluopcode <= 0;
done <= 0;
aludo <= 0;
end
else begin
case (state)
3'b000: begin
cs <= 0;
done <= 0;
aluop1 <= 0;
aluop2 <= 0;
aluopcode <= 0;
state <= 3'b001;
aludo <= 0;
end
3'b001: begin
state <= 3'b010;
if (opcode != 4'd7) begin
address <= op2[3:0];
cs <= 1;
rw <= 1;
end
end
3'b010:begin
state <= 3'b011;
// if (opcode != 4'd7) begin
address <= op1;
// end
end
3'b011:begin
state <= 3'b100;
if (opcode != 4'd7) begin
aluop2 <= memdatr;
end
end
3'b100:begin
rw <= 0 ;
state <= 3'b101;
if (opcode != 4'd7) begin
aluop1 <= memdatr;
aludo <= 1 ;
aluopcode <= opcode ;
end
end
3'b101: state <= 3'b110;
3'b110: begin
state <= 3'b111;
cs <= 1;
rw <= 0;
end
3'b111:begin
done <= 1;
state <= 3'b000;
if (opcode != 4'd7) begin
memdatw <= aluout;
aludo <= 0;
end
else begin
memdatw <= op2;
end
end
default:state <= 3'd0;
endcase
end
end
endmodule