21-CP-6 (Report12) DLD
21-CP-6 (Report12) DLD
21-CP-6 (Report12) DLD
TECHNOLOGY, TAXILA
Lab Report 12
Digital Logic Design Lab
Name: Alina Gulzar
Section: Omega
LAB Tasks:
1. Write Verilog Code for 2x1 and 4x1 Mux along with Test Bench and simulate it on Icarus
Verilog.
2. Write Verilog Code for 4 bit Adder using data flow modeling along with Test Bench and
simulate it on Icarus Verilog.
3. Write Verilog Code for Comparator along with Test Bench 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.
• Mux (2x1)
Verilog Code:
module mux21(Y, D0, D1, S);
output Y;
input D0, D1, S;
assign Y= (S) ? D1 : D0 ;
endmodule
Test Bench:
module mux21tb;
wire out;
reg d0, d1, s;
mux21 name(.Y(out), .D0(d0), .D1(d1), .S(s));
initial
begin
d0=1'b0;
d1=1'b0;
s=1'b0;
#100 $finish;
end
always #40 d0=~d0;
always #20 d1=~d1;
always #10 s=~s;
always@(d0 or d1 or s)
$monitor("At time = %t, Output = %d", $time, out);
initial
begin
$dumpfile ("mux21tb.vcd");
$dumpvars (0, mux21tb);
end
endmodule
Simulation:
• Mux (4x1)
Verilog Code:
module mux41 ( input a,
input b,
input c,
input d,
input s0, s1,
output out);
endmodule
Test Bench:
module mux41tb;
wire out;
reg a;
reg b;
reg c;
reg d;
initial
begin
s0=1'b0; s1=1'b0;
#500 $finish;
end
always #5 d=~d;
always@(a or b or c or d or s0 or s1)
initial
begin
$dumpfile ("mux41tb.vcd");
end
endmodule
Simulation:
• 4-bit Adder
Verilog Code:
module adder4bit (sum, Cout, A, B, Cin);
input [3:0] A, B;
input Cin;
output [3:0] sum;
output Cout;
endmodule
Test Bench:
module adder4bittb ( );
initial
begin
end
initial
begin
$dumpfile ("adder4bittb.vcd");
$dumpvars (0, adder4bittb);
end
endmodule
Simulation:
• Comparator
Verilog Code:
module cmp (EQ, LT, GT, In1, In2);
endmodule
Test Bench:
module cmptb;
initial
begin
$dumpfile ("cmptb.vcd");
$dumpvars (0, cmptb);
end
endmodule
Simulation:
Results:
We have verified the truth table of Mux (2x1 and 4x1) , 4-bit adder and comparator. Their outputs
are correct.
Conclusion:
Dataflow modelling uses the functions that determine how the circuit operates, instead of using
the gate structure of the circuit. Dataflow modelling is becoming more and more well-liked as
a design method because of the emergence of sophisticated logic synthesis tools. By using this
method, the circuit designer can focus on enhancing data flow across the circuit.