Vlsi Lab Maual 20-21 Finalized
Vlsi Lab Maual 20-21 Finalized
Vlsi Lab Maual 20-21 Finalized
ENGINEERING COLLEGE
(Approved by AICTE, New Delhi & affiliated to VTU, Belagavi)
18th Km, Bannerghatta road, Bengaluru-560083)
SEMESTER: VII
Student name:
USN:
Year:
1
INDEX TABLE
IV Syllabus 8
V Rubrics 9
VI Introduction 10
crea
List of Experiments
Exp. Bloom’s
Exp. Name CO PO PSO
No. cognitive level
Part-A
Design a Schematic and layout 4, 5
1. Create 2,3, 5 1,2
diagram of Inverter with DC,AC
Analysis.
Design a Schematic and layout Create 4 ,5 2,3, 5 1,2
diagram of NAND with DC,AC
2. Analysis
Design a Schematic and layout Create 4,5 2,3, 5 1,2
3. diagram of Common Sourcs (CS)
with DC,AC Analysis
4 Design a Schematic and layout Create 4,5 2,3,5 1,2
diagram of Opamp with DC,AC
Analysis
Part-B
1. Design a Verilog code for the Flip- Apply 1 2,3,5,10 1,2
flops and Latches and perform
Simulation and Synthesizes
2. Design a Verilog code for the 4- bit Apply 2 2,3,5,10 1,2
counter and perform Simulation and
Synthesizes
INSTITUTE VISION
To be a leader in imparting value based Technical Education and Research for the benefit of society.
INSTITUTE MISSION
To provide state of the art Infrastructure facilities.
To implement modern pedagogical methods in delivering the academic programs with
experienced and committed faculty.
To create a vibrant ambience that promotes Learning, Research, Invention and Innovation.
To undertake manpower and skill development programmes for Academic Institutions and
Industries.
To enhance Institute Industry Interface through Collaborative Research and Consultancy
To generate and disseminate knowledge through training
programme/workshops/seminars/conferences/publications.
To be a more comprehensive college in terms of the number of programs offered.
To relentlessly pursue professional excellence with ethical and moral values.
DEPARTMENT VISION
To develop outstanding Electronics and Communication Engineers to meet the ever changing
Social and Technological needs of the Society.
DEPARTMENT MISSION
MoD1 To provide State-of-the-Art infrastructure in Electronics and Communication Engineering.
To disseminate strong theoretical and practical exposure to meet the emerging trends in the
MoD2 industry.
MoD3 To promote a free thinking environment with innovative teaching-learning pedagogy.
To develop value based socially responsible professionals for the betterment of the
MoD4
Society.
C208.1 3 - - - - - - - - - - - 2 2
C208.2 - - 3 - - - - - - - - - 2 2
C208.3 - - 3 - - - - - - - - 2 -
C208.4 - - 3 - - - - - - - - - 2
C208.5 - - 1 - - - - - 1 - - 1 1 1
B. E. EC / TC
Choice Based Credit System (CBCS) and Outcome Based Education (OBE)
SEMESTER – III
VLSI DESIGN LABORATORY
Laboratory Code 18ECL77 IA Marks 40
02Hr Tutorial (Instructions)
Number of Lecture Hours/Week Exam Mark 60
+ 02 Hours Laboratory
CREDITS 02 Exam Hour 03
Course objectives:This laboratory course enables students to get practical experience in design,
verification , synthesis ,schematic and layout of
Flip-Flops,Latches,Adders,Counter ALU and URAT Programs.
Schematic of Inverter, NANA, Common Source(CS).
Layout formation of Inverter, NANA, Common Source(CS).
NOTE:
For stimulate we use tool Mentogaphics.
For synthesis we use tool oyasis.
For schematic we use tool S-edit.
For layout we use tool T-edit softwares
Part-A
Design the Schematic diagram for the followings with their Layout.
Inverter(INV)
NAND
Common Source(CS)
Opamp
Part-B
Perform stimulation and synthesis for below programs.
(i)Flip-flops and Latches.
(ii)4-bit counter
(iii)Asynchronous adder
(iv)32- bit ALU
(v)URAT
Conduction of program beyond syllabus
(vi)Booth multiplexer(Radix-4)
Conduct of Practical Examination:
All laboratory experiments are to be included for practical examination.
Students are allowed to pick one experiment from the lot.
Strictly follow the instructions as printed on the cover page of answer script for breakup of
marks.
Change of experiment is allowed only once and 15% Marks allotted to the procedure
part to be made zero.
IV. RUBRICS
S.no. Description( IA 1) Marks allotted
1 Write-up 15
2 Execution 70
3 Viva 15
1 Write-up 15
2 Execution 70
3 Viva 15
2 Record Book 12
Run simulation
Tanner L – edit – create new design
Click File -> New -> Design
Browse design path and select Open Access referenced
libraries option in Technology reference
Click OK
Layout design
• Use Poly layer and Metal1 layer to establish
connection between nmos and pmos
•
Layout design
• Use Cnt_Poly from library to connect vin at poly layer
Layout design
• Complete layout design through metal1 layer
connection and place vdd, vss and vout in their
respective places
• Use ctrl+c and ctrl+v to copy metal1 layers
PART-A
EXPERIMENT NO.1
INVERTER
INVERTER schematic
Transient analysis
LAYOUT:
EXPERIMENT NO.2
2-BIT NAND GATE
NAND schematic
Transient analysis
Layout:
EXPERIMENT NO.3
COMMON SOURCE AMPLIFIER
Waveforms
Transient analysis
Layout:
EXPERIMENT NO.4
OPAMP
Schematic
Testbench Schematic
Waveforms
Transient analysis
Layout:
PART-B
Stepsto –QuestaSim.
Create verilogprogram
4 bit up counter program is created with active high reset
Clicksaveicon in toolbar to saveverilog program file
3
Compileverilogprogram
• ClickCompile -> compile to check syntax errors in the program
• Select the verilog file and click Compilebutton.
Compilation results
• Compilation results will be displayed in the Transcriptwindow
• Errors and warnings details will bedisplayed
• vlog command is an alternative foe the GUIcompilation processwhich is used
Functional simulation
4
Addwave
• Right click on module name cnt in library and clickAdd wave (Ctrl +W)
• add wave * is the command to add wave through transcript
Forceinputs reset and clock
16
RunOasysscript
17
Start oasysGUI
• After scripts execution completed successfully type command start_gui tostart oasys application GUI.
• If there is any error, itwill be displayed by stopping scripts execution and design data won’t be exported to outputdirectory
18
Oasys source
• Start_gui command opens the oasys-RTLtool and verilog code of our program will be displayed in sourcetab.
19
Oasysnetlist
20
Oasysnetlist
• Detailed gate level netlist structure canbe seenby zoomin through continuous double clicks
• In the given example standard Half Adder, NOR,ANDandAOIare used
21
Oasysnetlist
22
Oasysnetlist
• Following picture givesthe detailed view of the always block is used for thisexample
• Dflip flop is used to achieve the behavior which is shown inpic
23
Oasysnetlist
• Following picture shows the schematic of four flip flops which are used to achieve the requirement for thisexample
Oasysoutput:
module adder(a, b, cin, sum, carry);
input [3:0]a;
input [3:0]b;
input cin;
output [3:0]sum;
output carry;
wire n_0_0_0;
wire n_0_0_1;
wire n_0_0_2;
wire n_0_0_3;
wire n_0_0_4;
wire n_0_0_5;
wire n_0_0_6;
wire n_0_0_7;
wire n_0_0_8;
wire n_0_0_9;
wire n_0_0_10;
wire n_0_0_11;
wire n_0_0_12;
wire n_0_0_13;
wire n_0_0_14;
EXPERIMENT NO.1
FLIP FLOPS SIMULATION AND SYNTHESIS
Aim: Design and simulate SR Flip Flop in one of the following modeling styles
Program
Test Bench
module rs_ff_tb;
reg [1:0] rs;
reg clock,rest;
wire q, qb;
rs_ff rs_ffuut(rest,clock,rs,q,qb);
initial
clock=1'b1;
rest=1’b0;
end
always #5 clock=~clock;
always #20 rest=~rest;
initial
begin
rs=2'b00;
#20 rs =2'b01;
#20 rs =2'b10;
#20 rs =2'b11;
end
initial
$monitor ($time, "rs=%b, clock=%b ,rest=%b,q=%b, qb=%b ", rs, q, qb);
endmodule
Expected Waveforms:
Synthesis Output:
module srff(sr, clock, q, qb);
input [1:0]sr;
input clock;
output q;
output qb;
wire n_1_0;
wire n_1_1;
wire n_1_2;
wire n_1_1_0;
wire n_1_3;
wire n_1_1_1;
wire n_1_1_2;
Result:
Program
Test Bench
module dff_tb;
reg clock, reset, d;
wire q, qb;
dff uut (reset, clock, d, q, qb);
Initial
Begin
clock=1'b1;
reset=1'b0;
d=1`b0;
End
always#5 clock=~clock;
always#40 reset=~reset;
Initial
Begin
#20 d =1'b1;
#20 d =1'b0;
#20 d =1'b1;
#50 d =1'b0;
end
initial
begin
$monitor ($time, "reset=%b clock=%b d=%b q=%b qb=%b", reset, clock, d, q, qb);
end
endmodule
Expected Waveforms:
Synthesis Output:
module dff(rst, clk, d, q, qb, SE, SI, SO);
input rst;
input clk;
input d;
output q;
output qb;
input SE;
input SI;
output SO;
wire n_0_0_0;
wire n_0_0;
Result:
Aim: Design and simulate JK Flip Flop in one of the following modelingstyles (Behavioral,
Data flow or Structural) using Verilog.
Program:
Test Bench
module JK_ff_tb;
reg [1:0] JK;
reg clock,rest;
wire q, qb;
JK_FF uut(JK,rest, clock, q, qb);
initial
clock=1'b1;
always #5 clock=~clock;
always #20 rest=~rest;
initial
begin
JK=2'b00; #20;
JK=2'b01; #20;
JK=2'b10; #20;
JK=2'b11; #50;
end initial
$monitor ($time, "JK=%b ,rest=%b,q=%b ,qb=%b ", JK,clock,rest, q, qb);
endmodule
Expected Waveforms:
Synthesis Output:
module jkff(jk, clk, q, qb, SE, SI, SO);
input [1:0]jk;
input clk;
output q;
output qb;
input SE;
input SI;
output SO;
wire n_0_0;
wire n_0_0_0;
wire n_0_2;
wire n_0_1;
Result:
EXPERIMENT NO.2
LATHCHES SIMULATION AND SYNTHESIS
(i) SR-Latches
Aim: Design and simulate SR Latches in one of the following modeling styles
Block Diagram
Truth Table
S q S R en q qb
0 0 0 x x
en 0 1 1 0 1
R qb
1 0 1 1 0
b
1 1 1 0 0
Program:
module rs_ff(rs,enable,q,qb);
input[1:0]rs;
input enable;
output q,qb;
reg q,qb;
always@(posedge enable)
begin
case(rs)
2'b00:q=q;
2'b01:q=1'b1;
2'b10:q=1'b0;
2'b11:q=1'dz;
endcase
qb=~q;
end
endmodule
Test Bench
module rs_ff_tb;
reg[1:0]rs;
reg enable;
wire q,qb;
rs_ff uut(rs,enable,q,qb);
initial
enable=1'b1;
always#5 enable=~enable;
initial
begin
rs=2'b00;
#20 rs=2'b01;
#20 rs=2'b10;
#20 rs=2'b11;
end
initial
$monitor($time,"rs=%b q=%b qb=%b",rs,q,qb);
endmodule
Expected Waveforms:
Synthesis Output:
module srl(rs, enable, q, qb);
input [1:0]rs;
input enable;
output q;
output qb;
wire n_1_0;
wire n_1_1;
wire n_1_2;
wire n_1_1_0;
wire n_1_3;
wire n_1_1_1;
wire n_1_1_2;
Result:
(ii) JK-Latches
Aim: Design and simulate JK-Latches in one of the following modeling styles
J q J K en q qb
0 0 0 x x
en
0 1 1 0 1
1 0 1 1 0
K qb 1 1 1 0 0
Program:
module jkl(jk,enable,q,qb);
input[1:0]jk;
input enable;
output q,qb;
reg q,qb;
always@(enable)
begin
case(jk)
2'b00:q=q;
2'b01:q=1'b0;
2'b10:q=1'b1;
2'b11:q=~q;
endcase
qb=~q;
end
endmodule
Test Bench:
module jkl_tb;
reg [1:0]jk;
reg enable;
wire q,qb;
jkl uut(jk,enable,q,qb);
initial
enable=1'b1;
always#5 enable=~enable;
initial
begin
#20 jk=2'b00;
#20 jk=2'b01;
#20 jk=2'b10;
#20 jk=2'b11;
end
initial
$monitor($time,"enable=%b,jk=%b,q=%b,qb=%b",enable,jk,q,qb);
endmodule
Expected Waveforms:
Synthesis Output:
module jkl(jk, enable, q, qb);
input [1:0]jk;
input enable;
output q;
output qb;
wire n_0_1;
wire n_0_0;
wire n_0_0_0;
Result:
(iii) D-Latches
Aim: Design and simulate D-Latche in one of the following modeling styles
D q D en q qb
0 0 x x
en
0 1 0 1
qb
1 1 1 0
1 1 0 0
Program:
module dl(d,enable,q,qb);
input d,enable;
output q,qb;
reg q,qb;
always @(enable)
begin
if(enable)
q<=1'b0;
else
q<=d;
end
assign qb=~q;
endmodule
Test Bench:
module dl_tb;
reg d,enable;
wire q,qb;
dl uut(d,enable,q,qb);
initial
enable=1'b1;
always#5 enable=~enable;
initial
begin
#20 d=1'b1;
#20 d=1'b0;
#20 d=1'b1;
#20 d=1'b0;
end
initial
$monitor($time,"d=%b,enable=%b,q=%b,qb=%b",d,enable,q,qb);
endmodule
Expected Waveforms:
Synthesis Output:
module dl(en, d, q);
input en;
input d;
output q;
output qb;
DLH_X1 q_reg (.D(d), .G(en), .Q(q));
INV_X1 1-0-0-0(.A(q), .ZN(/qb));
endmodule
Result:
EXPERIMENT NO.2
4BIT-ADDER DESIGN AND SIMULATION
Aim: Design a 4-Bit adder in one of the following modeling styles (Behavioral, Data flow or
Structural) using Verilog.
Block Diagram
a b a b a b a b
Program
(i) full_adder
(ii) 4bit_serial_full_adder
module fa_serial_4bit (a, b, cin, sum, carry);
input [3:0] a,b;
input cin;
output [3:0] sum;
output carry;
wire [3:1] w;
[[
full_adder fa0(.a(a[0]),.b(b[0]),.cin(cin),.sum(sum[0]),.carry(w[1]));
full_adder fa1(.a(a[1]),.b(b[1]),.cin(w[1]),.sum(sum[1]),.carry(w[2]));
full_adder fa2(.a(a[2]),.b(b[2]),.cin(w[2]),.sum(sum[2]),.carry(w[3]));
full_adderfa3(.a(a[3]),.b(b[3]),.cin(w[3]),.sum(sum[3]),.carry(carry));
endmodule
Test Bench
module fa_serial_4bit_tb;
reg [3:0] a,b;
reg cin;
wire [3:0] sum; wire carry;
fa_serial_4bit uu1(a, b, cin, sum, carry);
initial
begin
a=4'b0111; b=4'b0100; cin=1'b0;#10;
a=4'b1011; b=4'b0110; cin=1'b1;
end
initial
$monitor ($time, "a=%b b=%b cin=%b sum=%b carry=%b", a, b, cin, sum, carry);
endmodule
Expected Waveforms:
Synthesis Output:
module adder(a, b, cin, sum, carry);
input [3:0]a;
input [3:0]b;
input cin;
output [3:0]sum;
output carry;
wire n_0_0_0;
wire n_0_0_1;
wire n_0_0_2;
wire n_0_0_3;
wire n_0_0_4;
wire n_0_0_5;
wire n_0_0_6;
wire n_0_0_7;
wire n_0_0_8;
wire n_0_0_9;
wire n_0_0_10;
wire n_0_0_11;
wire n_0_0_12;
wire n_0_0_13;
wire n_0_0_14;
EXPERIMENT NO.3
COUNTER DESIGN AND SIMULATION
Asynchronous Counter
Aim: Design an Asynchronous counter in the behavioral modeling styles using Verilog.
Block Diagram
Program
(ii) 4bit-counter
Test Bench
module asyn_counter_tb;
reg clock, reset;
wire [3:0] count;
asyn_counter uut(clock, reset, count);
initial clock=1'b0;
always #10 clock=~clock;
initial
begin
#20; reset=1'b1; #20; reset=1'b0;
end
initial
$monitor( $time, " reset=%b count = %b" ,reset, count);
endmodule
Expected Waveforms
Synthesis Output:
module counter(clk, reset, count, SE, SI, SO);
input clk;
input reset;
output [3:0]count;
input SE;
input SI;
output SO;
assign SO = SI;
Result :
EXPERIMENT NO.4
32-Bit ALU DESIGN AND SIMULATION
Aim: Design an 32-Bit ALU in the behavioral modeling styles using Verilog.
Opcode-3bit
Block Diagram
a-32bit
32-Bit ALU
Op-32
b-32bit
Program
4'b0101:begin op=a&b;
$display("Bit wise AND");
end
4'b0110:begin op=a|b;
$display("Bit wise OR");
end
4'b0111:begin op=a&&b;
$display("Logical AND");
end
4'b1000:begin op=a^b;
$display("Bitwise XOR");
end
4'b1001:begin op=a||b;
$display("Logical OR");
end
4'b1010:begin op=~a;
$display("Bitwise Inverter");
end
4'b1011:begin op=!a;
$display("Logical Invert");
end
4'b1100:begin op=a>>1;
$display("Right Shift");
end
4'b1101:begin op=a<<1;
$display("Left shift");
end
4'b1110:begin op=a+1;
$display("Increment");
end
4'b1111:begin op=a-1;
$display("Decrement");
end
default:op=32'h00000000;
endcase
end
endmodule
Test Bench
module alut_tb;
reg [31:0]a,b;
reg [3:0]opcode;
wire [31:0]op;
alu uut(op,a,b,opcode);
initial
begin
a=32'h98765432;
b=32'h12345689;
opcode=4'b0000;
end
always#50 opcode=opcode+1;
endmodule
Expected Waveforms
Result :
EXPERIMENT NO.5
UART DESIGN AND SIMULATION
Program
RECIVER
case(r_SM_Main)
s_IDLE:
begin
r_Rx_DV <= 1'b0;
r_Clock_Count <= 0;
r_Bit_Index <= 0;
if(r_Rx_Data == 1'b0)
r_SM_Main <= s_RX_START_BIT;
else
r_SM_Main <= s_IDLE;
end
s_RX_START_BIT :
begin
if(r_Clock_Count== (CLKS_PER_BIT-1)/2)
begin
if(r_Rx_Data== 1'b0)
begin
r_Clock_Count<= 0;
r_SM_Main<= s_RX_DATA_BITS;
end
else
r_SM_Main<= s_IDLE;
end
else
begin
r_Clock_Count<= r_Clock_Count + 1;
r_SM_Main<= s_RX_START_BIT;
end
end
s_RX_DATA_BITS :
begin
if (r_Clock_Count<CLKS_PER_BIT-1)
begin
r_Clock_Count<=r_Clock_Count + 1;
r_SM_Main<=s_RX_DATA_BITS;
end
else
begin
r_Clock_Count <= 0;
r_Rx_Byte[r_Bit_Index] <= r_Rx_Data;
if (r_Bit_Index < 7)
begin
r_Bit_Index <= r_Bit_Index + 1;
r_SM_Main <= s_RX_DATA_BITS;
end
else
begin
r_Bit_Index <= 0;
r_SM_Main <= s_RX_STOP_BIT;
end
end
end
s_RX_STOP_BIT :
begin
if (r_Clock_Count < CLKS_PER_BIT-1)
begin
r_Clock_Count <= r_Clock_Count + 1;
r_SM_Main <= s_RX_STOP_BIT;
end
else
begin
r_Rx_DV <= 1'b1;
r_Clock_Count <= 0;
r_SM_Main <= s_CLEANUP;
end
end
s_CLEANUP :
begin
r_SM_Main <= s_IDLE;
r_Rx_DV <= 1'b0;
end
default :
r_SM_Main <= s_IDLE;
endcase
end
assign o_Rx_DV = r_Rx_DV;
assign o_Rx_Byte = r_Rx_Byte;
endmodule
TRANSMITTER
end
end // case: s_TX_START_BIT
// Wait CLKS_PER_BIT-1 clock cycles for data bits to finish
s_TX_DATA_BITS :
begin
o_Tx_Serial <= r_Tx_Data[r_Bit_Index];
if (r_Clock_Count < CLKS_PER_BIT-1)
begin
r_Clock_Count <= r_Clock_Count + 1;
r_SM_Main <= s_TX_DATA_BITS;
end
else
begin
r_Clock_Count <= 0;
// Check if we have sent out all bits
if (r_Bit_Index < 7)
begin
r_Bit_Index <= r_Bit_Index + 1;
r_SM_Main <= s_TX_DATA_BITS;
end
else
begin
r_Bit_Index <= 0;
r_SM_Main <= s_TX_STOP_BIT;
end
end
end // case: s_TX_DATA_BITS
// Send out Stop bit. Stop bit = 1
s_TX_STOP_BIT :
begin
o_Tx_Serial <= 1'b1;
// Wait CLKS_PER_BIT-1 clock cycles for Stop bit to finish
if (r_Clock_Count < CLKS_PER_BIT-1)
begin
r_Clock_Count <= r_Clock_Count + 1;
r_SM_Main <= s_TX_STOP_BIT;
end
else
begin
r_Tx_Done <= 1'b1;
r_Clock_Count <= 0;
r_SM_Main <= s_CLEANUP;
r_Tx_Active <= 1'b0;
end
end // case: s_Tx_STOP_BIT
// Stay here 1 clock
s_CLEANUP :
begin
r_Tx_Done <= 1'b1;
r_SM_Main <= s_IDLE;
end
default :
r_SM_Main <= s_IDLE;
endcase
end
assign o_Tx_Active = r_Tx_Active;
assign o_Tx_Done = r_Tx_Done;
endmodule
Test Bench
#(c_BIT_PERIOD);
#1000;
// Send Data Byte
for (ii=0; ii<8; ii=ii+1)
begin
r_Rx_Serial <= i_Data[ii];
#(c_BIT_PERIOD);
end
// Send Stop Bit
r_Rx_Serial <= 1'b1;
#(c_BIT_PERIOD);
end
endtask // UART_WRITE_BYTE*/
uart_rx #(.CLKS_PER_BIT(c_CLKS_PER_BIT)) UART_RX_INST
(.i_Clock(r_Clock),.i_Rx_Serial(v),.o_Rx_DV(),.o_Rx_Byte(w_Rx_Byte));
uart_tx #(.CLKS_PER_BIT(c_CLKS_PER_BIT)) UART_TX_INST
(.i_Clock(r_Clock),.i_Tx_DV(r_Tx_DV),.i_Tx_Byte(r_Tx_Byte),.o_Tx_Active(),.o_Tx_Serial(v),.o_Tx_Done(w_Tx_Do
ne));
always#(c_CLOCK_PERIOD_NS/2) r_Clock <= !r_Clock;
// Main Testing:
initial
begin
// Tell UART to send a command (exercise Tx)
@(posedge r_Clock);
@(posedge r_Clock);
r_Tx_DV <= 1'b1;
r_Tx_Byte <= 8'hAB;
@(posedge r_Clock);
r_Tx_DV <= 1'b0;
@(posedge w_Tx_Done);
// Send a command to the UART (exercise Rx)
//@(posedge r_Clock);
//UART_WRITE_BYTE(8'h3F);
@(posedge r_Clock);
// Check that the correct command was received
if (w_Rx_Byte == 8'hAB)
$display("Test Passed - Correct Byte Received");
else
$display("Test Failed - Incorrect Byte Received");
end
endmodule
Expected Waveforms
Result:
EXPERIMENT NO.6
BOOTH MULTIPLICATION(RADIX-4) AND SIMULATION
Aim: Design an Booth Multiplication (Radix-4) in the behavioral modeling styles using Verilog
Program
module booth_mul( m,n,reset,clk,result);
input [4:0] m,n;
input reset;
input clk;
output [8:0] result;
reg [8:0] result;
wire [9:0]a,s,p;
wire [4:0]cm;
wire [9:0] p1,p2;
reg [2:0] count;
reg [9:0] reg_p;
reg [9:0] reg_a;
reg [9:0] reg_s;
assign cm= ~m+1;
assign a={m,5'b00000};
assign s={cm,5'b00000};
assign p={4'b0000,n,1'b0};
assign p1=(reg_p+reg_a);
assign p2=(reg_p+reg_s);
always @(posedge clk or posedge reset)
begin
if(reset)
begin
reg_p <=0;
count <=0;
reg_a <= 0;
reg_s <= 0;
result<=0;
end
else if(count == 0)
begin
reg_p <= p;
count <= count + 1;
reg_a <= a;
Dept. of ECE, AMCEC Page 36
VLSI Lab Manual
reg_s <= s;
end
else if(count>0 && count<=4)
case (reg_p[1:0])
0:
begin
reg_p <={reg_p[9],reg_p[9:1]};
count <=count+1;
end
1:
begin
reg_p <={p1[9],p1[9:1]};
count <=count+1;
end
2:
begin
reg_p <={p2[9],p2[9:1]};
count<=count+1;
end
3: begin
reg_p <={reg_p[9],reg_p[9:1]};
count <=count+1;
end
default:reg_p<=reg_p;
endcase
else
begin
count <= 0;
result <= reg_p[9]?(reg_p[9:1]-1):reg_p[9:1];
end
end
endmodule
Test Bench
module boothmul_test_4bit;
reg [4:0]a,b;
reg clk,reset;
wire [8:0]result;
booth_mul d1(a,b,reset,clk,result);
always
#5 clk=~clk;
initial
begin
clk = 0;
reset = 1;
a =0;
b = 0;
#40 reset=1'b0;
#50 a=5'b01011; b=5'b11101;
#120 a=5'b00100; b=5'b00010;
#120 reset=1'b0;
#120 a=5'b01010; b=5'b00000;
#120 a=5'b01010; b=5'b11010;
#120 a=5'b00110; b=5'b11011;
#100
$stop;
$finish;
end
endmodule
RESULT