CPE314-PIT Code
CPE314-PIT Code
output Y,
input A,
input B
);
assign Y=A&B;
endmodule
-------------------------------------------------------------------------------------------------------
Module OR_Gate (
output y,
input A,
input B
);
Assign Y=A|B;
endmodule
-------------------------------------------------------------------------------------------------------
module XOR_Gate (
output Y,
input A,
input B
);
assign Y = A ^ B;
Endmodule
module NOT_Gate (
output Y,
input A
);
assign Y = ~A;
endmodule
-------------------------------------------------------------------------------------------------------
module Basic_Gates (
input [3:0] A,
input [3:0] B,
output [3:0] and_out,
output [3:0] or_out,
output [3:0] xor_out,
output [3:0] not_out
);
-------------------------------------------------------------------------------------------------------
module Full_Adder (
input A,
input B,
input Cin,
output Sum,
output Cout
);
wire AB_xor;
wire A_and_B;
wire Cin_and_AB;
endmodule
-------------------------------------------------------------------------------------------------------
module Add_Sub (
output [3:0] Sum,
output C,
input [3:0] A, B,
input Sub
);
endmodule
-------------------------------------------------------------------------------------------------------
module MUX_5tol (
input [3:0] in0,
input [3:0] inl,
input [3:0] in2,
input [3:0] in3,
input [3:0] in4,
input [2:0] Opcode,
output reg [3:0] Out
);
always @(*) begin
case (Opcode)
3'b000: Out = in0;
3'b001: Out = inl;
3'b010: Out = in2;
3'b011: Out = in3;
3'b100: Out = in4;
default: Out = 4'b0000;
endcase
end
Endmodule
-------------------------------------------------------------------------------------------------------
Module ALU_dbit (
Input [3:0] A,
Input [3:0] B,
Input [2:0] Opcode,
Output reg [3:0] Out,
Output reg C,
Output reg Z,
Output reg sign_bit
);
Always @(*)
Begin
Out <= 4’b0000;
Sign_bit <= 0;
Case (Opcode)
3’b000; begin
{C, Out} <= A+B;
End
3’b001: begin
C <= 0;
If (A < B) begin
B_twos_complement <= ~ B +1;
Sum1 <= A+B_twos_complement;
Sum <= sum1 + 1;
out <= sum[3 :0;
Sign_bit <= 1;
End else begin
Out <= A - B;
Sign_bit <= 0;
End
End
3’b010: begin
Out <= and_out;
C <= 0;
End
3’b011: begin
Out <= or_out;
C <= 0;
End
3’b100: begin
Out <= xor_out;
C <= 0;
End
3’b010: begin
Out <= not_out;
C <= 0;
End
default: begin
Out <= 4’b0000;
C <= 0;
End
endcase