Professional Documents
Culture Documents
21-CP-6 (Report10) DLD
21-CP-6 (Report10) DLD
TECHNOLOGY, TAXILA
Lab Report 10
Digital Logic Design Lab
Name: Alina Gulzar
Section: Omega
LAB Tasks:
1. Write Verilog Code for Even Parity Generator for 3-bit Message and simulate it on Icarus
Verilog
2. Write Verilog Code for Odd Parity Generator for 3-bit Message and simulate it on Icarus
Verilog
3. Write Verilog Code for Half Adder and simulate it on Icarus Verilog
4. Write Verilog Code for 1-bit Full Adder simulate it on Icarus Verilog
Design Methodology:
• First of all, we have to create a folder so that all the related files are in the same folder.
• Open Notepad, and write the Verilog code, save that notepad file in [module_name.v]
extension. The name of file and name of module must be same. As Verilog HDL is the case
sensitive Language so, a smallest mistake will cause an error.
• Again open notepad and write a test bench for the code file and save this file as syntax:
[module_nametb.v].
• Now, copy both files and open Local Disk: C → iverilog → bin → Paste the files.
• Click on the address bar.
3. Half Adder
Input Output
A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Test Bench:
module evenparity_tb ();
reg x,y,z;
wire S;
evenparity DUT(S,x,y,z);
initial
begin
x=1'b0; y=1'b0; z=1'b0;
#10 x=1'b0; y=1'b0; z=1'b1;
#10 x=1'b0; y=1'b1; z=1'b0;
#10 x=1'b0; y=1'b1; z=1'b1;
#10 x=1'b1; y=1'b0; z=1'b0;
#10 x=1'b1; y=1'b0; z=1'b1;
#10 x=1'b1; y=1'b1; z=1'b0;
#10 x=1'b1; y=1'b1; z=1'b1;
end
initial
begin
$dumpfile("evenparitytb.vcd");
$dumpvars(0, evenparitytb);
end
endmodule
Simulation:
2. Odd Parity Generator
Verilog Code:
module oddparity(W, X, Y, Z);
input X, Y,Z ;
output O;
wire w1;
endmodule
Test Bench:
module oddparitytb();
reg X, Y, Z;
wire O;
oddparity(O, X, Y, Z);
initial
begin
X=1'b0; Y=1'b0; Z=1'b0;
#10 X=1'b0; Y=1'b0; Z=1'b1;
#10 X=1'b0; Y=1'b1; Z=1'b0;
#10 X=1'b0; Y=1'b1; Z=1'b1;
#10 X=1'b1; Y=1'b0; Z=1'b0;
#10 X=1'b1; Y=1'b0; Z=1'b1;
#10 X=1'b1; Y=1'b1; Z=1'b0;
#10 X=1'b1; Y=1'b1; Z=1'b1;
end
initial
begin
$dumpfile ("oddparitytb.vcd");
$dumpvars (0, oddparitytb);
end
endmodule
Simulation:
3. Half Adder
Verilog Code:
module halfadder (S, C, A, B);
input A, B;
output S, C;
xor x1(S, A, B);
and a1(C, A, B);
endmodule
Test Bench:
module halfaddertb ( );
reg X, Y;
wire Sum, Carry;
halfadder DUT (Sum , Carry, X, Y);
initial
begin
X=1'b0; Y=1'b0;
#10 X=1'b0; Y=1'b1;
#10 X=1'b1; Y=1'b0;
#10 X=1'b1; Y=1'b1;
end
initial
begin
$dumpfile ("halfadddertb.vcd");
$dumpvars (0, halfaddertb);
end
endmodule
Simulation:
4. 1-bit Full Adder
Verilog Code:
module fulladder (Sum, Carry, A, B, Cin);
input A, B, Cin;
output Sum, Carry;
wire w1, w2, w3;
halfadder HA1(.A(A), .B(B), .Sum(w1), .Carry(w2));
halfadder HA2(.A(w1), .B(Cin), .Sum(S), .Carry(w3));
or o(Carry, w2, w3 );
endmodule
module halfadder (Sum, Carry, A, B);
input A, B;
output Sum, Carry;
xor x1(Sum, A, B);
and a1(Carry, A, B);
endmodule
Test Bench:
module fulladdertb ( );
wire Sum, Carry;
reg A, B, Cin;
fulladder DUT(.Sum(Sum) , .Carry(Carry), .A(A), .B(B), .Cin(Cin));
initial
begin
A=1'b0; B=1'b0; Cin=1'b0;
#10 A=1'b0; B=1'b0; Cin=1'b1;
#10 A=1'b0; B=1'b1; Cin=1'b0;
#10 A=1'b0; B=1'b1; Cin=1'b1;
#10 A=1'b1; B=1'b0; Cin=1'b0;
#10 A=1'b1; B=1'b0; Cin=1'b1;
#10 A=1'b1; B=1'b1; Cin=1'b0;
#10 A=1'b1; B=1'b1; Cin=1'b1;
end
initial
begin
$dumpfile ("fulladddertb.vcd");
$dumpvars (0, fulladdertb);
end
endmodule
Simulation:
Results:
We have verified the truth table of Odd Parity, Even Parity, Half Adder and Full Adder. Their
outputs are correct.
Conclusion:
Parity comes in even and odd varieties. The output of an even parity generator will be a logic
1 if the data word has an odd number of ones. The parity generator's output will be low if the
data word has an even number of ones.
Half adders serve as a fundamental building component for aspiring digital artists. Two bits
can be added together using just a few basic logic gates, as demonstrated by a half-adder.
Because they can only accept two one-bit inputs, they are rarely used in practise.
Verilog code for simple modules conclusion full adder image result 1 bit
The output is 0 if all of the input bits are 0. When only one input or three inputs are equal to
1, the S output is also equal to 1. The c output has carry of 1 if two or three inputs are equal to
1.