Ddco Cse Manual
Ddco Cse Manual
LABORATORY MANUAL
SEMESTER : III
NAME: ____________________________________________________________
USN: _____________________________________________________________
SECTION: __________________________________________________________
BATCH: ___________________________________________________________
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
PROGRAM OUTCOMES
Engineering Graduates will able to:
Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems.
Problem analysis: Identify, formulate, review research literature, and analyse complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations.
Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering
and IT tools including prediction and modelling to complex engineering activities with an understanding
of the limitations.
The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
Project management and finance: Demonstrate knowledge and understanding of the Engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
Life -long learning: Recognize the need for and have the preparation and ability to engage in independent
and life -long learning in the broadest context of technological change.
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
The East Point College of Engineering and Technology aspires to be a globally acclaimed
institution, recognized for excellence in engineering education, applied research and nurturing
students for holistic development.
MISSION
M1: To create engineering graduates through quality education and to nurture innovation,
creativity and excellence in teaching, learning and research
M2: To serve the technical, scientific, economic and societal developmental needs of our
communities
M3: To induce integrity, teamwork, critical thinking, personality development and ethics in
students and to lay the foundation for lifelong learning
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
MISSION
M1: To create successful Computer Science Engineering graduates through effective
pedagogies, the latest tools and technologies, and excellence in teaching and learning.
M2: To augment experiential learning skills to serve technical, scientific, economic, and social
developmental needs.
M3: To instill integrity, critical thinking, personality development, and ethics in students for a
successful career in Industries, Research, and Entrepreneurship.
PEO 1: To produce graduates who can perform technical roles to contribute effectively in
software industries and R&D Centre
PEO 2: To produce graduates having the ability to adapt and contribute in key domains of
computer science and engineering to develop competent solutions.
PEO 3: To produce graduates who can provide socially and ethically responsible solutions
while adapting to new trends in the domain to carve a successful career in the industry
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
COURSE OUTCOMES
Sl. Experiments
NO Simulation packages preferred: Multisim, Modelsim, PSpice or any other relevant
1 Given a 4-variable logic expression, simplify it using appropriate technique and simulate the same
using basic gates.
2 Design a 4 bit full adder and subtractor and simulate the same using basic gates.
3 Design Verilog HDL to implement simple circuits using structural, Data flow and Behavioural model.
4 Design Verilog HDL to implement Binary Adder-Subtractor – Half and Full Adder, Half and Full
Subtractor.
6 Design Verilog program to implement Different types of multiplexer like 2:1, 4:1 and 8:1.
8 Design Verilog program for implementing various types of Flip-Flops such as SR, JK and D.
CIE for the theory component of the IPCC (maximum marks 50)
● IPCC means practical portion integrated with the theory of the course.
● CIE marks for the theory component are 25 marks and that for the practical component is 25
marks.
25 marks for the theory component are split into 15 marks for two Internal Assessment Tests (Two Tests,
each of 15 Marks with 01-hour duration, are to be conducted) and 10 marks for other assessment
methods mentioned in 22OB4.2. The first test at the end of 40-50% coverage of the syllabus and the
second test after covering 85-90% of the syllabus.
● Scaled-down marks of the sum of two tests and other assessment methods will be CIE marks for the theory
component of IPCC (that is for 25 marks).
● The student has to secure 40% of 25 marks to qualify in the CIE of the theory component of IPCC.
● 15 marks for the conduction of the experiment and preparation of laboratory record, and 10 marks
for the test to be conducted after the completion of all the laboratory sessions.
● On completion of every experiment/program in the laboratory, the students shall be evaluated including viva-
voce and marks shall be awarded on the same day.
● The CIE marks awarded in the case of the Practical component shall be based on the continuous evaluation
of the laboratory report. Each experiment report can be evaluated for 10 marks. Marks of all experiments’
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Index
Sl Page
Program List CO PO RB T
No No
I VERILOG INTRODUCTION 9
I VERILOG INTRODUCTION
Verilog is a hardware description language (HDL) that describes the functionality of hardware
design and the synthesis tool converts hardware descriptions into an actual design that has combinational and
sequential elements. Verilog language is simpler than VHDL Verilog is based on C language, whereas VHDL is
based on Ada and Pascal languages. Latest Verilog standard: IEEE Standard 1364-2005
Verilog is basically a structural and behavior language and defines four abstraction levels to
implement modules. With respect to the external environment, the module is viewed as identical irrespective of
abstraction levels. But internal module implementation differs based on abstraction as described below.
1. Gate level – The module implementation is similar to the gate-level design description in terms of logic
gates and interconnections between them.
2. Dataflow level – The module implementation depends on data flow specification i.e. how data flows
and processes in the design circuit.
3. Switch level – The module implementation requires switch level knowledge to implement a design in
terms of storage nodes, switches. This is the lowest level of abstraction.
4. Behavior level – The module implementation is similar to C language programming that includes
algorithmic level implementation without worrying about hardware implementation details.Above abstraction
levels are also commonly mentioned with modeling terminology. The design can be implemented with a
combination of gate-level, data flow, and behavioral modeling. The commonly heard term RTL (Register
Transfer Level) in digital design is used for a combination of data flow and behavior modeling.
II HOW TO USE A ISE DESIGN SUITE 14.7
Running Verilog code in Xilinx ISE Design Suite 14.7 involves several steps from creating your
project to simulating your design.
9
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
10
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Experiment-1
1. Given a 4-variable logic expression, F(A,B,C,D)= ∑ m (0,1,2,4,5,6,8,9,10,12,13)
simplify it using appropriate technique and simulate the same using basic gates.
AIM: To simplify given four variable logical expression using K-map and simulate using basic gates.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
To minimize a Boolean expression we can employ any one of the
followingtechniques:
(i) Boolean Algebra
(ii) Karnaugh maps.
Before we proceed to simplification techniques, two forms of the Boolean expression must be noted.
1. Sum of product (SOP): Ex: ABC+AB+AC
2. Product of Sum (POS): Ex: (A+B+C) (A+B) +(A+C)
11
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Truth Table
Decimal
a b c d Output e
Number
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 1
5 0 1 0 1 1
6 0 1 1 0 1
7 0 1 1 1 0
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 1
13 1 1 0 1 1
14 1 1 1 0 0
15 1 1 1 1 0
PROCEDURE:
1. Simplify the given expression using techniques like Boolean algebra and Karnaugh-map to minimize
number of gates required.
2. Create Verilog code for implementation and view the logic gates and their interconnections in your
design using RTL Schematic .
Fig 1.2
RTL Schematic For e = c’ +a’ d’+b’d’
13
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
This Verilog code models the logic expression using basic gates and assigns the result to output signal ‘e’.
3. Create a test bench code to verify the functionality of Verilog design and obtain the corresponding
simulation waveform. The test bench code includes input and monitors the output to compare it with
expected results.
Test Bench Code:
module b4v_tb;
// Inputs
reg a;
reg b;
reg c;
reg d;
// Outputs
wire e;
// Instantiate the Unit Under Test (UUT)
b4v uut (
.a(a),
.b(b),
.c(c),
.d(d),
.e(e)
);
initial begin
$monitor("a=%bb=%bc=%bd=%be=%b",a,b,c,d,e);
#10 a=0;b=0;c=0;d=0;
#10 a=0;b=0;c=0;d=1;
#10 a=0;b=0;c=1;d=0;
#10 a=0;b=0;c=1;d=1;
#10 a=0;b=1;c=0;d=0;
#10 a=0;b=1;c=0;d=1;
#10 a=0;b=1;c=1;d=0;
#10 a=0;b=1;c=1;d=1;
#10 a=1;b=0;c=0;d=0;
#10 a=1;b=0;c=0;d=1;
#10 a=1;b=0;c=1;d=0;
#10 a=1;b=0;c=1;d=1;
#10 a=1;b=1;c=0;d=0;
#10 a=1;b=1;c=0;d=1;
#10 a=1;b=1;c=1;d=0;
#10 a=1;b=1;c=1;d=1;
end
endmodule
14
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation Output
(iii) Get the output from the console output window at the time of simulation
15
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
16
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
EXPERIMENT-2
Design Verilog HDL to implement Binary Adder– Half , Full , and 4-bit Full adder.
AIM: To design i) Half adder
ii) Full adder
iii) 4-bit full adder using basic logic gates and simulate their operations.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
i) Half Adder: Half adder is a basic combinational design that can add two single bits and results to a
sum and carry bit as an output.
Fig 2.2 K-MAP for SUM Fig 2.3 K-MAP for CARRY
17
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
The half adder circuit is suitable for the addition of two bits at the LSB (Least Significant Bit)
position. Because during the addition of two bits at the LSB position, there is no incoming carry. But
whenever there is an incoming carry (Cin) along with the two bits, then a full adder circuit can be used.
Procedure
1. Write a Verilog Code using appropriate modelling style (Structural , data flow, or behavioral) to describe
the desired logic. Ensure Your Verilog code includes input and output ports, logical operations and any
necessary components. Obtain RTL Schematic for Half adder.
18
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
// Outputs
wire S;
wire C;
#10 A=0;B=1;
#10 A=1;B=0;
#10 A=1;B=1;
end
endmodule
19
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation Output
20
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
21
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
The full adder is the combinational circuit that adds the two bits along with the incoming carry (Cin)
and generates the sum bit (S) and an outgoing carry bit (Cout) as an output. The truth table of the full adder is
shown below.
22
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Fig 2.10 logic circuit for the sum (S) and the carry (Cout) output
Procedure
1. Write a Verilog Code using appropriate modelling style (Structural , data flow, or behavioral) to describe
the desired logic. Ensure Your Verilog code includes input and output ports, logical operations and any
necessary components. Obtain RTL Schematic for Full adder.
Verilog Code For Full Adder
module fa(A,B,Cin, S,CO);
input A,B,Cin;
output reg S,CO;
always @ (*)
begin
S=A^B^Cin;
CO= (A&B)|(A&Cin)|(Cin&A);
end
endmodule
Fig 2.11 Simple Circuit
23
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
2. Create a testbench module that instantiates your Verilog module, defines test inputs and applies stimulus
and generate the simulation waveform.
Testbench code for Full Adder
module fa_tb_v;
// Inputs
reg A;
reg B;
reg Cin;
// Outputs
wire S;
wire CO;
// Instantiate the Unit Under Test (UUT)
fa uut (
.A(A),
.B(B),
.Cin(Cin),
.S(S),
.CO(CO)
24
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
);
initial begin
// Initialize Inputs
$monitor("A=%bB=%bCin=%bS=%bCO=%b",A,B,Cin,S,CO);
#10 A=0;B=0;Cin=0;
#10 A=0;B=0;Cin=1;
#10 A=0;B=1;Cin=0;
#10 A=0;B=1;Cin=1;
#10 A=1;B=0;Cin=0;
#10 A=1;B=0;Cin=1;
#10 A=1;B=1;Cin=0;
#10 A=1;B=1;Cin=1;
end
endmodule
Simulation Output
25
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
26
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Binary adders are implemented to add two binary numbers. So in order to add two 4 bit binary numbers, we
will need to use 4 full-adders.
Procedure
1. Write a Verilog Code using appropriate modelling style (Structural , data flow, or behavioral) to describe
the desired logic. Ensure Your Verilog code includes input and output ports, logical operations and any
necessary components. Obtain RTL Schematic for 4-bit Full adder.
module fa_behav(s,co,a,b,c);
input a,b,c;
output reg s,co;
always @ (*)
begin
s=a^b^c;
co= (a&b)|(b&c)|(c&a)
end
endmodule
Fig 2.15 Simple Circuit
2. Create a testbench module that instantiates your Verilog module, defines test inputs and applies stimulus
and generate the simulation waveform.
Testbench code for 4-Bit Full Adder
module fa4bit_tb;
// Inputs
reg [3:0] a;
reg [3:0] b;
reg cin;
// Outputs
wire [3:0] s;
wire co;
integer i;
// Instantiate the Unit Under Test (UUT)
fa4bit uut (
.s(s),
.co(co),
.a(a),
.b(b),
.cin(cin)
);
initial begin
// Initialize Inputs
//$monitor("a=0x%0h b=0x%0h c=%b s=0x%0h co=ox%0h",a,b,c,s,co);
#10 a =4'b0000; b=4'b0000;cin = 0;
#10 a =4'b0001; b=4'b0001;
#10 a =4'b0010; b=4'b0010;
#10 a =4'b0011; b=4'b0011;
#10 a =4'b0100; b=4'b0100;
#10 a =4'b0101; b=4'b0101;
#10 a =4'b0110; b=4'b0110;
#10 a =4'b0111; b=4'b0111;
#10 a =4'b1000; b=4'b1000;
#10 a =4'b1001; b=4'b1001;
#10 a =4'b1010; b=4'b1010;
#10 a =4'b1011; b=4'b1011;
#10 a =4'b1100; b=4'b1100;
#10 a =4'b1101; b=4'b1101;
#10 a =4'b1110; b=4'b1110;
#10 a =4'b1111; b=4'b1111;
// Wait 100 ns for global reset to finish
#100;
// using for loop to random the values to the input
//for(i=0 ; i<5 ; i=i+1) begin
// #10 a <= $random;
//b <= $random;
//end
end
endmodule
29
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation Output
30
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
31
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
EXPERIMENT-3
Design Verilog HDL to implement Binary Substractor– Half , Full , and 4-bit Full
Subtractor.
AIM: To design i) Half Subtractor ii) Full Subtractoriii) 4-bit full Subtractor using basic logic gates
and simulate their operations.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
i) Half Subtractor
A half-subtractor is a combinational logic circuit that have two inputs and two outputs (i.e. difference
and borrow). The half subtractor produces the difference between the two binary bits at the input and also
produces a borrow output (if any). In the subtraction (A-B), A is called as Minuend bit and B is called
as Subtrahend bit.
Diff=A'B+AB'
Borrow = A'B
33
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation Output
a=0b=0d=0bo=0
a=0b=1d=1bo=1
a=1b=0d=1bo=0
a=1b=1d=0bo=0
35
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
36
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
The Half Subtractor is used to subtract only two numbers. To overcome this problem, a full subtractor
was designed. The full subtractor is used to subtract three 1-bit numbers A, B, and C, which are minuend,
subtrahend, and borrow, respectively. The full subtractor has three input states and two output states i.e., diff
and borrow.
37
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Procedure
1. Write a Verilog code for Full Subtractor and obtain the RTL Schematic
38
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
39
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
2. Write a test bench code for Full Subtractor and obtain the RTL Simulation Waveform.
Test Bench Code For Full Subtractor
module fsub_tb;
// Inputs
reg a;
reg b;
reg bin;
// Outputs
wire d;
wire bout;
// Instantiate the Unit Under Test (UUT)
fsub uut (
.a(a),
.b(b),
.bin(bin),
.d(d),
.bout(bout)
);
initial begin
$monitor("a=%b b=%b bin=%b d=%b bout=%b",a,b,bin,d,bout);
#10 a=0;b=0;bin=0;
#10 a=0;b=0;bin=1;
#10 a=0;b=1;bin=0;
#10 a=0;b=1;bin=1;
#10 a=1;b=0;bin=0;
#10 a=1;b=0;bin=1;
#10 a=1;b=1;bin=0;
#10 a=1;b=1;bin=1;
end
endmodule
40
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation Output
41
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
42
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Procedure
1. Write a Verilog Code using appropriate modelling style (Structural , data flow, or behavioral) to
describe the desired logic. Ensure Your Verilog code includes input and output ports, logical operations and
any necessary components.
43
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
2. Create a testbench module that instantiates your Verilog module, defines test inputs and applies stimulus
and generate the simulation waveform.
Testbench code for 4-Bit Full Subtractor
module sub4b_tb;
// Inputs
reg [3:0] a;
reg [3:0] b;
reg bin;
// Outputs
wire [3:0] d;
wire bout;
//integer i;
// Instantiate the Unit Under Test (UUT)
sub4b uut (
.a(a),
.b(b),
.bin(bin),
44
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
.d(d),
.bout(bout)
);
initial begin
// Initialize Inputs
//$monitor("a=0x%0h b=0x%0h c=%b s=0x%0h co=ox%0h",a,b,c,s,co);
#10 a =4'b0000; b=4'b1111;bin =1;
#10 a =4'b0001; b=4'b1110;
#10 a =4'b0010; b=4'b1101;
#10 a =4'b0011; b=4'b1100;
#10 a =4'b0100; b=4'b1011;
#10 a =4'b0101; b=4'b1010;
#10 a =4'b0110; b=4'b1001;
#10 a =4'b0111; b=4'b1000;
#10 a =4'b1000; b=4'b0111;
#10 a =4'b1001; b=4'b0110;
#10 a =4'b1010; b=4'b0101;
#10 a =4'b1011; b=4'b0100;
#10 a =4'b1100; b=4'b0011;
#10 a =4'b1101; b=4'b0010;
#10 a =4'b1110; b=4'b0001;
#10 a =4'b1111; b=4'b0000;
45
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation Output
46
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
47
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
EXPERIMENT-4
Design Verilog HDL to implement Simple circuits using structural, Data flow and
Behavioural model
AIM: To design a simple circuit using structural, Data flow and Behavioural model .
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
i) Structural Modeling
Description : Structural modeling describes a design in terms of interconnected hardware components or
modules.It explicitly defines the components and their interconnections.
Use Cases: This modeling style is suitable for designing and connecting pre-defined components or IP blocks,
such as multiplexers, adders, and flip-flops.
Implementation : On structural modeling you instantiate predefined components and connect them to create
the desired circuit.
Example Verilog code for a 2 to 1 multiplexer using structural modeling:
module mux2x1(
input I0,I1,S,
output Y );
wire w1,w2,w3;
not(w1,S);
and(w2,I0,w1);
and(w3,I1,S);
or(Y,w2,w3);
endmodule
ii) Data Flow Modeling
Description : Data flow modeling specifies how data flows through the circuit. It defines operations on data
as function of inputs, similar to equations in mathematics.
Use Cases: Data flow modeling is suitable for designing the desired functionality of circuit without
specifying its structure explicitly.
Implementation : You describe the behaviour of the circuit using assignments and combinational logic
48
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
equations.
Example Verilog code for and gate using Data flow modeling:
module and_gate(a,b,out);
input a,b;
output out;
assign out = a&b;
endmodule
iii) Behavioural Modeling
Description : iii) Behavioural modeling focuses on high-level functionality,describing how a module
behaves without specifying the underlying hardware details.It’s often used for algorithimicdescriptions.
Use Cases: Behavioural modeling is useful for designing modules where the internal hardware is not critical
or when you want to abstract away hardware details.
Implementation : You use procedural constructs like always blocks and if-else statements to specify how
the modules behaves based on inputs.
Example Verilog code for and full adder using Behavioural modeling:
module full_adder(
input a,
input b,
input cin,
output sum,
output cout
);
always @(*) begin
// Calculate the sum
sum = a ^ b ^ cin;
// Calculate the carry-out
cout = (a & b) | (a & cin) | (b & cin);
end
endmodule
Procedure
1. Minimize the following Boolean expression f(A,B,C) = Σm(1,3,6,7)
49
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
50
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Behavioural Modeling
Verilog Code :
module designall_3(a,b,c,e);
input a,b,c;
output reg e;
always @ (*)
begin
e = (a&b)|(~a&c);
end
endmodule
2. Write a testbench code for the give expression using any model and obtain the simulation waveform
51
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
initial begin
$monitor("a=%bb=%bc=%be=%b",a,b,c,e);
#10 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;
end
endmodule
Simulation Output
53
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
EXPERIMENT-5
Design Verilog HDL to implement Decimal adder or BCD Adder
AIM: To design a decimal or BCD adder using Verilog HDL.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY: The digital systems handles the decimal number in the form of binary coded decimal numbers
(BCD). A BCD Adder Circuit that adds two BCD digits and produces a sum digit also in BCD. BCD numbers use
10 digits, 0 to 9 which are represented in the binary form 0 0 0 0 to 1 0 0 1, i.e. each BCD digit is represented as a
4-bit binary number. When we write BCD number say 526, it can be represented as
The addition is carried out as in normal binary addition and the sum is 1 0 0 1, which is BCD code for 9.
Sum greater than 9 with carry 0
Let us consider addition of 6 and 8 in BCD
The sum 1 1 1 0 is an invalid BCD number. This has occurred because the sum of the two digits exceeds 9.
Whenever this occurs the sum has to be corrected by the addition of six (0110) in the invalid BCD number, as
shown below
54
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
In this, case, result (0001 0001) is valid BCD number, but it is incorrect. To get the correct BCD result
correction factor of 6 has to be added to the least significant digit sum, as shown below
Going through these three cases of BCD addition we can summarise the BCD addition procedure as follows :
Add two BCD numbers using ordinay binary addition.
If four-bit sum is equal to or less than 9, no correction is needed. The sum is in proper BCD form.
If the four-bit sum is greater than 9 or if a carry is generated from the four-bit sum, the sum is invalid.
To correct the invalid sum, add 01102 to the four-bit sum. If a carry results from this addition, add it to the next
higher-order BCD digit.
Thus to implement BCD Adder Circuit we require :
• 4-bit binary adder for initial addition
55
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
The two BCD numbers, are first added in the top 4-bit binary adder to produce a binary sum. When the
output carry is equal to zero (i.e. when sum ≤ 9 and Cout = 0) nothing (zero) is added to the binary sum. When
it is equal to one (i.e. when sum > 9 or Cout = 1), binary 0110 is added to the binary sum through the bottom 4-
bit binary adder. The output carry generated from the bottom binary adder can be ignored, since it supplies
information already available at the output-carry terminal.
Procedure
1.Write the Verilog code for BCD adder .
Verilog Code For BCD adder
module bcd(a,b,sum,carry);
//declare the inputs and outputs of the module with their sizes.
input [3:0] a,b;
57
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation OutPut
58
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
59
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
EXPERIMENT-6
Design Verilog Program to implement Different types of Multiplexer like 2:1,4:1,8:1
AIM: To design and implement Different types of Multiplexer like 2:1,4:1,8:1 using Verilog HDL.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
Multiplexer:
A multiplexer is a combinational circuit that has 2n input lines and a single output line. Simply, the
multiplexer is a multi-input and single-output combinational circuit. The binary information is received from the
input lines and directed to the output line. On the basis of the values of the selection lines, one of these data
inputs will be connected to the output.
Unlike encoder and decoder, there are n selection lines and 2n input lines. So, there is a total of 2N possible
combinations of inputs. A multiplexer is also treated as Mux.
i) 2:1 Multiplexer:
In 2×1 multiplexer, there are only two inputs, i.e., a and b, 1 selection line, i.e., S and single outputs, i.e., Y. On
the basis of the combination of inputs which are present at the selection line S, one of these 2 inputs will be
connected to the output. The block diagram and the truth table of the 2×1 multiplexer are given below.
60
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Procedure
1. Write a Verilog Code for 2:1 MUX
2. Write a Test Bench code for 2:1 MUX and obtain Simulation Waveform
// Outputs
wire y;
endmodule
61
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation Output
Inputs Output
s1 s0 y
0 0 I0
0 1 I1
1 0 I2
1 1 I3
62
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Procedure
1. Write a Verilog Code for 4:1 MUX
endmodule
2. Write a Test Bench code for 4:1 MUX and obtain Simulation Waveform
// Outputs
wire y;
endmodule
63
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Simulation Output
64
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Inputs Output
s2 s1 s0 y
0 0 0 I0
0 0 1 I1
0 1 0 I2
0 1 1 I3
1 0 0 I4
1 0 1 I5
1 1 0 I6
1 1 1 I7
Procedure
1. Write a Verilog Code for 8:1 MUX
endmodule
2. Write a Test Bench code for 8:1 MUX and obtain Simulation Waveform
.s(s),
.y(y)
);
initial begin
I = 8'b 10101100;
s = 3'b 000;
#100 s=3'b 001;
#100 s=3'b 010;
#100 s=3'b 011;
#100 s=3'b 100;
#100 s=3'b 101;
#100 s=3'b 110;
#100 s=3'b 111;
end
endmodule
Simulation Output
66
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
67
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
EXPERIMENT-7
Design Verilog Program to implement Different types of De-Multiplexer like 1:2,1:4,1:8
AIM: To design and implement Different types of De-Multiplexer like 1:2,1:4,1:8 using Verilog HDL.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
De-Multiplexer:
The demultiplexer is a combinational logic circuit designed to switch one common input line to one of
several seperate output line. The data distributor, known more commonly as the demultiplexer or “Demux” for
short. The demultiplexer takes one single input data line and then switches it to any one of a number of
individual output lines one at a time.
i) 1:2 De-Multiplexer:
A 1-to-2 demultiplexer consists of one input line, two output lines and one select line. The signal on the select
line helps to switch the input to one of the two outputs. The figure below shows the block diagram of a 1-to-2
demultiplexer with additional enable input.
Y0=S'.I
Y1=S.I
68
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Procedure
1. Write a Verilog Code for 1:2 DMUX
Verilog Code for 1:2 DMUX
module dmt(s,I, y0,y1);
input s,I;
output y0,y1;
wire w1;
not n1(w1,s);
and a1(y0,w1,I);
and a2(y1,s,I);
endmodule
2. Write a Test Bench code for 1:2 DMUX and obtain Simulation Waveform
Simulation Output
70
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Y0=S1' S0' I
Y1=S0' S1 I
Y2=S0 S1' I
Y3=S0 S1 I
Procedure
1. Write a Verilog Code for 1:4 DMUX
2. Write a Test Bench code for 1:4 DMUX and obtain Simulation Waveform
// Inputs
reg s0;
reg s1;
reg I;
// Outputs
71
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
wire y0;
wire y1;
wire y2;
wire y3;
// Instantiate the Unit Under Test (UUT)
dmf uut (
.s0(s0),
.s1(s1),
.I(I),
.y0(y0),
.y1(y1),
.y2(y2),
.y3(y3)
);
initial begin
I = 1;
#10 s0=0;s1=0;
#10 s0=0;s1=1;
#10 s0=1;s1=0;
#10 s0=1;s1=1;
end
endmodule
Simulation Output
72
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Input S0 S1 S2 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
line
I 0 0 0 0 0 0 0 0 0 0 1
I 0 0 1 0 0 0 0 0 0 1 0
I 0 1 0 0 0 0 0 0 1 0 0
I 0 1 1 0 0 0 0 1 0 0 0
I 1 0 0 0 0 0 1 0 0 0 0
I 1 0 1 0 0 1 0 0 0 0 0
I 1 1 0 0 1 0 0 0 0 0 0
I 1 1 1 1 0 0 0 0 0 0 0
Procedure
1. Write a Verilog Code for 1:8 DMUX
and a1(y1,w0,w1,s2);
and a2(y2,w0,s1,w2);
and a3(y3,w0,s1,s2);
and a4(y4,s0,w1,w2);
and a5(y5,s0,w1,s2);
and a6(y6,s0,s1,w2);
and a7(y7,s0,s1,s2);
endmodule
2. Write a Test Bench code for 1:8 DMUX and obtain Simulation Waveform
Y0=S0’.S1’.S2’.I
Y1=S0’.S1’.S2.I
Y2=S0’.S1.S2’.I
Y3=S0’.S1.S2.I
Y4=S0.S1’.S2’.I
Y5=S0.S1’.S2.I
Y6=S0.S1.S2’.I
Y7=S0.S1.S2.I
wire y4;
wire y5;
wire y6;
wire y7;
// Instantiate the Unit Under Test (UUT)
dme uut (
.s0(s0),
.s1(s1),
.s2(s2),
.I(I),
.y0(y0),
.y1(y1),
.y2(y2),
.y3(y3),
.y4(y4),
.y5(y5),
.y6(y6),
.y7(y7)
);
initial begin
I = 1;
#10 s0 = 0;s1 = 0;s2 = 0;
#10 s0 = 0;s1 = 0;s2 = 1;
#10 s0 = 0;s1 = 1;s2 = 0;
#10 s0 = 0;s1 = 1;s2 = 1;
#10 s0 = 1;s1 = 0;s2 = 0;
#10 s0 = 1;s1 = 0;s2 = 1;
#10 s0 = 1;s1 = 1;s2 = 0;
#10 s0 = 1;s1 = 1;s2 = 1;
end
endmodule
Simulation Output
76
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
EXPERIMENT-8
Design Verilog Program for implementing various types of Flip-flops like SR,JK & D
AIM: To design and implement various types of Flip-flop like SR,JK & D using Verilog HDL.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
A flip-flop is a fundamental building block in digital electronics and is a type of bistable multivibrator. It
is a circuit that has two distinct output states and is capable of storing one bit of information. Flip-flops are widely
used in sequential circuits, memory devices, and digital systems. There are several types of flip-flops, each with its
own characteristics. Here are some common types:
i) S-R Flip Flop
This is the most common flip-flop among all. This simple flip-flop circuit has a set input (S) and a reset
input (R). In this system, when you Set “S” as active, the output “Q” would be high, and “Q‘” would be low.
Once the outputs are established, the wiring of the circuit is maintained until “S” or “R” go high, or power is
turned off.
Clock S R q qb Action
+ve No
0 0 q qb
edge change
+ve
0 1 0 1 Reset
edge
+ve
1 0 1 0 Set
edge
+ve Not
1 1 X X
edge Defined
77
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Fig 8.2 Logic circuit of S-R Flip Flop Using NAND Gates
Procedure
1. Write a Verilog code for S-R Flip flip.
endmodule
2. Write the Test Bench code for SR Flip flop and obtain simulation waveform.
.r(r),
.c(c),
.q(q),
.qb(qb)
);
initial begin
s = 0;r = 0;c = 0;
#100;s = 0;r = 1;
#100;s = 1;r = 0;
#100;s = 1;r = 1;
end
always #10 c=~c;
endmodule
Simulation Output
79
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Clock J K q qb Action
+ve No
0 0 q qb
edge change
+ve
0 1 0 1 Reset
edge
+ve
1 0 1 0 Set
edge
+ve
1 1 qb q Toggle
edge
Fig 8.5 Logic circuit of J-K Flip Flop Using NAND Gates
80
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Procedure
1. Write a Verilog code for J-K Flip flip.
endmodule
2. Write the Test Bench code for JK Flip flop and obtain simulation waveform.
Simulation Output
Clock D q qb Action
+ve
0 0 1 Reset
edge
+ve
1 1 0 Set
edge
82
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Procedure
1. Write a Verilog code for D Flip flip.
endmodule
2. Write the Test Bench code for JK Flip flop and obtain simulation waveform.
83
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
#100;d=1;
end
always #10 c=~c;
endmodule
Simulation Output
84
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
85
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
ADDITIONAL EXPERIMENTS
EXPERIMENT-10
Design Verilog Program for implementing T-Flip-flop
AIM: To design and implement T-Flip Flop using Verilog HDL.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
TRUTH TABLE &SYMBOLS:
86
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
TRUTH TABLE:
0 0 0 0 1 1 1 0 1
0 1 0 1 1 1 0 1 0
1 0 0 1 0 1 0 1 0
1 1 1 1 0 0 0 0 1
PROGRAM:
module gates ( a, b,and_out, or_out, not_out, nand_out, nor_out, xor_out, xnor_out );
input a,b;
outputand_out, or_out, not_out, nand_out, nor_out, xor_out, xnor_out;
assign and_out = a & b;
assign or_out= a | b,
assign not_out=~a ,
assign nand_out= ~(a & b),
assign nor_out= ~(a | b),
assign xor_out= a ^ b;
assign xnor_out = ~(a ^ b);
endmodule
PROCEDURE:
1. Write a Verilog code for all logic gates.
2. Write a Test Bench Code for all Logic Gates.
RESULT:
The functions of all the logic gates have been realized using Verilog HDL code.
87
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
88
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
EXPERIMENT-10
Design Verilog Program for implementing T-Flip-flop
AIM: To design and implement T-Flip Flop using Verilog HDL.
SIMULATOR USED: ISE DESIGN SUIT 14.7
THEORY:
i) T Flip Flop
A T flip-flop is like a JK flip-flop. These are basically single-input versions of JK flip-flops. This
modified form of the JK is obtained by connecting inputs J and K together. It has only one input along with the
clock input. The T flip-flop has a single input, T (toggle), and a clock input.
When the clock input transitions, the output toggles (flips) if the T input is 1; otherwise, it maintains its state.
Clock T q qb Action
+ve No
0 0 1
edge Change
+ve
1 1 0 Toggle
edge
Procedure
1. Write a Verilog code for T Flip flip.
endmodule
2. Write the Test Bench code for T Flip flop and obtain simulation waveform.
// Outputs
wire q;
endmodule
Simulation Output
91
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
92
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
1. What is HDL?
Hardware description language is a computer aided design (CAD). Tool to design and synthesis of
digital system. HDL language is similar to language.
2. HDL language is similar to which language?
It is similar to C Language.
3. Justify the statement "Debugging the design is easy " in HDL.
Yes, because HDL packages implementation simulator & test benches
4. List the Hardware Description Language?
VHDL & Verilog
5. What is the abbreviation of VHDL?
VHDL means Very High Speed Integrated Circuit(VHSIC) hardware description language.
6. What is the VHDL standard ?
The updated standard in 1993 is IEEE standard 1076-1993.
7. Write the general structure of VHDL model?
Entityentity_name is
port(define input and output port); endentity_name;
architecturearchitecture_name of entity_name is begin
statements; endarchitecture_name;
8. Write the general structure for verilog?
Module modulename(input and output variable); input ;
output;
statement;
endmodule;
9. Which package is attached with VHDL program?
std_logic_1164 package is attached with VHDL program.
10. What is the Verilog HDL standard and who is maintaining it?
IEEE standard 1364-1995 is the verilog HDL standard and it is maintain by Verilog international
organization.
11. In VHDL, what are the modes that the ports can take?
in, out, inout, buffer, linkage.
12. Explain the function of the modes of the port.
in-The port is only an i/p and appears only on the right hand side of the statement. out-The port is
only an o/p and appears only on the left and right hand side of the statement.
inout-The port can be used as both an i/p & o/p.
buffer-The port can be used as both i/p & o/p but should have only one source.
13. Explain the structure of the verilog module.
The verilog module has two parts, Declaration & Body. Declaration- name, inputs and outputs of the
module are listed. Body-shows the relationship between the inputs & outputs.
14. Which of two Hardware Description Language is case Sensitive?
Verilog is case Sensitive.
15. How should the module be terminated in verilog?
The module is terminated by the predefined word endmodule.
16. What are the modes that exists in verilog ports?
input : The port is only an i/p Port.
output : The port is only an o/p Port.
inout : The port can be used as both an i/p and o/p.
17. How are the operators broadly classified?
93
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Logical- AND,OR,XOR.
Relational =,=,<,<,>,> Arithmetic +,-,*,
Shift to move the bits of an objects in a certain direction right or left.
94
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
Absabsolute
{,} Concatenate &Concatenate
95
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
A constant is VHDL is declared by using the predefined word constant and in verilog it is declared
by its type like time or integer.
To assign a value to a constant assignment operator or initial value assignment operator
:=is used in VHDL & = in verilog.
37. Write a time delay signed assignment statement.
To assign a delay time to a signed - assigned statement the predefined word after is used in VHDL &
in Verilog it is # (Delay time).
Ex : S1 - sel and b after 10 nsec - VHDL. assign # 10 S1=sel& b// Verilog.
38. Define Vector data types.
A vector is a data type that declares an array of similar elements suchas to declare an object that has
a width of more than 1 bit.
39. What is the difference between syntax error and semantic error?
Syntax error is those that result from not following the rules of the language. it terminates
compilation of the program.
A semantic error is an error in the mechanics of the statement. it may not terminate the program, but
the outcome of the program may not be as expected.
40. What is the function of Behavioral Description?
The behavioral description describes the system by showing how the outputs behave according to
changes in its inputs. In behavioral description one need not know the logic diagram of the system
but one should know how the output behaves in response to change in the output.
41. What are the two phase of execution in HDL?
The two phases of execution in HDL are Calculation and Assignment.
42. What do you mean by Sequential Calculation?
Sequential calculation means the calculation of a statement will not wait until the proceeding
statement is assigned only until the calculation is done.
43. Which are the Sequential statements that are assigned with behavioral description?
If statement, else-if, loop statements, for loop, forever, report, repeat, next-exit.
44. State the difference between signal and variable assignment.
A process is written based on signal assignment statements and then another process is written based
on variable assignment statements. The difference can be observed by the simulation wave forms.
45. When do use loop statements and what is its advantage?
Loops is used to repeat the execution of statements written inside the body. The number of
repetitions is controlled by the range of an index parameter. The loop allows the code to be
shortened.
46. When is Structural Description best suited?
It is best suited when the digital logic of the system hardware components is known.
47. What type of components are used in structural description?
Components can be gate level: AND, OR, NOT, XOR, XNOR gates. Components can be of higher
logic level such as Register Transfer Level (RTL) or processor level.
48. What type of statements are written in Structural Description and why?
Statements are “Concurrent “ in nature. At any simulation time, all statements that have an event are
executed concurrently.
49. Difference between VHDL & Verilog structural description.
Verilog recognizes all the primitive gates such as AND, OR, NOT, XOR, XNOR. Basic VHDL
packages do not recognize any gates unless the package is limited to one more libraries, packages
that have gate description
96
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
97
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
98
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
99
DIGITAL DESIGN AND COMPUTER ORGANIZTION (BCS302) 2023-2024
100