SlideShare a Scribd company logo
Verilog
Introduction
• Verilog HDL originated in 1983 at Gateway Design Automation.
• HDL are popular for logic verification
• Designers manually translate the HDL-based design into a schematic circuit with
interconnections between gates
• Digital circuits could be described at a register transfer level (RTL) by use of an HDL.
• The details of gates and their interconnections to implement the circuit were
automatically extracted by logic synthesis tools from the RTL description.
• Verilog standardized as IEEE 1364
• HDLs also began to be used for system-level design - ASIC / FPGA
VLSI Design Flow
Specifications functionality, interface, and
overall architecture of the digital circuit
behavioral description analyze the design in
terms of functionality performance, compliance
to standards and other high-level issues
behavioral description is manually converted
to an RTL description in an HDL
Design Methodologies
define the top-level block and identify the sub-blocks necessary to build the top-
level block.
We further subdivide the sub-blocks until we come to leaf cells
which are the cells that cannot further be divided
Top-down Design Methodology
Bottom-up Design Methodology
first identify the building blocks that are available to us.
We build bigger cells, using these building blocks.
These cells are then used for higher-level blocks until we build the top-level block in the
design
Typically, a combination of top-down and bottom-up flows is used
Modules
• A module is the basic building block in Verilog.
• A module can be an element or a collection of lower-level design blocks.
• Typically, elements are grouped into modules to provide common functionality
that is used at many places in the design.
• A module provides the necessary functionality to the higher-level block through its
port interface (inputs and outputs)
module can be defined at four levels of abstraction
1. Behavioral or algorithmic level
• This is the highest level of abstraction provided by Verilog HDL.
• A module can be implemented in terms of the desired design algorithm without
concern for the hardware implementation details
2. Dataflow level
• module is designed by specifying the data flow.
• The designer is aware of how data flows between hardware registers
3. Gate level
• module is implemented in terms of logic gates and interconnections between
these gates
4. Switch level
• This is the lowest level of abstraction provided by Verilog.
• A module can be implemented in terms of switches, storage nodes, and the
interconnections between them.
Instances
A module provides a template from which you can create actual objects.
When a module is invoked, Verilog creates a unique object from the template.
Each object has its own name, variables, parameters, and I/O interface.
The process of creating objects from a module template is called instantiation, and the
objects are called instances
Lexical Conventions
Whitespace Blank spaces (b)
tabs (t)
newlines (n)
Comments one-line comment starts with "//“
multiple-line comment starts with "/*" and ends with "*/“
Operators
Number Specification
Sized numbers <size> '<base format> <number>
<size> in decimal and specifies the number of bits in the number.
<base format> are decimal ('d or 'D), hexadecimal ('h or 'H), binary ('b or 'B) and octal ('o or 'O).
<number> specified as consecutive digits from 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f
Unsized numbers
without a <base format> specification are decimal numbersby default.
Numbers that are written without a <size> specification have a default number of bits that is
simulator- and machine-specific (must be at least 32).
Negative numbers
minus sign before the size for a constant number.
Strings
• sequence of characters that are enclosed by double quotes.
• string is that it must be contained on a single line
• It cannot be on multiple lines.
Nets
Nets represent connections between hardware elements.
Nets are declared primarily with the keyword wire.
Nets are one-bit values by default
The default value of a net is z
Nets get the output value of their drivers. If a net has no driver, it gets the value z.
Registers
• Registers represent data storage elements.
• Registers retain value until another value is placed onto them.
reg  variable that can hold a value.
• default value for a reg data type is x
Vectors
Nets or reg data types can be declared as vectors (multiple bit widths).
If bit width is not specified, the default is scalar (1-bit).
[high# : low#] or [low# : high#]
left number in the squared brackets is always the MSB of the vector
Vector Part Select
Arrays array is a collection of variables
Arrays are accessed by <array_name>[<subscript>]
Integer
integer is a general purpose register data type used for manipulating quantities.
The default width for an integer is the host-machine word size 32 bits
integer counter; // general purpose variable used as a counter.
initial
counter = -1;
Time
time register data type is used in Verilog to store simulation time.
system function $time is invoked to get the current simulation time.
time save_sim_time; // Define a time variable save_sim_time
initial
save_sim_time = $time; // Save the current simulation time
Parameters
constants to be defined in a module by the keyword parameter
parameter port_id = 5;
System Tasks $<keyword>
system tasks for certain routine operations
$display is system task for displaying values of variables or strings or expressions.
$monitor task monitor a signal when its value changes
continuously monitors the values of the variables or signals specified in the parameter list
displays all parameters in the list whenever the value of any one variable or signal changes
$stop designer wants to suspend the simulation and examine the values of signals in the design.
$finish task terminates the simulation
Example
Verilog
module stimulus;
reg clk;
reg reset;
wire[3:0] q;
ripple_carry_counter r1(q, clk, reset);
initial
clk = 1'b0;
always
#5 clk = ~clk;
initial
begin
reset = 1'b1;
#15 reset = 1'b0;
#180 reset = 1'b1;
#10 reset = 1'b0;
#20 $finish;
End
initial
$monitor($time, " Output q = %d", q);
endmodule
Verilog Program
module orgate(out, a, b, c, d);
input a, b, c, d;
wire x, y; output out;
or or1(x, a, b);
or or2(y, c, d);
or or3(out, x, y);
endmodule
four input OR gate
module example_2_bl(out, a, b, c, d);
input a, b, c, d;
output out;
wire x, y;
and gate_1(x, a, b);
or gate_2(y, c, d);
xor gate_3(out, x, y);
endmodule
module example_3_bl(out, i0, i1, i2, i3, s1, s0);
input i0, i1, i2, i3, s1, s0;
output out;
wire y0, y1, y2, y3, s1n, s0n;
not n1(s1n, s1);
not n2(s0n, s0);
and alpha(y0, i0, s1n, s0n);
and beta(y1, i1, s1n, s0);
and gamma(y2, i2, s1, s0n);
and terra(y3, i3, s1, s0);
or out2(out, y0, y1, y2, y3);
endmodule
4×1 Multiplexer using gate level Modeling
Full Adder in Gate Level
module fa(s,co,a,b,ci);
output s,co;
input a,b,ci;
Wire n1,n2,n2;
xor1 u1(s,a,b,ci);
and1 u2(n1,a,b);
and1 u3(n2,b,ci);
and1 u4(n3,a,ci);
or1 u5(co,n1,n2,n3);
endmodule
module full_adder(x,y,cin,s,cout);
input x,y,cin;
output s,cout;
wire s1,c1,c2;
half_adder ha1(x,y,s1,c1);
half_adder ha2(cin,s1,s,c2);
or(cout,c1,c2); endmodule
module half_adder(x,y,s,c);
input x,y;
output s,c;
Xor x1(s,x,y);
And a1(c,x,y);
endmodule
Subtractor
4:1 mux using 2:1 mux
2:4 Decoder
module dec24_str(
output [3:0] y,
input [1:0] a,
input en);
and (y[0], ~a[1], ~a[0], en);
and (y[1], ~a[1], a[0], en);
and (y[2], a[1], ~a[0], en);
and (y[3], a[1], a[0], en);
endmodule
module dec2_4 (a,b,en,y0,y1,y2,y3)
input a, b, en;
output y0,y1,y2,y3;
assign y0= (~a) & (~b) & en;
assign y1= (~a) & b & en;
assign y2= a & (~ b) & en;
assign y3= a & b & en;
end module
3:8 Decoder using 2:4
Decoder
Full Adder using 3:8 Decoder
4:16 Decoder using 2:4 Decoder
module dec4x16_str(a,en,y);
output [15:0] y,
input [3:0] a,
input en;
wire [3:0] w;
dec2x4_str u0(w, a[3:2], en);
dec2x4_str u1(y[3:0], a[1:0], w[0]);
dec2x4_str u2(y[7:4], a[1:0], w[1]);
dec2x4_str u3(y[11:8], a[1:0], w[2]);
dec2x4_str u4(y[15:12], a[1:0], w[3]);
endmodule
4 bit Ripple Carry Adder
module four_bit_adder(x,y,cin,sum,cout);
input [3:0] x,y;
input cin;
output[3:0] sum;
output cout;
wire c1,c2,c3;
full_adder fa1(x[0],y[0],cin,sum[0],c1);
full_adder fa2(x[1],y[1],c1,sum[1],c2);
full_adder fa3(x[2],y[2],c2,sum[2],c3);
full_adder fa4(x[3],y[3],c3,sum[3],cout);
endmodule
Carry Look ahead Adder
Similar to Ripple carry Adder It is used to add together two binary numbers; carry look ahead
adders are able to calculate the Carry bit before the Full Adder is done with its operation.
This gives it an advantage over the Ripple Carry Adder because it is able to add two numbers
together faster. The drawback is that it takes more logic
C1 = C0P0 + G0
C2 = C1P1 + G1 = (C0P0+G0)P1 + G1 = C0P0P1 + P1G0 + G1
C3 = C2P2 +G2 = (C0P0P1 + P1G0 + G1)P2+G2 = C0P0P1P2 + P2P1G0 + P2G1 + G2
C4 = C3P3 +G3 = (C0P0P1P2 + P2P1G0 + P2G1 + G2)P3 + G3 = C0P0P1P2P3 + P3P2P1G0 +
P3P2G1 + G2P3 + G3
Pi = Ai xor Bi
Gi = Ai.Bi
Si = Pi xor Ci
Ci+1 = Ci.Pi + Gi
CLA
Carry Save Adder module fulladder( a,b,cin,sum,carry);
input a,b,cin;
output sum,carry;
assign sum = a ^ b ^ cin;
assign carry = (a & b) | (cin & b) | (a & cin);
endmodule
module CSA ( x,y,z,s,cout);
input [3:0] x,y,z;
output [4:0] s;
output cout;
wire [3:0] c1,s1,c2;
fulladder fa_inst10(x[0],y[0],z[0],s1[0],c1[0]);
fulladder fa_inst11(x[1],y[1],z[1],s1[1],c1[1]);
fulladder fa_inst12(x[2],y[2],z[2],s1[2],c1[2]);
fulladder fa_inst13(x[3],y[3],z[3],s1[3],c1[3]);
fulladder fa_inst20(s1[1],c1[0],1'b0,s[1],c2[1]);
fulladder fa_inst21(s1[2],c1[1],c2[1],s[2],c2[2]);
fulladder fa_inst22(s1[3],c1[2],c2[2],s[3],c2[3]);
fulladder fa_inst23(1'b0,c1[3],c2[3],s[4],cout);
assign s[0] = s1[0];
endmodule

More Related Content

PPTX
Verilog
PPTX
Verilog data types -For beginners
PPT
Switch level modeling
PDF
Logic Synthesis
PDF
Day2 Verilog HDL Basic
PDF
Router 1X3 – RTL Design and Verification
PPTX
Vlsi physical design (Back End Process)
PPT
Verilog Tasks and functions
Verilog
Verilog data types -For beginners
Switch level modeling
Logic Synthesis
Day2 Verilog HDL Basic
Router 1X3 – RTL Design and Verification
Vlsi physical design (Back End Process)
Verilog Tasks and functions

What's hot (20)

PPTX
Verilog Tutorial - Verilog HDL Tutorial with Examples
PPTX
PPTX
System verilog assertions
PPTX
VERILOG HDL :: Blocking & NON- Blocking assignments
PPTX
System verilog coverage
PPTX
ODP
APB protocol v1.0
DOCX
Switch level modeling 2 x4
PDF
System verilog important
PPTX
8251 USART
PDF
Fault Simulation (Testing of VLSI Design)
PDF
Basic concepts in Verilog HDL
PDF
Data types in verilog
PPTX
Introduction to System verilog
PPT
Verilog tutorial
PPTX
8051 MICROCONTROLLER ARCHITECTURE.pptx
PPTX
I2c protocol - Inter–Integrated Circuit Communication Protocol
PPTX
I/O port programming in 8051
PPT
VHDL Part 4
PPTX
Complete ASIC design flow - VLSI UNIVERSE
Verilog Tutorial - Verilog HDL Tutorial with Examples
System verilog assertions
VERILOG HDL :: Blocking & NON- Blocking assignments
System verilog coverage
APB protocol v1.0
Switch level modeling 2 x4
System verilog important
8251 USART
Fault Simulation (Testing of VLSI Design)
Basic concepts in Verilog HDL
Data types in verilog
Introduction to System verilog
Verilog tutorial
8051 MICROCONTROLLER ARCHITECTURE.pptx
I2c protocol - Inter–Integrated Circuit Communication Protocol
I/O port programming in 8051
VHDL Part 4
Complete ASIC design flow - VLSI UNIVERSE
Ad

Similar to Verilog (20)

PPTX
a verilog presentation for deep concept understa
PPTX
Experiment 1- UCS 704_ESD engineering money waste
PDF
SKEL 4273 CAD with HDL Topic 2
PPT
VIT_Workshop.ppt
DOCX
15CS202-unitV.docx HDL CODE FOR II/IV JNTU GV
DOCX
HDL CODE FOR II/IV B.TECH STUDENTS JNTU GV
PPTX
INTERN VLSI 1.pptx INTERN VLSI 1.pptx ppt
PDF
An Overview of SystemVerilog for Design and Verification
PPTX
Concept of a ‘module’ in verilog coding
PPTX
Verilog Final Probe'22.pptx
PPTX
HDL_verilog_unit_1 for engagement subjects and technology
PDF
Short Notes on Verilog and SystemVerilog
PPTX
systemverilog and veriog presentation
PPTX
Verilog presentation final
PPTX
vlsi design using verilog presentaion 1
PDF
Verilog HDL
PPTX
very large scale integration ppt vlsi.pptx
PDF
Lecture03-Modelling-Structuresqweqweqwe.pdf
PDF
Lecture03(DHDN)-Modelling-Structures.pdf
a verilog presentation for deep concept understa
Experiment 1- UCS 704_ESD engineering money waste
SKEL 4273 CAD with HDL Topic 2
VIT_Workshop.ppt
15CS202-unitV.docx HDL CODE FOR II/IV JNTU GV
HDL CODE FOR II/IV B.TECH STUDENTS JNTU GV
INTERN VLSI 1.pptx INTERN VLSI 1.pptx ppt
An Overview of SystemVerilog for Design and Verification
Concept of a ‘module’ in verilog coding
Verilog Final Probe'22.pptx
HDL_verilog_unit_1 for engagement subjects and technology
Short Notes on Verilog and SystemVerilog
systemverilog and veriog presentation
Verilog presentation final
vlsi design using verilog presentaion 1
Verilog HDL
very large scale integration ppt vlsi.pptx
Lecture03-Modelling-Structuresqweqweqwe.pdf
Lecture03(DHDN)-Modelling-Structures.pdf
Ad

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
RMMM.pdf make it easy to upload and study
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Complications of Minimal Access Surgery at WLH
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Institutional Correction lecture only . . .
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Cell Types and Its function , kingdom of life
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Pre independence Education in Inndia.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Pharma ospi slides which help in ospi learning
RMMM.pdf make it easy to upload and study
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Complications of Minimal Access Surgery at WLH
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Institutional Correction lecture only . . .
102 student loan defaulters named and shamed – Is someone you know on the list?
Cell Types and Its function , kingdom of life
O7-L3 Supply Chain Operations - ICLT Program
Pre independence Education in Inndia.pdf
human mycosis Human fungal infections are called human mycosis..pptx
VCE English Exam - Section C Student Revision Booklet
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O5-L3 Freight Transport Ops (International) V1.pdf

Verilog

  • 2. Introduction • Verilog HDL originated in 1983 at Gateway Design Automation. • HDL are popular for logic verification • Designers manually translate the HDL-based design into a schematic circuit with interconnections between gates • Digital circuits could be described at a register transfer level (RTL) by use of an HDL. • The details of gates and their interconnections to implement the circuit were automatically extracted by logic synthesis tools from the RTL description. • Verilog standardized as IEEE 1364 • HDLs also began to be used for system-level design - ASIC / FPGA
  • 3. VLSI Design Flow Specifications functionality, interface, and overall architecture of the digital circuit behavioral description analyze the design in terms of functionality performance, compliance to standards and other high-level issues behavioral description is manually converted to an RTL description in an HDL
  • 4. Design Methodologies define the top-level block and identify the sub-blocks necessary to build the top- level block. We further subdivide the sub-blocks until we come to leaf cells which are the cells that cannot further be divided Top-down Design Methodology
  • 5. Bottom-up Design Methodology first identify the building blocks that are available to us. We build bigger cells, using these building blocks. These cells are then used for higher-level blocks until we build the top-level block in the design Typically, a combination of top-down and bottom-up flows is used
  • 6. Modules • A module is the basic building block in Verilog. • A module can be an element or a collection of lower-level design blocks. • Typically, elements are grouped into modules to provide common functionality that is used at many places in the design. • A module provides the necessary functionality to the higher-level block through its port interface (inputs and outputs)
  • 7. module can be defined at four levels of abstraction 1. Behavioral or algorithmic level • This is the highest level of abstraction provided by Verilog HDL. • A module can be implemented in terms of the desired design algorithm without concern for the hardware implementation details 2. Dataflow level • module is designed by specifying the data flow. • The designer is aware of how data flows between hardware registers 3. Gate level • module is implemented in terms of logic gates and interconnections between these gates 4. Switch level • This is the lowest level of abstraction provided by Verilog. • A module can be implemented in terms of switches, storage nodes, and the interconnections between them.
  • 8. Instances A module provides a template from which you can create actual objects. When a module is invoked, Verilog creates a unique object from the template. Each object has its own name, variables, parameters, and I/O interface. The process of creating objects from a module template is called instantiation, and the objects are called instances
  • 9. Lexical Conventions Whitespace Blank spaces (b) tabs (t) newlines (n) Comments one-line comment starts with "//“ multiple-line comment starts with "/*" and ends with "*/“ Operators Number Specification Sized numbers <size> '<base format> <number> <size> in decimal and specifies the number of bits in the number. <base format> are decimal ('d or 'D), hexadecimal ('h or 'H), binary ('b or 'B) and octal ('o or 'O). <number> specified as consecutive digits from 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f
  • 10. Unsized numbers without a <base format> specification are decimal numbersby default. Numbers that are written without a <size> specification have a default number of bits that is simulator- and machine-specific (must be at least 32). Negative numbers minus sign before the size for a constant number.
  • 11. Strings • sequence of characters that are enclosed by double quotes. • string is that it must be contained on a single line • It cannot be on multiple lines. Nets Nets represent connections between hardware elements. Nets are declared primarily with the keyword wire. Nets are one-bit values by default The default value of a net is z Nets get the output value of their drivers. If a net has no driver, it gets the value z.
  • 12. Registers • Registers represent data storage elements. • Registers retain value until another value is placed onto them. reg  variable that can hold a value. • default value for a reg data type is x Vectors Nets or reg data types can be declared as vectors (multiple bit widths). If bit width is not specified, the default is scalar (1-bit). [high# : low#] or [low# : high#] left number in the squared brackets is always the MSB of the vector
  • 13. Vector Part Select Arrays array is a collection of variables Arrays are accessed by <array_name>[<subscript>]
  • 14. Integer integer is a general purpose register data type used for manipulating quantities. The default width for an integer is the host-machine word size 32 bits integer counter; // general purpose variable used as a counter. initial counter = -1; Time time register data type is used in Verilog to store simulation time. system function $time is invoked to get the current simulation time. time save_sim_time; // Define a time variable save_sim_time initial save_sim_time = $time; // Save the current simulation time Parameters constants to be defined in a module by the keyword parameter parameter port_id = 5;
  • 15. System Tasks $<keyword> system tasks for certain routine operations $display is system task for displaying values of variables or strings or expressions.
  • 16. $monitor task monitor a signal when its value changes continuously monitors the values of the variables or signals specified in the parameter list displays all parameters in the list whenever the value of any one variable or signal changes
  • 17. $stop designer wants to suspend the simulation and examine the values of signals in the design. $finish task terminates the simulation
  • 20. module stimulus; reg clk; reg reset; wire[3:0] q; ripple_carry_counter r1(q, clk, reset); initial clk = 1'b0; always #5 clk = ~clk; initial begin reset = 1'b1; #15 reset = 1'b0; #180 reset = 1'b1; #10 reset = 1'b0; #20 $finish; End initial $monitor($time, " Output q = %d", q); endmodule
  • 21. Verilog Program module orgate(out, a, b, c, d); input a, b, c, d; wire x, y; output out; or or1(x, a, b); or or2(y, c, d); or or3(out, x, y); endmodule four input OR gate
  • 22. module example_2_bl(out, a, b, c, d); input a, b, c, d; output out; wire x, y; and gate_1(x, a, b); or gate_2(y, c, d); xor gate_3(out, x, y); endmodule
  • 23. module example_3_bl(out, i0, i1, i2, i3, s1, s0); input i0, i1, i2, i3, s1, s0; output out; wire y0, y1, y2, y3, s1n, s0n; not n1(s1n, s1); not n2(s0n, s0); and alpha(y0, i0, s1n, s0n); and beta(y1, i1, s1n, s0); and gamma(y2, i2, s1, s0n); and terra(y3, i3, s1, s0); or out2(out, y0, y1, y2, y3); endmodule 4×1 Multiplexer using gate level Modeling
  • 24. Full Adder in Gate Level module fa(s,co,a,b,ci); output s,co; input a,b,ci; Wire n1,n2,n2; xor1 u1(s,a,b,ci); and1 u2(n1,a,b); and1 u3(n2,b,ci); and1 u4(n3,a,ci); or1 u5(co,n1,n2,n3); endmodule module full_adder(x,y,cin,s,cout); input x,y,cin; output s,cout; wire s1,c1,c2; half_adder ha1(x,y,s1,c1); half_adder ha2(cin,s1,s,c2); or(cout,c1,c2); endmodule module half_adder(x,y,s,c); input x,y; output s,c; Xor x1(s,x,y); And a1(c,x,y); endmodule
  • 26. 4:1 mux using 2:1 mux
  • 27. 2:4 Decoder module dec24_str( output [3:0] y, input [1:0] a, input en); and (y[0], ~a[1], ~a[0], en); and (y[1], ~a[1], a[0], en); and (y[2], a[1], ~a[0], en); and (y[3], a[1], a[0], en); endmodule module dec2_4 (a,b,en,y0,y1,y2,y3) input a, b, en; output y0,y1,y2,y3; assign y0= (~a) & (~b) & en; assign y1= (~a) & b & en; assign y2= a & (~ b) & en; assign y3= a & b & en; end module
  • 28. 3:8 Decoder using 2:4 Decoder Full Adder using 3:8 Decoder
  • 29. 4:16 Decoder using 2:4 Decoder module dec4x16_str(a,en,y); output [15:0] y, input [3:0] a, input en; wire [3:0] w; dec2x4_str u0(w, a[3:2], en); dec2x4_str u1(y[3:0], a[1:0], w[0]); dec2x4_str u2(y[7:4], a[1:0], w[1]); dec2x4_str u3(y[11:8], a[1:0], w[2]); dec2x4_str u4(y[15:12], a[1:0], w[3]); endmodule
  • 30. 4 bit Ripple Carry Adder module four_bit_adder(x,y,cin,sum,cout); input [3:0] x,y; input cin; output[3:0] sum; output cout; wire c1,c2,c3; full_adder fa1(x[0],y[0],cin,sum[0],c1); full_adder fa2(x[1],y[1],c1,sum[1],c2); full_adder fa3(x[2],y[2],c2,sum[2],c3); full_adder fa4(x[3],y[3],c3,sum[3],cout); endmodule
  • 31. Carry Look ahead Adder Similar to Ripple carry Adder It is used to add together two binary numbers; carry look ahead adders are able to calculate the Carry bit before the Full Adder is done with its operation. This gives it an advantage over the Ripple Carry Adder because it is able to add two numbers together faster. The drawback is that it takes more logic C1 = C0P0 + G0 C2 = C1P1 + G1 = (C0P0+G0)P1 + G1 = C0P0P1 + P1G0 + G1 C3 = C2P2 +G2 = (C0P0P1 + P1G0 + G1)P2+G2 = C0P0P1P2 + P2P1G0 + P2G1 + G2 C4 = C3P3 +G3 = (C0P0P1P2 + P2P1G0 + P2G1 + G2)P3 + G3 = C0P0P1P2P3 + P3P2P1G0 + P3P2G1 + G2P3 + G3 Pi = Ai xor Bi Gi = Ai.Bi Si = Pi xor Ci Ci+1 = Ci.Pi + Gi
  • 32. CLA
  • 33. Carry Save Adder module fulladder( a,b,cin,sum,carry); input a,b,cin; output sum,carry; assign sum = a ^ b ^ cin; assign carry = (a & b) | (cin & b) | (a & cin); endmodule module CSA ( x,y,z,s,cout); input [3:0] x,y,z; output [4:0] s; output cout; wire [3:0] c1,s1,c2; fulladder fa_inst10(x[0],y[0],z[0],s1[0],c1[0]); fulladder fa_inst11(x[1],y[1],z[1],s1[1],c1[1]); fulladder fa_inst12(x[2],y[2],z[2],s1[2],c1[2]); fulladder fa_inst13(x[3],y[3],z[3],s1[3],c1[3]); fulladder fa_inst20(s1[1],c1[0],1'b0,s[1],c2[1]); fulladder fa_inst21(s1[2],c1[1],c2[1],s[2],c2[2]); fulladder fa_inst22(s1[3],c1[2],c2[2],s[3],c2[3]); fulladder fa_inst23(1'b0,c1[3],c2[3],s[4],cout); assign s[0] = s1[0]; endmodule