Logic Symbol:
Function Table:
CODE:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module alu(input [3:0] A,B, | |
input [3:0] S, | |
input Cin, | |
output reg [3:0] F, | |
output reg Cout); | |
always @(*) | |
begin | |
if ( M == 1) | |
case (S) | |
4'b0000: F = ~A; | |
4'b0001: F = ~A | ~B; | |
4'b0010: F = ~A | B; | |
4'b0011: F = 4'b1111; | |
4'b0100: F = ~A & ~B; | |
4'b0101: F = ~B; | |
4'b0110: F = A ^ ~B; | |
4'b0111: F = A | ~B; | |
4'b1000: F = ~A & B; | |
4'b1001: F = A ^ B; | |
4'b1010: F = B; | |
4'b1011: F = A | B; | |
4'b1100: F = 4'b0000; | |
4'b1101: F = A & ~B; | |
4'b1110: F = A & B; | |
4'b1111: F = A; | |
default: F = 4'b0000; | |
endcase | |
else | |
case (S) | |
4'b0000: F = A – 1 + Cin; | |
4'b0001: F = (A & B)–1+ Cin; | |
4'b0010: F = (A& ~B)–1+ Cin; | |
4'b0011: F = 4'b1111+ Cin; | |
4'b0100: F =A+ (A | ~B)+ Cin; | |
4'b0101: F = (A& B) + (A | ~B)+ Cin; | |
4'b0110: F =A–B– 1 + Cin; | |
4'b0111: F = (A | ~B) + Cin; | |
4'b1000: F =A+ (A | B)+ Cin; | |
4'b1001: F =A+B+ Cin ; | |
4'b1010: F = (A & ~B)+ (A | B)+ Cin; | |
4'b1011: F = (A | B) + Cin; | |
4'b1100: F = A + B + Cin; | |
4'b1101: F = (A & B) + A + Cin; | |
4'b1110: F = (A & ~B) + A + Cin; | |
4'b1111: F = A + Cin; | |
default: F = 4'b0000; | |
endcase | |
end | |
endmodule |