Vlsi Lab
Vlsi Lab
INTRODUCTION TO HDL
In computer engineering, a Hardware Description Language (HDL) is a specialized computer
language used to describe the structure and behavior of electronic circuits, and most commonly, digital
logic circuits.
Due to the exploding complexity of digital electronic circuits since the 1970s (see Moore's law),
circuit designers needed digital logic descriptions to be performed at a high level without being tied to a
specific electronic technology, such as CMOS or BJT. HDLs were created to implement register-transfer
level abstraction, a model of the data flow and timing of a circuit.
3. Data Types:
Verilog supports various data types for representing different kinds of digital signals and
variables.
Common data types include wire, reg, integer, parameter, etc.
wire: Used for representing connections between components.
reg: Used for sequential logic elements like flip-flops and registers.
4. Continuous Assignments:
Continuous assignments allow you to assign values to wires directly within the module body.
They are used for combinational logic, where the output depends solely on the current input
values. Continuous assignments use the “assign” keyword.
5. Behavioral Statements:
Behavioral statements describe the behavior of a digital circuit.
They include procedural blocks like always, initial, and begin/end.
Procedural blocks are used to model sequential logic and control the simulation flow.
6. Simulation Constructs:
Verilog provides constructs for specifying simulation scenarios and test cases.
Testbenches are written to verify the functionality of modules.
Simulation constructs include initial blocks for initialization and always b locks for continuous
behavior.
INTRODUCTION TO XILINX
ISE Xilinx (Integrated Software Environment (ISE)), i.e. programmable logic design tool in electronics
industry. This Xilinx design software suite allows taking design from design entry through Xilinx device
programming. The ISE Project Navigator manages and processes design through several steps in the ISE
design flow. These steps are Design Entry, Synthesis, Implementation, Simulation/Verification, and
Device Configuration. Xilinx is one of most popular software tool used to synthesize VHDL code.
Release version : 14.7
3
Page
4
Page
STEP 2:
5
Page
STEP 3:
6. In the Design window (Left most top corner) Select available device (Ex. Xc6slx4-3csg225),
right click on it. Select the new source, select Verilog module, give file name, enable the Add
Project and click on next.
6
Page
7. Specify the ports (Input, Output and Inout). Then click on Next and Finish.
7
Page
STEP 4:
9. In the process window (Left most bottom corner), e xpand synthesize XST and double click on
check syntax.
STEP 5:
11. In the Design window (Left most top corner), select .v file, click on new source.
12. In new source window select Verilog Test Fixture and give file name and enable the option Add
to Project, click on next, next and finish.
9
Page
STEP 6:
13. Give the inputs (between initial begin and end) in the Test bench (TB) file and click on save.
14. In the Design window (Left most top corner), Change the view to Simulation, select the test
bench (TB) file.
15. In the Process window (Left most bottom corner), elaborate ISim Simulator. Double click on
Behavioral Check Syntax to check for errors and double click on Simulate Behavioral Model to
observe the output waveform.
10
16. Select the measure marker option in the Toolbar to verify the simulation output.
Page
PROGRAM 01
4 - BIT ADDER
AIM
To design a Verilog model for 4-bit adder and to generate a report for determining total area,
maximum delay and power requirement.
APPARATUS REQUIRED
THEORY
A 4-bit adder is a digital circuit that performs addition of two 4-bit binary numbers. The basic building
blocks of a 4-bit adder are the full adders. Each full adder takes in three inputs : two bits to be added (A
and B) and a carry in (Cin) from the previous stage. It produces two outputs: a sum (S) and a carry out
(Cout) to the next stage.
Input: Two 4-bit binary numbers are provided as input, typically labeled as A and B. Each of these
numbers is broken down into individual bits: A0, A1, A2, A3 and B0, B1, B2, B3.
Carry In (Cin): Initially, there is no carry into the least significant bit (LSB), so Cin is usually set to 0.
Addition: The bits from each position (A0 and B0, A1 and B1, and so on) are added together along with
the carry in (Cin) from the previous stage using full adders. This generates a sum (S) and a carry out
(Cout) for each stage.
Propagation: The carry out (Cout) from each stage is fed as the carry in (Cin) to the next higher-order
stage.
Output: The sum bits (S0, S1, S2, S3) generated at each stage constitute the result of the addition
operation. The carry out (Cout) from the most significant bit (MSB) indicates whether there is a carry
11
beyond the 4-bit boundary, which would imply overflow in unsigned addition.
Page
LOGIC SYMBOL
TRUTH TABLE
Inputs Outputs
A3 A2 A1 A0 B3 B2 B1 B0 Cin Cout S3 S2 S1 S0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1 1 0 0 0 1 1
0 0 1 0 0 0 1 0 0 0 0 1 0 0
0 0 1 1 0 0 1 1 1 0 0 1 1 1
0 1 0 0 0 1 0 0 0 0 1 0 0 0
0 1 0 1 0 1 0 1 1 0 1 0 1 1
0 1 1 0 0 1 1 0 0 0 1 1 0 0
0 1 1 1 0 1 1 1 1 0 1 1 1 1
1 0 0 0 1 0 0 0 0 1 0 0 0 0
1 0 0 1 1 0 0 1 1 1 0 0 1 1
1 0 1 0 1 0 1 0 0 1 0 1 0 0
1 0 1 1 1 0 1 1 1 1 0 1 1 1
1 1 0 0 1 1 0 0 0 1 0 1 0 0
1 1 0 1 1 1 0 1 1 1 0 1 1 1
1 1 1 0 1 1 1 0 0 1 1 1 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1
12
Page
VERILOG CODE
DESIGN BLOCK (DATAFLOW DESCRIPTION)
module adder_4bit(
input [3:0] a,b,
input c_in,
output [3:0] s,
output c_out);
assign {c_out,sum}=a+b+c_in;
endmodule
STIMULUS BLOCK
module adder_4bit_sb;
// Inputs
reg [3:0] a;
reg [3:0] b;
reg c_in;
// Outputs
wire [3:0] s;
wire c_out;
// Instantiate the Unit Under Test (UUT)
adder_4bit uut (
.a(a),
.b(b),
.c_in(c_in),
.s(s),
.c_out(c_out));
initial begin
a=4'b0000;b=4'b0000; c_in=0;
#10 a=4'b0001;b=4'b0001; c_in=1;
#10 a=4'b0010;b=4'b0010; c_in=0;
#10 a=4'b0011;b=4'b0011; c_in=1;
#10 a=4'b0100;b=4'b0100; c_in=0;
#10 a=4'b0101;b=4'b0101; c_in=1;
#10 a=4'b0110;b=4'b0110; c_in=0;
#10 a=4'b0111;b=4'b0111; c_in=1;
#10 a=4'b1000;b=4'b1000; c_in=0;
#10 a=4'b1001;b=4'b1001; c_in=1;
#10 a=4'b1010;b=4'b1010; c_in=0;
#10 a=4'b1011;b=4'b1011; c_in=1;
#10 a=4'b1100;b=4'b1100; c_in=0;
#10 a=4'b1101;b=4'b1101; c_in=1;
#10 a=4'b1110;b=4'b1110; c_in=0;
13
endmodule
RTL SCHEMATIC
TECHNOLOGY SCHEMATIC
OUTPUT WAVEFORM
14
Page
ANALYSIS REPORT
1. Total Area
Device utilization summary:
Number of IOs: ______ out of _____ ______
2. Maximum Delay
Timing Details:
Maximum Delay: __________
3. Power Requirement
Total Power Dynamic Quiescent
15
RESULT: The 4-bit adder has been realized and simulated using verilog code and report has bee n
Page
generated for calculating total area, maximum delay and power requirement..
16
Page
PROGRAM 02
32-BIT ALU
AIM
To design a Verilog model for 32-bit ALU supporting 4-Logical and 4-Arithmetic operations using
case statement and if statement and to generate a report for determining to tal area, maximum dela y
and power requirement.
THEORY
ALU stands for Arithmetic Logic Unit.An arithmetic- logic unit is the part of a central processing unit
that carries out arithmetic and logic operations on the operands. The inputs to an ALU are the data to
be operated on, called operands, and an opcode indicating the operation to be performed; the ALU's
output is the result of the performed operation.
Typically, the ALU has direct input and output access to the processor controller, main memor y
(random access memory or RAM in a personal computer) and input/output devices. Inputs and
outputs flow along an electronic path that is called a bus.
The input consists of an instruction word, that contains an opcode which tells the ALU what
operation to perform and the operands are used in the operation.
The output consists of a result that is placed in a storage register and settings that indicate whether
the operation was performed successfully.
The four basic arithmetic operations are: Addition (Finding the Sum; ‘+’), Subtraction (Finding the
difference; ‘-’), Multiplication (Finding the product; ‘×’ ), and Division (Finding the quotient; ‘÷’)
The basic Logical operations are: AND, OR, NOT, XOR, and NAND.
17
Page
LOGIC SYMBOL
TRUTH TABLE
VERILOG CODE
DESIGN BLOCK (BEHAVIORAL DESCRIPTION)
module alu_4bit(
input [31:0] a,b,
input [2:0] opcode,
output reg[31:0] y);
always @ (a,b,opcode)
begin
case(opcode)
3'b000:y=a+b;
3'b001:y=a-b;
18
3'b010:y=a*b;
3'b011:y=a/b;
Page
3'b100:y=a&b;
3'b101:y=a|b;
3'b110:y=~(a&b);
3'b111:y=a^b;
endcase
end
endmodule
STIMULUS BLOCK
module alu_4bit_sb;
// Inputs
reg [31:0] a;
reg [31:0] b;
reg [2:0] opcode;
// Outputs
wire [31:0] y;
// Instantiate the Unit Under Test (UUT)
alu_4bit uut (.a(a), .b(b), .opcode(opcode), .y(y));
initial begin
a = 32'b0100;b =32'b0010;
opcode=3'b000;
#10 opcode=3'b001;
#10 opcode=3'b010;
#10 opcode=3'b011;
#10 opcode=3'b100;
#10 opcode=3'b101;
#10 opcode=3'b110;
#10 opcode=3'b111;
end
endmodule
RTL SCHEMATIC
19
Page
OUTPUT WAVEFORM
ANALYSIS REPORT
1. Total Area
Device utilization summary:
Number of IOs: ______ out of _____ ______
2. Maximum Delay
Timing Details:
Maximum Delay: __________
3. Power Requirement
Total Power Dynamic Quiescent
20
RESULT: The 32-bit ALUhas been realized and simulated using verilog code and report has bee n
Page
generated for calculating total area, maximum delay and power requirement.
1. Expand ALU.
2. Explain the functioning of ALU.
3. Define opcode.
4. Define operand.
5. Explain the types of logical operators in digital system.
6. Explain the types of arithmetic operators in digital system.
21
Page
PROGRAM 03
LATCH AND FLIP-FLOP
AIM
To design a Verilog model for SR Latch and SR Flip-Flop and to generate a report for determining
total area, maximum delay and power requirement.
THEORY
SR is also called as Set (Logic 1) and Reset (Logic 0). SR latch affects the outputs as long as the
enable, E is maintained at ‘1’. For SR flip- flop a clock pulse is supplied to operate. If the flip- flop
works either with positive clock or negative clock.
Set and Reset condition: The output is set (Q = 1) when S = 1 and R = 0, and reset (Q = 0) when S =
0 and R = 1.
No change condition: The output is no change (Q = Q) when S = R = 0.
Invalid condition: The output is invalid (Q = X) when S = R = 1.
LOGIC SYMBOL
TRUTH TABLE
SR LATCH SR FLIP-FLOP
INPUTS OUTPUTS INPUTS OUTPUTS
En S R Q Qb ACTION Reset Clk S R Q Qb ACTION
0 X X 0 1 Reset 1 X X X 0 1 Reset
1 0 0 Q Qb No change 0 1 0 0 Q Qb No change
1 0 1 0 1 Reset 0 1 0 1 0 1 Reset
22
1 1 0 1 0 Set 0 1 1 0 1 0 Set
Page
1 1 1 X X Invalid 0 1 1 1 X X Invalid
SR LATCH SR FLIP-FLOP
module SR_LATCH( module SR_FF(
input [1:0] SR, input [1:0] SR,
input en, input reset,clk,
output reg Q,Qb); output reg Q,Qb);
always @ (SR,en) always @ (posedge clk)
begin begin
if (en == 0) if (reset == 1)
Q=0; Q=0;
else else
begin begin
casex (SR) casex (SR)
2'b00:Q=Q; 2'b00:Q=Q;
2'b01:Q=0; 2'b01:Q=0;
2'b10:Q=1; 2'b10:Q=1;
2'b11:Q=1'bX; 2'b11:Q=1'bX;
endcase endcase
end end
Qb=~Q; Qb=~Q;
end end
endmodule endmodule
STIMULUS BLOCK
SR LATCH SR FLIP-FLOP
module SR_LATCH_SB; module SR_FF_SB;
// Inputs // Inputs
reg [1:0] SR; reg [1:0] SR;
reg en; reg reset;
// Outputs reg clk;
wire Q; // Outputs
wire Qb; wire Q;
// Instantiate the Unit Under Test (UUT) wire Qb;
SR_LATCH uut ( // Instantiate the Unit Under Test (UUT)
.SR(SR), SR_FF uut (
.en(en), .SR(SR),
.Q(Q), .reset(reset),
.Qb(Qb)); .clk(clk),
initial begin .Q(Q),
en=0;SR=2'b00; .Qb(Qb));
#10 en=1;SR=2'b00; initial begin
#10 en=1;SR=2'b01; clk=1;
23
endmodule reset=1;SR=2'b00;
#10 reset=0;SR=2'b00;
#10 reset=0;SR=2'b01;
#10 reset=0;SR=2'b10;
#10 reset=0;SR=2'b11;
end
endmodule
RTL SCHEMATIC
TECHNOLOGY SCHEMATIC
24
Page
OUTPUT WAVEFORM
1. SR LATCH
2. SR FLIP-FLOP
1. Total Area
Device utilization summary:
Number of IOs: ______ out of _____ ______
2. Maximum Delay
Timing Details:
Maximum Delay: __________
3. Power Requirement
Total Power Dynamic Quiescent
25
RESULT: The SR Latch and Flip-Flop has been realized and simulated using verilog code and report
Page
has been generated for calculating total area, maximum delay and power requirement.
AIM
To design a Verilog model for JK Latch and JK Flip-Flop and to generate a report for determining
total area, maximum delay and power requirement.
THEORY
The JK represents an advancement over the SR by resolving the invalid state issue inherent in the SR
latch / flip- flop through the inclusion of feedback. The JK originally named after its inventor, Jack
Kilby, stands for Jack Kilby latch / flip-flop.
JK latch affects the outputs as long as the enable, E is maintained at ‘1’. For JK flip- flop a clock
pulse is supplied to operate. If the flip-flop works either with positive clock or negative clock.
Set and Reset condition: The output is set (Q = 1) when J = 1 and K = 0, and reset (Q = 0) when J = 0
and K = 1.
No change condition: The output is no change (Q = Q) when J = K = 0.
Toggle condition: The output is toggle (Q = ~Q) when J = K = 1.
LOGIC SYMBOL
TRUTH TABLE
JK LATCH JK FLIP-FLOP
INPUTS OUTPUTS INPUTS OUTPUTS
En J K Q Qb ACTION Reset Clk J K Q Qb ACTION
0 X X 0 1 Reset 1 X X X 0 1 Reset
1 0 0 Q Qb No change 0 1 0 0 Q Qb No change
1 0 1 0 1 Reset 0 1 0 1 0 1 Reset
26
1 1 0 1 0 Set 0 1 1 0 1 0 Set
Page
1 1 1 Qb Q Toggle 0 1 1 1 Qb Q Toggle
JK LATCH JK FLIP-FLOP
module JK_LATCH( module JK_FF(
input [1:0] JK, input [1:0] JK,
input en, input reset,clk,
output reg Q,Qb); output reg Q,Qb);
always @ (JK,en) always @ (posedge clk)
begin begin
if (en == 0) if (reset == 1)
Q=0; Q=0;
else else
begin begin
case(JK) case (JK)
2'b00:Q=Q; 2'b00:Q=Q;
2'b01:Q=0; 2'b01:Q=0;
2'b10:Q=1; 2'b10:Q=1;
2'b11:Q=~Q; 2'b11:Q= ~Q;
endcase endcase
end end
Qb=~Q; Qb=~Q;
end end
endmodule endmodule
STIMULUS BLOCK
JK LATCH JK FLIP-FLOP
module JK_LATCH_SB; module JK_FF_SB;
// Inputs // Inputs
reg [1:0] JK; reg [1:0] JK;
reg en; reg reset;
// Outputs reg clk;
wire Q; // Outputs
wire Qb; wire Q;
// Instantiate the Unit Under Test (UUT) wire Qb;
JK_LATCH uut ( // Instantiate the Unit Under Test (UUT)
.JK(JK), JK_FF uut (
.en(en), .JK(JK),
.Q(Q), .reset(reset),
.Qb(Qb)); .clk(clk),
initial begin .Q(Q),
en=0;JK=2'b10; .Qb(Qb));
#10 en=1;JK=2'b00; initial begin
#10 en=1;JK=2'b01; clk=1;
27
endmodule reset=1;JK=2'b10;
#10 reset=0;JK=2'b00;
#10 reset=0;JK=2'b01;
#10 reset=0;JK=2'b10;
#10 reset=0;JK=2'b11;
end
endmodule
RTL SCHEMATIC
TECHNOLOGY SCHEMATIC
28
Page
OUTPUT WAVEFORM
1. JK LATCH
2. JK FLIP-FLOP
1. Total Area
Device utilization summary:
Number of IOs: ______ out of _____ ______
2. Maximum Delay
Timing Details:
Maximum Delay: __________
3. Power Requirement
RESULT: The JK Latch and Flip-Flop has been realized and simulated using verilog code and report
Page
has been generated for calculating total area, maximum delay and power requirement.
AIM
To design a Verilog model for D Latch and D Flip-Flop and to generate a report for determining tota l
area, maximum delay and power requirement.
THEORY
D represents “Delay” or “Data”. They are used to store 1 – bit binary data. D latch affects the outputs
as long as the enable, E is maintained at ‘1’. For D flip-flop a clock pulse is supplied to operate. If the
flip-flop works either with positive clock or negative clock.
Set and Reset condition: The output is set (Q = 1) when D = 1, and reset (Q = 0) when D = 0.
LOGIC SYMBOL
TRUTH TABLE
D LATCH D FLIP-FLOP
INPUTS OUTPUTS INPUTS OUTPUTS
En D Q Qb ACTION Reset Clk D Q Qb ACTION
0 X 0 1 Reset 1 X X 0 1 Reset
1 0 0 1 Reset 0 1 0 0 1 Reset
1 1 1 0 Set 0 1 1 1 0 Set
D LATCH D FLIP-FLOP
module D_LATCH( module D_FF(
30
begin begin
if (en == 0) if (reset == 1)
begin begin
Q=0; Q=0;
Qb=~Q; Qb=~Q;
end end
else else
begin begin
Q=D; Q=D;
Qb=~Q; Qb=~Q;
end end
end end
endmodule endmodule
STIMULUS BLOCK
D LATCH D FLIP-FLOP
module D_LATCH_SB; module D_FF_SB;
// Inputs // Inputs
reg D, en; reg D, reset, clk;
// Outputs // Outputs
wire Q; wire Q;
wire Qb; wire Qb;
// Instantiate the Unit Under Test (UUT) // Instantiate the Unit Under Test (UUT)
D_LATCH uut ( D_FF uut (
.D(D), .D(D),
.en(en), .reset(reset),
.Q(Q), .clk(clk),
.Qb(Qb)); .Q(Q),
initial begin .Qb(Qb));
en=0;D=0; initial begin
#10 en=1;D=0; clk=1;
#10 en=1;D=1; forever #5 clk=~clk;
end end
endmodule initial begin
reset=1;D=0;
#10 reset=0;D=0;
#10 reset=0;D=1;
end
endmodule
31
Page
RTL SCHEMATIC
TECHNOLOGY SCHEMATIC
OUTPUT WAVEFORM
1. D LATCH
2. D FLIP-FLOP
32
Page
1. Total Area
Device utilization summary:
Number of IOs: ______ out of _____ ______
2. Maximum Delay
Timing Details:
Maximum Delay: __________
3. Power Requirement
Total Power Dynamic Quiescent
33
RESULT: The D latch and Flip-Flop has been realized and simulated using verilog code and report
Page
has been generated for calculating total area, maximum delay and power requirement.
PROGRAM 04
4-BIT BOOTH’S ALGORITHM
AIM
To design a Verilog model for 4-bit Booth’s algorithm and to generate a report for determining tota l
area, maximum delay and power requirement.
THEORY
Booth algorithm gives a procedure for multiplying binary integers in signed 2’s complement
representation in efficient way, i.e., less number of additions/subtractions required. It is also used to
speed up the performance of the multiplication process.
Start
A = 0; Accumulator,
P = 0; Previous bit,
X = Multiplicand, Y = Multiplier, N = Count
10 Y0,P 01
00, 11
A=A-X A=A+X
No N=0? Yes
End
34
Page
OPERATION
Example 1: 4 * 2 = 8
Where X = 4 = 0100 and Y = 2 = 0010
Step A Y P Operation
0 0000 0010 0 Initial
1 0000 0001 0 00 = Arithmetic Right Shift
10 = A = A-X
-X = 2’s complement of X
X = 0100
1’s complement = 1011
1100 0001 0 + 1
2
-X = 2’s complement = 1100
A =A–X
A = 0000 + 1100 = 1100
Example 2: -5 * 4 = -20
Where X = -5 (2’s complement) = 1011 and Y = 4 = 0100
Step A Y P Operation
0 0000 0100 0 Initial
1 0000 0010 0 00 = Arithmetic Right Shift
2 0000 0001 0 00 = Arithmetic Right Shift
10 = A = A - X
0101 0001 0 -X = 0101
3 A = 0000 + 0101 = 0101
0010 1000 1 Arithmetic Right Shift
01 = A = A + X
1101 1000 1
4 A = 0010 + 1011 = 1101
1110 1100 0 Arithmetic Right Shift
Verification: 11101100
1’s complement: 00010011
+ 1
2’s complement: 00010100 (-21)
module booth_multiplier(
input signed [3:0] X, Y,
output reg signed [7:0] Z);
reg [1:0] temp;
integer N;
reg P;
reg [3:0] X1;
always @ (X, Y)
begin
Z = 8‘b00000000;
P = 0;
for (N = 0; N < 4; N = N + 1)
begin
temp = {Y[N], P};
X1 = - X;
case (temp)
2'd2 : Z [7 : 4] = Z [7 : 4] + X1;
2'd1 : Z [7 : 4] = Z [7 : 4] + X;
endcase
Z = Z >>> 1;
Z[7]=Z[6];
P = Y[N];
end
end
36
endmodule
Page
STIMULUS BLOCK
module booth_tb;
reg [3:0] X;
reg [3:0] Y;
wire [7:0] Z;
booth_multiplier uut (.X(X),.Y(Y),.Z(Z));
initial begin
X = 4'b0100; Y = 4'b0010;
#10 X = -4’b0101; y = 4’b1000;
end
endmodule
RTL SCHEMATIC
OUTPUT WAVEFORM
ANALYSIS REPORT
1. Total Area
Device utilization summary:
Number of IOs: ______ out of _____ ______
2. Maximum Delay
Timing Details:
Maximum Delay: __________
3. Power Requirement
Total Power Dynamic Quiescent
37
RESULT: The 4-bit Booth’s algorithm has been realized and simulated using verilog code and report
Page
has been generated for calculating total area, maximum delay and power requirement.