Dunna Sravan Kumar21BCE5726 Exp-2
Dunna Sravan Kumar21BCE5726 Exp-2
Dunna Sravan Kumar21BCE5726 Exp-2
EXPERIMENT NO.(HW/SW): 2
AIM:
(a) Design and construct half adder circuits and verify the truth table using logic gates.
(b) Do design and construct half subtractor circuits and verify the truth table using logic gates.
(c) Design a partial simplified Arithmetic Logic Unit (ALU) using basic logic gates, which can
perform the 1-bit arithmetic addition operation with the inclusion of carry as an additional input.
(d) Design a partial simplified Arithmetic Logic Unit (ALU) using basic logic gates, which can
perform the 1-bit arithmetic subtraction operation with the inclusion of borrow as an additional
input.
IC PIN DIAGRAM:
i) GATE LEVEL MODELING:
1. HALF ADDER:
module ha_g(A,B,S,CA);
input A,B;
output S,CA;
xor(S,A,B);
and(CA,A,B);
endmodule
TESTBENCH:
module ha_g_tb;
reg A,B;
wire S,CA;
ha_g UUT(A,B,S,CA);
initial
begin
A=0;B=0;
#10 A=0;B=1;
#10 A=1;B=0;
#10 A=1;B=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,S=%b,CA=%b",A,B,S,CA);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
2. HALF SUBTRACTOR:
module hs_g(A,B,D,BO);
input A,B;
output D,BO;
wire W1;
xor(D,A,B);
not(W1,A);
and(BO,B,W1);
endmodule
TESTBENCH:
module hs_g_tb;
reg A,B;
wire D,BO;
hs_g UUT(A,B,D,BO);
initial
begin
A=0;B=0;
#10 A=0;B=1;
#10 A=1;B=0;
#10 A=1;B=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,D=%b,BO=%b",A,B,D,BO);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
3. FULL ADDER:
module fa_g(A,B,C,S,CA);
input A,B,C;
output S,CA; wire
W1,W2,W3;
xor(W1,A,B);
xor(S,W1,C);
and(W2,A,B);
and(W3,W1,C);
or(CA,W3,W2);
endmodule
TESTBENCH:
module fa_g_tb;
reg A,B,C;
wire S,CA;
fa_g UUT(A,B,C,S,CA);
initial
begin
A=0;B=0;C=0; #10
A=0;B=0;C=1;
#10 A=0;B=1;C=0;
#10 A=0;B=1;C=1;
#10 A=1;B=0;C=0;
#10 A=1;B=0;C=1;
#10 A=1;B=1;C=0;
#10 A=1;B=1;C=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,C=%b,S=%b,CA=%b",A,B,C,S,CA);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
4. FULL SUBTRACTOR:
module fs_g(A,B,C,D,BO);
input A,B,C;
output D,BO;
wire W1,W2,W3,W4,W5;
xor(W1,A,B);
xor(D,W1,C);
not(W2,A);
and(W3,W2,B);
not(W4,W1);
and(W5,W4,C);
or(BO,W5,W3);
endmodule
TESTBENCH:
module fs_g_tb;
reg A,B,C;
wire D,BO;
fs_g UUT(A,B,C,D,BO);
initial
begin
A=0;B=0;C=0; #10
A=0;B=0;C=1;
#10 A=0;B=1;C=0;
#10 A=0;B=1;C=1;
#10 A=1;B=0;C=0;
#10 A=1;B=0;C=1;
#10 A=1;B=1;C=0;
#10 A=1;B=1;C=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,C=%b,D=%b,BO=%b",A,B,C,D,BO);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
ii) DATAFLOW MODELLING:
ha_d(A,B,S,CA); input
A,B;
output S,CA;
assign S=A^B;
assign CA=A&B;
endmodule
TESTBENCH:
module ha_d_tb;
reg A,B;
wire S,CA;
ha_d UUT(A,B,S,CA);
initial
begin
A=0;B=0;
#10 A=0;B=1;
#10 A=1;B=0;
#10 A=1;B=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,S=%b,CA=%b",A,B,S,CA);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
2. HALF SUBTRACTOR:
module hs_d(A,B,D,BO);
input A,B;
D=A^B; assign
BO=(~A)&B;
endmodule
TESTBENCH:
module hs_d_tb;
reg A,B;
wire D,BO;
hs_d UUT(A,B,D,BO);
initial
begin
A=0;B=0;
#10 A=0;B=1;
#10 A=1;B=0;
#10 A=1;B=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,D=%b,BO=%b",A,B,D,BO);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
3. FULL ADDER:
module fa_d(A,B,C,S,CA);
input A,B,C;
S=A^(B^C);
assign CA=(A^B)&C|(A&B);
endmodule
TESTBENCH:
module fa_d_tb;
reg A,B,C;
wire S,CA;
fa_d UUT(A,B,C,S,CA);
initial
begin
A=0;B=0;C=0; #10
A=0;B=0;C=1;
#10 A=0;B=1;C=0;
#10 A=0;B=1;C=1;
#10 A=1;B=0;C=0;
#10 A=1;B=0;C=1;
#10 A=1;B=1;C=0;
#10 A=1;B=1;C=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,C=%b,S=%b,CA=%b",A,B,C,S,CA);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
4. FULL SUBTRACTOR:
module fs_d(A,B,C,D,BO);
input A,B,C;
D=A^(B^C);
assign BO=((~A)&B)|(C&(~(A^B)));
endmodule
TESTBENCH:
module fs_d_tb;
reg A,B,C;
wire D,BO;
fs_d UUT(A,B,C,D,BO);
initial
begin
A=0;B=0;C=0; #10
A=0;B=0;C=1;
#10 A=0;B=1;C=0;
#10 A=0;B=1;C=1;
#10 A=1;B=0;C=0;
#10 A=1;B=0;C=1;
#10 A=1;B=1;C=0;
#10 A=1;B=1;C=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,C=%b,D=%b,BO=%b",A,B,C,D,BO);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
iii) BEHAVIOURAL MODELLING:
ha_b(A,B,S,CA); input
A,B;
output S,CA;
reg S,CA;
always @(A or B)
begin
case({A,B})
endcase
end endmodule
TESTBENCH:
module ha_b_tb;
reg A,B;
wire S,CA;
ha_b UUT(A,B,S,CA);
initial
begin
A=0;B=0;
#10 A=0;B=1;
#10 A=1;B=0;
#10 A=1;B=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,S=%b,CA=%b",A,B,S,CA);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
2. HALF SUBTRACTOR:
module hs_b(A,B,D,BO);
input A,B;
output D,BO;
reg D,BO;
always @(A or B)
begin
case({A,B})
endcase
end endmodule
TESTBENCH:
module hs_b_tb;
reg A,B;
wire D,BO;
hs_b UUT(A,B,D,BO);
initial
begin
A=0;B=0;
#10 A=0;B=1;
#10 A=1;B=0;
#10 A=1;B=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,D=%b,BO=%b",A,B,D,BO);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
3. FULL ADDER:
module fa_b(A,B,C,S,CA);
input A,B,C;
output S,CA;
reg S,CA;
always @(A or B or C)
begin
case({A,B,C})
endcase
end endmodule
TESTBENCH:
module fa_b_tb;
reg A,B,C;
wire S,CA;
fa_b UUT(A,B,C,S,CA);
initial
begin
A=0;B=0;C=0; #10
A=0;B=0;C=1;
#10 A=0;B=1;C=0;
#10 A=0;B=1;C=1;
#10 A=1;B=0;C=0;
#10 A=1;B=0;C=1;
#10 A=1;B=1;C=0;
#10 A=1;B=1;C=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,C=%b,S=%b,CA=%b",A,B,C,S,CA);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
4. FULL SUBTRACTOR:
module fs_b(A,B,C,D,BO);
input A,B,C;
output D,BO;
reg D,BO;
always @(A or B or C)
begin
case({A,B,C})
endcase
end
endmodule
TESTBENCH:
module fs_b_tb;
reg A,B,C;
wire D,BO;
fs_b UUT(A,B,C,D,BO);
initial
begin
A=0;B=0;C=0; #10
A=0;B=0;C=1;
#10 A=0;B=1;C=0;
#10 A=0;B=1;C=1;
#10 A=1;B=0;C=0;
#10 A=1;B=0;C=1;
#10 A=1;B=1;C=0;
#10 A=1;B=1;C=1;
#10 $stop;
end
initial
begin
$monitor($time,"A=%b,B=%b,C=%b,D=%b,BO=%b",A,B,C,D,BO);
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
RESULT/INFERENCE: The half adder, half subtractor, full adder and full subtractor have been
constructed and their truth tables are verified.