DLD (Assignment 2)
DLD (Assignment 2)
VERILOG CODE:
module NumberDetector (Sum, a, b, c, d)
output Sum;
input a, b, c, d;
assign Sum={(a&&b&&c&&d)||(a&&b&&c&&!d)||(a&&b&&!c&&d)||(!a&&!b&&c&&!d)
||(!a&&!b&&!c&&d)||(!a&&!b&&!c&&!d)}
end module
CIRCUIT:
a
b
c
d
Sum
SIMULATION:
d
Sum
QUESTION: 02
Write the Verilog code for logic circuit that meet the following requirements:
A battery-powered lamp in a room is to be operated from two switches, one at the back door
and one at the front door. The lamp is to be on if the front switch is on and the back switch is
off, or if the front switch is off and the back switch is on. The lamp is to be off if both switches
are off or if both switches are on. Let a HIGH output represent the on condition and a LOW
output represent the off condition. [CLO 2]
VERILOG CODE:
module Switch (X, A, B)
output X;
input A, B;
assign X = {(A&&!B)||(!A&&B)}
end module
CIRCUIT:
A
B X
SIMULATION:
B
X
QUESTION: 03
Parity bits are often used in digital communication for error detection and correction. The
simplest of these involve transmitting one additional bit with the data, a parity bit. In these
system the parity bit is attached to a group of transmitting bits to make the total number of 1s
in a group always even or always odd. An even parity bit makes number of 1s even and odd
parity bit makes the total number of 1s odd. Write the VHDL for parity generator that generates
a 5 bit odd parity generation for a 4 bit input number/group. [CLO 2]
VHDL CODE:
entity Parity_generator is
port(B1, B2, B3, B4: in bit;
P : out bit);
end Parity_generator;
SIMULATION:
QUESTION: 04
Write the Verilog code for 6 bit subtractor i.e.
S(6bit) = A(6bit) – B(6bit)
Where,
A,B is a 6 bit signed number
VERILOG CODE:
(PART 01)
SIMULATION:
VERILOG CODE:
(PART 02)
output [5:0]S;
output Co;
input [5:0]A, B;
input Ci;
wire [4:0]x;
end module
CIRCUIT:
SIMULATION:
VERILOG CODE:
(PART 03)
output [5:0]S;
output Co;
input [5:0]A, B;
input Ci;
wire [5:0]X;
xor(X[0],B[0],Ci);
xor(X[1],B[1],Ci);
xor(X[2],B[2],Ci);
xor(X[3],B[3],Ci);
xor(X[4],B[4],Ci);
xor(X[5],B[5],Ci);
end module
CIRCUIT:
SIMULATION: