-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALU.v
54 lines (51 loc) · 972 Bytes
/
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
//ALU Block
module ALU (a,b,shamt,funct,ALUOp,out,zero);
input [15:0]a,b;
input [4:0]shamt;
input [5:0]funct;
input [1:0]ALUOp;
output reg [31:0] out;
output reg zero;
always @(*)
begin
if(ALUOp == 2'b 00)
begin
out = a+b;
end
else if(ALUOp == 2'b 01)
begin
out = a - b;
end
else
begin
if(funct == 6'b 100000) //add
out = a+b;
else if(funct == 6'b 100010) //sub
out = a-b;
else if(funct == 6'b 011000) //mul
out = a*b;
else if(funct == 6'b 011010) //div
out = a/b;
else if(funct == 6'b 000000) //sll
out = a<<shamt;
else if(funct == 6'b 000010) //srl
out = a>>shamt;
else if(funct == 6'b 100101) //or
out = a|b;
else if(funct == 6'b 100100) //and
out = a&b;
else if(funct == 6'b 100111) //nor
out = ~(a|b);
else if(funct == 6'b 100110) //xor
out = (a&~b) + (~a&b);
else
begin
$display ("Error: Incorrent funct");
end
end
if(out == 0)
zero = 1;
else
zero = 0;
end
endmodule