-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.v
52 lines (47 loc) · 1.11 KB
/
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 20:30:57 09/30/2018
// Design Name:
// Module Name: alu
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module alu (
input i_clk,
input i_rst,
input i_enable,
input i_subtract, // 0 - add, 1 - subtract
input [7:0] i_reg_a,
input [7:0] i_reg_b,
output o_carry,
output o_zero,
output [7:0] o_result
);
// additional bit for the carry
reg [7+1:0] out = 0;
assign o_result = i_enable ? out[7:0] : 8'bZZ;
assign o_carry = out[8];
assign o_zero = out[7:0] == 8'h00;
always @* begin
if (~i_rst) begin
out <= 0;
end else begin
if (i_subtract)
out <= i_reg_a - i_reg_b;
else
out <= i_reg_a + i_reg_b;
end
end
endmodule