-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.sv
42 lines (37 loc) · 758 Bytes
/
alu.sv
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
`include "cc.sv"
/* ALU interface types. */
package alu;
/* Operations supported by the ALU. */
typedef enum bit [2:0] {
ADD,
AND,
XOR,
LSL,
LSR,
MUL,
OR,
SUB
} op_t;
endpackage
/* ALU implementation. */
module Alu(
input alu::op_t op,
input [15:0] a,
input [15:0] b,
output [15:0] result,
output [2:0] cc
);
Cc Cc(.value(result), .cc(cc));
always @(*) begin
case(op)
alu::ADD: result = a + b;
alu::AND: result = a & b;
alu::XOR: result = a ^ b;
alu::LSL: result = a << b[3:0];
alu::LSR: result = a >> b[3:0];
alu::MUL: result = a * b;
alu::OR: result = a | b;
alu::SUB: result = a - b;
endcase
end
endmodule