Assignment 5 E23CSEU0698
Assignment 5 E23CSEU0698
Lab Assignment 5
Sanskar Sengar
E23CSEU0667
Example: Adders (perform addition), Encoders (convert information from one format
or code to another), Multiplexers (select one out of several input signals).
1.1
Assignment 5 – Sanskar Sengar 2
Example : Flip-Flops (basic memory element storing one bit of information), Counters
(increment or decrement in response to input pulses), Registers (store multiple bits
of data)
2.1
Assignment 5 – Sanskar Sengar 3
Let control = 1, A = In0, In1, In2, In3 then Y(Output of XOR gate) = (In0, In1,
3.1
Assignment Assignment 5 – Sanskar Sengar 4
initial begin
$display(”A B SUM CARRY” );
$display(” ” );
end
initial begin
$monitor(”%d %d %d %d” ,A,B,S,C);
A = 0; B = 0; #10;
A = 1; B = 0; #10;
A = 0; B = 1; #10;
A = 1; B = 1; #10;
$finish ; end
endmodule
Truth Table:
3.1
Question 4 Write truth table and Verilog code to im-
Assignment 5 – Sanskar Sengar 5
endmodule
reg A,B,C; wire sum, carry ; full adder q4 (. a(A) , .b(B) , . Cin(C) , .Sum(sum) , .
Cout( carry ) );
4.1
$display(”A B Cin SUM CARRY” ); end
initial begin
$monitor(”%d %d %d %d %d” , A,B,C,sum, carry
A = 0; B = 0; C = 0; #10;
Assignment Assignment 5 – Sanskar Sengar 6
initial begin
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; end
endmodule
Truth Table:
4.1
Question 5 Write truth table and Verilog code to im-
plement Half Subtractor using only NAND gates.
Answer 5.1
Design File:
Assignment 5 – Sanskar Sengar 7
Testbench File:
module main nand tb ; reg A,B; wire D, Borrow ; half subtractor nand q5 (. a(A) , .b(B) ,
.d(D) , . Borrow(Borrow ));
initial begin
$display(”A B DIFF CARRY” );
$display(” ” );
end
5.1
$monitor(”%d %d %d %d” ,A,B,D, Borrow );
A = 0; B = 0; #10;
A = 1; B = 0; #10;
A = 0; B = 1; #10;
A = 1; B = 1; #10;
$finish ;
end endmodule
Truth Table:
Assignment Assignment 5 – Sanskar Sengar 8
initial begin
Table 3: Truth Table for Binary Subtraction
A B DIFF CARRY
0 0 0 1
1 0 1 0
0 1 1 1
1 1 0 0
Output:
5.1