Ddco Lab Manual
Ddco Lab Manual
Ddco Lab Manual
K. S. Group of Institutions
K. S. SCHOOL OF ENGINEERING & MANAGEMENT
Mallasandra, Off Kanakapura Road, Bengaluru - 560 109
Department of
Computer Science & Business Systems
LABORATORY MANUAL
Digital Design & Computer Organization BCS302
CO1 Apply the K–Map techniques to simplify various Boolean Applying (K3)
expressions.
CO2 Design different types of combinational and sequential circuits Applying (K3)
along with Verilog programs.
LIST OF PROGRAMS
Program – 1
Given a 4-variable logic expression, simplify it using appropriate technique and simulate the same
using basic gates.
Program – 2
Design a 4-bit full adder and subtractor and simulate the same using basic gates.
Program – 3
Design Verilog HDL to implement simple circuits using structural, Data flow and Behavioural
model.
Program – 4
Design Verilog HDL to implement Binary Adder-Subtractor – Half and Full Adder, Half and Full
Subtractor.
Program – 5
Design Verilog HDL to implement Decimal adder.
Program – 6
Design Verilog program to implement Different types of multiplexers like 2:1, 4:1 and 8:1.
Program – 7
Design Verilog program to implement types of De-Multiplexer.
Program – 8
Design Verilog program for implementing various types of Flip-Flops such as SR, JK and D.
PO PO PO PO PO PO PO PO PO PO PO PO PSO PSO
CO PO
1 2 3 4 5 6 7 8 9 10 11 12 1 2
BCS K-
302 level
CO1 3 3 1 - 3 - - 2 - - - - 2 2
CO2 3 3 2 - 3 - - 2 3 - - - 2 2
CO3 2 2 1 - - - - 1 - - - - 2 2
CO4 2 2 2 - - - - 1 - - - - 2 2
CO5 2 3 2 - - - - 2 - - - - 2 2
VISION:
“To impart quality education in engineering and management to meet technological, business
and societal needs through holistic education and research”
MISSION:
K.S. School of Engineering and Management shall,
NI Multisim is an easy-to-use schematic capture and simulation environment that engineers, students,
and professors can use to define and simulate circuits.
Step 1: Open Multisim: Select Start» All Programs» National Instruments» Circuit Design Suite
11.0» Multisim 11.0 to open Multisim. Multisim opens showcasing the default capture and
simulation environment.
EXPERIMENTS
Experiment 1: -
Given a 4-variable logic expression, simplify it using appropriate technique and simulate the
same using basic gates.
Solution: -
Truth Table: -
Decimal A B C D Y
0 0 0 0 0 1
1 0 0 0 1 1
2 0 0 1 0 1
3 0 0 1 1 0
4 0 1 0 0 0
5 0 1 0 1 1
6 0 1 1 0 0
7 0 1 1 1 1
8 1 0 0 0 1
9 1 0 0 1 1
10 1 0 1 0 1
11 1 0 1 1 0
12 1 1 0 0 0
13 1 1 0 1 1
14 1 1 1 0 0
15 1 1 1 1 1
Experiment 2: -
Design a 4-bit full adder and subtractor and simulate the same using basic gates.
sum= A ⊕ B ⊕ C
carry=A B + B C + A C
Ex: A = 1101
+ B = 1001
Sum = 0110
C out = 1
Difference = A⨁B⨁C
Borrow = A’ B + B C + A’ C
Result:
Example: -
A3A2A1A0 = 1000
B3B2B1B0 = 0001
D3D2D1D0 = 0111
Cout=1
INTRODUCTION TO XILINX
Xilinx is one of most popular software tool, used to synthesize VHDL/Verilog code. This tool
includes many steps. To make user feel comfortable with the tool, the steps are given below:
Experiment 3: -
Design Verilog HDL to implement simple circuits using Structural, Data flow and
Behavioural model.
Structural Model: -
input a,b,c;
output y;
and(w1, a, b);
and(w2, b, c);
or(y,w1,w2);
endmodule
initial begin
// Initialize Inputs
#100 a=0; b=0; c=0;
#100 a=0; b=0; c=1;
#100 a=0; b=1; c=0;
#100 a=0; b=1; c=1;
#100 a=1; b=0; c=0;
#100 a=1; b=0; c=1;
#100 a=1; b=1; c=0;
#100 a=1; b=1; c=1;
Output Waveform: -
module p3(y,a,b,c);
input a,b,c;
output y;
assign y= (a&b)|(b&c);
endmodule
Output: -
Behavioral Model: -
module p3(y,a,b,c);
input a,b,c;
output y;
reg y;
always @(a,b,c)
begin
y= (a&b)|(b&c);
end
endmodule
Output: -
Experiment 4: -
Design Verilog HDL to implement Binary Adder-Subtractor – Half and Full Adder, Half and
Full Subtractor.
a. Half Adder:
module hfadd(
input a,b,
output sum,carry
);
endmodule
initial begin
// Initialize Inputs
a = 0;b = 0;#100;
a = 0;b = 1;#100;
a = 1;b = 0;#100;
a = 1;b = 1;#100;
Output Waveforms: -
b) Half subtractor: -
module hfadd(
input a,b,
output diff,borrow
);
assign diff=a^b;
assign borrow=(~a)&b;
endmodule
initial begin
a = 0;b = 0;#100;
a = 0;b = 1;#100;
a = 1;b = 0;#100;
a = 1;b = 1;#100;
Output Waveform: -
c) Full Adder: -
module hfadd(
input a,b,c,
output sum,carry
);
assign sum=a^b^c;
assign carry=(a&b)|(b&c)|(c&a);
endmodule
initial begin
// Initialize Inputs
#100 a=0; b=0;c=0;
#100 a=0; b=0;c=1;
#100 a=0; b=1;c=0;
#100 a=0; b=1;c=1;
#100 a=1; b=0;c=0;
#100 a=1; b=0;c=1;
#100 a=1; b=1;c=0;
#100 a=1; b=1;c=1;
Output Waveform: -
module hfadd(
input a,b,c,
output diff,borrow
);
assign diff=a^b^c;
assign borrow=((~a)&b)|(b&c)|(c&(~a));
endmodule
Test Bench Code: -
initial begin
Output Waveform: -
Experiment 5: -
initial begin
// Initialize Inputs
a = 0; b = 0; c = 0; #100;
a = 6; b = 9; c = 0; #100;
a = 3; b = 3; c = 1; #100;
a = 4; b = 5; c = 0; #100;
a = 8; b = 2; c = 0; #100;
a = 9; b = 9; c = 1; #100;
Output: -
Output Waveform: -
Experiment 6: -
Design Verilog program to implement Different types of multiplexers like 2:1, 4:1 and 8:1.
a. 2:1 Multiplexer:
module mulpx(A,d0,d1,y);
output y;
input d0;
input d1;
input A;
reg y;
always @ (d0,d1,A)
begin
y=((~A & d0)|(A & d1));
end
endmodule
initial begin
// Initialize Inputs
#100 A=0;d0=0;d1=0;
#100 A=0;d0=0;d1=1;
#100 A=0;d0=1;d1=0;
#100 A=0;d0=1;d1=1;
#100 A=1;d0=0;d1=0;
#100 A=1;d0=0;d1=1;
#100 A=1;d0=1;d1=0;
#100 A=1;d0=1;d1=1;
Output Waveform: -
b. 4:1 Multiplexer: -
module mulpx(y,d0,d1,d2,d3,a0,a1);
output y;
input d0,d1,d2,d3,a0,a1;
reg y;
always @ (d0,d1,d2,d3,a0,a1)
begin
y= (~a0 & ~a1 & d0) | (~a0 & a1 & d1) | (a0 & ~a1 & d2) | (a0 & a1 & d3);
end
endmodule
initial begin
// Initialize Inputs
#100 a0=0;a1=0;d0=0;
#100 a0=0;a1=1;d1=1;
#100 a0=1;a1=0;d2=0;
#100 a0=1;a1=1;d3=1;
Output Waveform: -
c. 8:1 Multiplexer: -
reg [7:0] i;
reg [2:0] s;
// Outputs
wire y;
// Instantiate the Unit Under Test (UUT)
mux81 uut (
.i(i),
.s(s),
.y(y)
);
initial begin
// Initialize Inputs
i=0;
s=0;
repeat(30)
begin
#40 i=i+1;
#40 s=s+1;
Output Waveform: -
Experiment 7: -
a. 1:2 Demultiplexer
module demux(D,A,Y0,Y1);
input D,A;
output Y0,Y1;
reg Y0,Y1;
always @ (A,D)
begin
Y0=(~A & D);
Y1=(A & D);
end
endmodule
#100 A=0;D=0;
#100 A=0;D=1;
#100 A=1;D=0;
#100 A=1;D=1;
Output Waveform: -
b. 1:4 Demultiplexer
module P714(D,A0,A1,Y0,Y1,Y2,Y3);
input D,A0,A1;
output Y0,Y1,Y2,Y3;
reg Y0,Y1,Y2,Y3;
always @(A0,A1,D)
begin
Y0=(~A0 & ~A1 & D);
Y1=(~A0 & A1 & D);
Y2=(A0 & ~A1 & D);
Y3=(A0 & A1 & D);
end
endmodule
c. 1:8 DEMULTIPLEXER
Output Waveform: -
Experiment 8: -
Design Verilog program for implementing various types of Flip-Flops such as SR, JK and D.
a. SR FLIP-FLOP
module SR_flipflop (
input clk, rst_n,
input s,r,
output reg q,
output q_bar
);
// always@(posedge clk or negedge rst_n) // for asynchronous reset
always@(posedge clk) begin
if(!rst_n) q <= 0;
else begin
case({s,r})
2'b00: q <= q; // No change
2'b01: q <= 1'b0; // reset
2'b10: q <= 1'b1; // set
2'b11: q <= 1'bx; // Invalid inputs
endcase
end
end
assign q_bar = ~q;
endmodule
#100; s= 0; r= 0;
#100; s= 0; r= 1;
#100; s= 1; r=1;
end
Output Waveform: -
b. JK FLIP-FLOP
module JK_flipflop (
input clk, rst_n,
input j,k,
output reg q,
output q_bar
);
// always@(posedge clk or negedge rst_n) // for asynchronous reset
always@(posedge clk) begin // for synchronous reset
if(!rst_n) q <= 0;
else begin
case({j,k})
2'b00: q <= q; // No change
2'b01: q <= 1'b0; // reset
2'b10: q <= 1'b1; // set
2'b11: q <= ~q; // output toggles
endcase
end
end
D FLIP-FLOP
module p8dff(d,clk,q);
input d,clk;
output q;
reg q;
begin
q<=d;
end
endmodule
initial begin
// Initialize Inputs
clk=0;
forever #10 clk = ~clk;
end
initial begin
#100; d <= 0;
#100; d <= 1;
#100; d <= 0;
#100; d <=0;
#100; d <= 1;
#100; d <= 1;
Output Waveform: -
VIVA QUESTIONS
A logic gate is an elementary building block of a digital circuit. Most logic gates have two inputs
and one output. At any given moment, every terminal is in one of the two binary conditions low (0)
or high (1), represented by different voltage levels.
NAND and NOR are called universal gates because all the other gates like and, or, not, xor and
xnor can be derived from it. ... Similarly, NOR means NOT of OR, so it is a combination of OR and
a NOT gate. A NOR gate is also implemented using inverted AND inputs and so also called as
bubbled AND gate.
3. Write the truth table for Ex-or gate and AND gate
Combinational circuit does not use memory and thus here output depends only on current input.
Also, there is no need of clock here.
Examples of combinational circuits are full adder, multiplexer, decoder, encoder etc.
Now sequential circuits use memory and thus their output depends on current input plus previous
output. They employ a feedback loop to give output back to input.
Half-Adder: A combinational logic circuit that performs the addition of two data bits, A and B, is
called a half-adder. Addition will result in two output bits; one of which is the sum bit, S, and the
other is the carry bit, C.
Full-Adder: The half-adder does not take the carry bit from its previous stage into account. This carry
bit from its previous stage is called carry-in bit. A combinational logic circuit that adds two data bits,
A and B, and a carry-in bit, Cin, is called a full-adder
8. Define multiplexer
A multiplexer (or mux) is a device that selects one of several analog or digital input signals and
forwards the selected input into a single line. A multiplexer of 2n inputs has n select lines, which are
used to select which input line to send to the output. Multiplexers are mainly used to increase the
amount of data that can be sent over the network within a certain amount of time and bandwidth.
A multiplexer is also called a data selector. Multiplexers can also be used to implement boolean
functions of multiple variables.
9. Define de-multiplexer
A demultiplexer (or demux) is a device taking a single input signal and selecting one of many data-
output-lines, which is connected to the single input.
Applications of Multiplexer
Communication System: By using a multiplexer, the efficiency of the communication system can be
increased by allowing the transmission of data, such as audio, video data from different channels
through single line.
Computer Memory: Multiplexers are used in computer memory to maintain a huge amount of
memory in the computers, and also to reduce the number of copper lines required to connect the
memory to other parts.
Telephone network: multiple audio signals are integrated on a single line of transmission with
the help of a multiplexer.
Transmission from computer system of a satellite: multiplexer is used to transmit the data signals
from compute system of a space craft or a satellite to the ground system by using a GSM.
Applications of De-Multiplexer
Mux and De-Mux are both used in communication system to carry out the process of data
transmission. A De-multiplexer receives the output signals from the multiplexer and at the receiver
end it converts them back to the original form.
Arithmetic Logic Unit: The output of the ALU is fed as an input to the de-multiplexer and the
output of the de-multiplexer is connected to a multiple register. The output of the ALU can be stored
in multiple registers.
Encoders are digital ICs used for encoding. By encoding, we mean generating a digital binary code
for every input. An Encoder IC generally consists of an Enable pin which is usually set high to
indicate the working. It consists of 2^n input lines and n output lines with each input line being
represented by a code of zeros and ones which is reflected at the output lines
Decoders are digital ICs which are used for decoding. In other words, the decoders decrypt or obtain
the actual data from the received code, i.e., convert the binary input at its input to a form, which is
reflected at its output. It consists of n input lines and 2^n output lines. A decoder can be used to
obtain the required data from the code or can also be used for obtaining the parallel data from the
serial data received.
13. Write the characteristic equation of a SR, JK, D and T flip flop