Professional Documents
Culture Documents
Coal Lab 2
Coal Lab 2
Coal Lab 2
LAB# 02
Objective: The main objective of this lab is to well-aware about the Xilinx software, step to
run Xilinx software and to verify the truth tables of adders and ALU operations.
LAB ASSESSMENT:
Data presentation
Experimental results
Conclusion
`CODE:
timescale 1ns / 1ps
module HALFADDER(A,B,C_out,Carry);
input A,B;
output C_out,Carry;
xor(C_out, A,B);
and(Carry, A,B);
endmodule
Truth table:
HALF ADDER
INPUT: OUTPUT:
A B C_out Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Block diagram:
2: Implement a Full Adder using Xilinx. Also mention its truth table, mathematical.
modeling (includes equations etc.) and block diagram.
CODE:
module FULLADDEER(input A,
input B,
input Cin,
output Sum,
output Cout
);
endmodule
Truth table:
Truth table
Input Output
A B Cin Sum Cout
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Block Diagram:
3: Implement a Half adder using either NAND gate or NOR gate. Verify waveform of
above gates by writing test module.
Code:
endmodule
Test bench
module Half_adder_tb;
// Inputs
reg A;
reg B;
// Outputs
wire Sum;
wire Carry;
initial begin
// Initialize Inputs
A = 0;
B = 0;
end
endmodule
Wave form:
Block Diagram:
Task 2:
Part a: Implement an ALU that will perform 8 operations.
Code:
module ALU(ALU_out,A,B,ALU_sel);
input[7:0]A,B;
input[2:0]ALU_sel;
output reg[9:0]ALU_out;
always@(*)
begin
case(ALU_sel)
3'b000:ALU_out=A+B;
3'b001:ALU_out=A-B;
3'b010:ALU_out=A*B;
3'b011:ALU_out=A/B;
3'b100:ALU_out=A>>B;
3'b101:ALU_out=A<<B;
3'b110:ALU_out=A&B;
3'b111:ALU_out=A|B;
default:
ALU_out=A+B;
endcase
end
endmodule
Part b: Implement a 4x1 Multiplexer.
Code:
module MUX(
input [3:0] D,
input [1:0] S,
output Y
);
Circuit Diagram:
Wave form:
Conclusion:
In conclusion, the implementation of half adder, full adder, and ALU on Verilog provides a solid
foundation for designing and implementing digital circuits.
A half adder is a basic building block of digital circuits that is used to add two binary digits and
produce a sum and carry output. Its implementation on Verilog is straightforward and requires only a
few lines of code.
A full adder is a more complex circuit that is used to add three binary digits and produce a sum and
carry output. Its implementation on Verilog can be done using either basic logic gates or more
advanced operations, such as using a carry lookahead adder.
An ALU, or arithmetic logic unit, is a circuit that performs various arithmetic and logic operations on
binary data. Its implementation on Verilog can be done using a combination of half adders, full
adders, and other logic gates, such as AND, OR, XOR, and NOT gates.
Overall, Verilog provides a flexible and efficient way to design and implement digital circuits, and the
implementation of half adder, full adder, and ALU on Verilog provides a strong foundation for further
study and exploration in the field of digital circuits and computer architecture.