summaryrefslogtreecommitdiff
path: root/alu/v0.1_16bit/alu.v
blob: 05bf2277e64e9427c335b155195e49d0022ebfa6 (plain) (blame)
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
module alu(
    input [15:0]a,b,
    input [2:0]alu_sel,
    output [15:0]alu_out,
    output carry_out
);

reg [7:0]alu_result;
wire [8:0]tmp;

assign alu_out=alu_result; //result from alu
//???
assign tmp = {1'b0,a}+{1'b0,b};


always @(*) 
begin
    case (alu_sel)
    4'b0000: //addition
        alu_result = a+b;
    4'b0001: //substraction
        alu_result = a-b;
    4'b0010: //multiplication
        alu_result = ~a;
    4'b0011: //division
        alu_result = a<<b;
    4'b0100: //logical shift left
        alu_result = a>>b;
    4'b0101: //logical shift right
        alu_result = a&b;
    4'b0110: //rotate right
        alu_result = a|b;
    4'b0111: //rotate left
        begin 
            if (a<b) alu_result = 16'd1;
            else alu_result = 16'd0;
        end
    default: 
        alu_result = a+b;
    endcase
end

assign zero = (alu_result==16'd0) ? 1'b1: 1'b0;


endmodule