-
Notifications
You must be signed in to change notification settings - Fork 0
/
mips-alu.v
77 lines (54 loc) · 1.1 KB
/
mips-alu.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
module MIPS_ALU
(
ALUCntrl_in,
A_in,
B_in,
ALU_out,
zero_out
);
parameter ALU_delay = 22;
parameter zero_delay = 3;
output [31:0] ALU_out;
reg [31:0] ALU_out;
output zero_out;
reg zero_out;
input [3:0] ALUCntrl_in;
input [31:0] A_in, B_in;
reg [31:0] temp;
always@*
begin
#ALU_delay;
case(ALUCntrl_in)
4'b0000: // and
ALU_out = A_in & B_in;
4'b0001: // or
ALU_out = A_in | B_in;
4'b0010: // add
ALU_out = A_in + B_in;
4'b0110: // sub
ALU_out = A_in - B_in;
4'b0111: // slt
begin
temp = A_in - B_in;
if(temp[31])
ALU_out = 32'd1;
else
ALU_out = 32'd0;
end
4'b1100: // nor
ALU_out = ~(A_in | B_in);
4'b1111: // lui
ALU_out = {B_in[15:0], 16'b0};
default: // all other control values
ALU_out = 32'bx;
endcase // case(ALUCntrl_in)
end // always@ *
always@*
begin
#zero_delay;
if (~(|ALU_out))
zero_out = 1;
else
zero_out = 0;
end
endmodule