International Islamic University Islamabad: Digital System Design Lab
International Islamic University Islamabad: Digital System Design Lab
Islamabad
Digital System Design Lab
Name of Student:
Roll No.:
Date of Experiment:
Marks obtained:
Remarks:
Instructor’s Signature:
2. Resources Required
• A Computer
• Xilinx ISE 10.1
• ModelSim 10.1
3. Introduction
HDL (Hardware Description Language) is any language from a class of computer languages,
specification languages, or modeling languages for formal description and design of
electronic circuits, and most-commonly, digital logic. It can describe the circuit's operation,
its design and organization, and tests to verify its operation by means of simulation. The two
most popular HDLs are Verilog and VHDL. Verilog due to its similarity to C language is
easier to understand so has become most widely used HDL in educational institutions.
Dataflow level
At this level, the module is designed by specifying the data flow. The designer is aware of
how data flows between hardware registers and how the data is processed in the design.
Gate level
The module is implemented in terms of logic gates and interconnections between these gates.
Design at this level is similar to describing a design in terms of a gate-level logic diagram.
a) Expressions
Expressions are constructs that combine operators and operands to produce a result.
// Examples of expressions. Combines operands and operators
a ^ b;
addr1[20:17] + addr2[20:17];
in1 | in2;
b) Operands
Operands can be constants, integers, real numbers, nets, registers, bit-select (one bit of vector
net or a vector register), part-select (selected bits of the vector net or register vector), and
memories or function calls (functions are discussed later).
real a, b, c;
c = a - b; //a and b are real operands
c) Operators
Operators act on the operands to produce desired results. Verilog provides various types of
operators.
d1 && d2 // && is an operator on operands d1 and d2
!a[0] // ! is an operator on operand a[0]
B >> 1 // >> is an operator on operands B and 1
For more detail on operators, see Chapter 6 of Verilog HDL by Samir Palinitkar. Some are
discussed below:
a) Shift Operators
Shift operators are right shift ( >>), left shift (<<), arithmetic right shift (>>>), and arithmetic
left shift (<<<). Regular shift operators shift a vector operand to the right or the left by a
specified number of bits. The operands are the vector and the number of bits to shift. When
the bits are shifted, the vacant bit positions are filled with zeros. Shift operations do not wrap
around. Arithmetic shift operators use the context of the expression to determine the value
with which to fill the vacated bits.
// X = 4'b1100
Y = X >> 1; //Y is 4'b0110. Shift right 1 bit. 0 filled in MSB position.
Y = X << 1; //Y is 4'b1000. Shift left 1 bit. 0 filled in LSB position.
Y = X << 2; //Y is 4'b0000. Shift left 2 bits.
Shift operators are useful because they allow the designer to model shift operations, shift-
and-add algorithms for multiplication, and other useful operations.
b) Concatenation Operator
The concatenation operator ( {, } ) provides a mechanism to append multiple operands. The
operands must be sized. Unsized operands are not allowed because the size of each operand
must be known for computation of the size of the result.
Concatenations are expressed as operands within braces, with commas separating the
operands. Operands can be scalar nets or registers, vector nets or registers, bit-select, part-
select, or sized constants.
// A = 1'b1, B = 2'b00, C = 2'b10, D = 3'b110
Y = {B , C} // Result Y is 4'b0010
Y = {A , B , C , D , 3'b001} // Result Y is 11'b10010110001
Y = {A , B[0], C[1]} // Result Y is 3'b101
d) Conditional Operator
The conditional operator(?:) takes three operands. The syntax of an assign statement is as
follows.
condition_expr ? true_expr : false_expr ;
The condition expression (condition_expr) is first evaluated. If the result is true (logical 1),
then the true_expr is evaluated. If the result is false (logical 0), then the false_expr is
evaluated. If the result is x (ambiguous), then both true_expr and false_expr are evaluated
and their results are compared, bit by bit, to return for each bit position an x if the bits are
different and the value of the bits if they are the same.
The action of a conditional operator is similar to a multiplexer. Alternately, it can be
compared to the if-else expression. Conditional operators are frequently used in dataflow
modeling to model conditional assignments. The conditional expression acts as a switching
control.
The logic diagram of a full adder is given below. From the following figure, it is clear that we
can make a full adder using two half adders & an OR gate.
output S, C;
input A, B;
endmodule
endmodule
4.3 Stimulus
module Stimulus;
//This time we have instantiated full-adder module as it is the one we are testing
endmodule
5. Lab Task
Implement a 3X8 Decoder in Verilog using Dataflow modeling. Also simulate your
design for verification (Create a proper Stimulus or Test Bench file).
Hint: Use Logic operators for the task. Set D with 8 bit size ([7:0]). It is clear from above
table that when x=0,y=0,z=0 then D=8’b00000001; or D[0]=1 i.e. we can write
6. Home Work
Implement a 4X16 Decoder using instantiation (Use two 3X8 Decoders). Simulate using
ModelSim. Submit the code and wave files in the next lab.
Note:
a) This assignment must be submitted before the next lab.
b) The assignment submitted must be in proper format as instructed by the teacher to get
maximum marks.
c) Marks will be deducted on late submissions.
d) Cheating or using any unfair means will award ZERO marks.
Q.3 Write the code for implementing 4X1 Mux using conditional operator.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________