-
Notifications
You must be signed in to change notification settings - Fork 0
/
alu.v
64 lines (46 loc) · 958 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
55
56
57
58
59
60
61
62
63
64
`timescale 1ns/1ps
module alu
#( parameter[3:0] LAND = 4'b0000,
LOR = 4'b0001,
ADD = 4'b0010,
SUB = 4'b0110,
LESS = 4'b0111,
LSHR = 4'b1000,
LSHL = 4'b1001,
ASHR = 4'b1010,
LXOR = 4'b1101
)
(
input [31:0] op1,
input [31:0] op2,
input [3:0] alu_op,
output reg zero,
output reg [31:0] result
);
always @(op1, op2, alu_op)
begin
case(alu_op)
//logic and
LAND:result = op1 & op2;
//logic or
LOR: result = op1 | op2;
//addition
ADD: result = op1 + op2;
//subtraction
SUB: result = op1 - op2;
//less than
LESS: result = $signed(op1) < $signed(op2);
//logic shift right
LSHR: result = op1 >> op2[4:0];
//logic shift left
LSHL: result = op1 << op2[4:0];
//arithmetic shift right
ASHR: result = $unsigned($signed(op1) >>> op2[4:0]);
//logix xor
LXOR: result = op1 ^ op2;
//set default value to zero
default: result=0;
endcase
zero = ~|result ;
end
endmodule