-
Notifications
You must be signed in to change notification settings - Fork 0
/
alternate_alu_implementation.v
38 lines (36 loc) · 1.04 KB
/
alternate_alu_implementation.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
//====================================================
// ALU
//====================================================
module ALU(clk, A, B, opcode, result)
// I/O
input clk;
input [15:0] A, B;
input [3:0] opcode;
output [15:0] result;
always @ (posedge clk)
begin
case(opcode):
//4'b0000: //NO-OP
// result = result;
4'b0001: // RESET
result = 16'b0000000000000000;
4'b0010: //ADD
result = A + B;
4'b0100: //SUBTRACT
result = A - B;
4'b0101: //AND
result = A & B;
4'b1000: //OR
result = A | B;
4'b1001: //XOR
result = A ^ B;
4'b1010: //NAND
result = ~(A + B);
4'b1011: //NOR
result = ~(A | B);
4'b1101: //NOT
result = ~A;
default: result = A + B;
endcase
end
endmodule