-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.v
38 lines (23 loc) · 785 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
`timescale 1ns / 1ps
module alu(
input [31:0] a, //src1
input [31:0] b, //src2
input [3:0] alu_control, //function sel
output reg [31:0] result, //result
output zero
);
always @ (*)
begin
case (alu_control)
4'b0000: result = a & b;
4'b0001: result = a | b;
4'b0010: result = a + b;
4'b0110: result = a - b;
4'b0111: result = (a > b ) ? b : a ;
4'b1100: result = ~ (a ^ b ) ;
4'b0011: result = a ; // JR
// default:result = a + b; // add
endcase
end
assign zero = (result == 0 ) ? 1'b1 : 1'b0 ;
endmodule