VERILOG DATATYPES AND OPERATORS - SYNTAX - EXAMPLES

ElecDude ED | Friday, July 12, 2013 | 0 comments

DATATYPES:
          The datatype denotes the type of the data assigned & processed by the variable. But in Verilog it exactly specifies the output type, such as a storage or non-storage type.
          The different datatypes in verilog are as follows
NETS
wire
Establishes connectivity, with no logical behavior or functionality implied.  (within non-procedural statements only)
tri
Establishes connectivity, with no logical behavior or functionality implied. This type of net has the same functionality as wire, but is identified distinctively to indicate that it will be three-stated in hardware.
wand
A net that is connected to the output of multiple primitives. It models the hardware implementation of a wired-AND, e.g., open collector technology.
wor
A net that is connected to the output of multiple primitives. It models the hardware implementation of a wired-OR, e.g., emitter coupled logic.
supply0
A global net that is connected to the circuit ground.
supply1
A global net that is connected to the power supply.
tri0
A net that is connected to ground by a resistive pull-down connection.
tri1
A net that is connected to the power supply by a resistive pull-up connection.
trireg
A net that models the charge stored on a physical net.

REGISTERS
reg
Register variables are assigned values by procedural statements within an always or initial block. REG variables can only be output.

Register variables hold their value until an assignment statement changes them. The following are predefined register types: reg, integer (32 bit, 2s complement), real (double precision 64bit), realtime, and time (for time related functions).

MEMORIES
       Verilog does not have separate datatype for memory array. But can be used from other data type reg
SYNTAX:      reg  [word_size]   <variable>[array_size];

STRINGS
       Verilog does not have a distinct data type for strings. Instead, a string must be stored within a properly sized register by a procedural assignment statement. A properly sized reg (array) has 8 bits of storage for each character of the string that it is to hold.

SYNTAX:      reg [8*num_char-1: 0] string_holder;

CONSTANTS
A constant in Verilog is declared with the keyword parameter, which declares and as- signs value to the constant. The value of a constant may not be changed during simulation. Constant expressions may be used in the declaration of the value of a constant.
SYNTAX:     parameter <variable> = <value>;

EXAMPLES
wire out1;
"out1" is a wire that only outputs
reg out2;
 "out2" is a register; it stores and outputs a value
reg [7:0] out3;
"out3" is a 8-bit register
reg [15:0] out4[7:0];
 "out4" is a 8-bit register array from 0 to 7
 Scope of a variable:

          The same net type is not referenced exactly the same within module, task, function. The flow is as given in the figure,

 OPERATORS:
          Operators in Verilog are the same as they are in other programming languages. They take two values and compare (or otherwise operate on) them to yield a third result. The following table briefs the operator and its examples.
Operator
Argument
Result
Arithmetic
Pair of operands
Binary word
Bitwise
Pair of operands
Binary word
Reduction
Single operand
Bit
Logical
Pair of operands
Boolean value
Relational
Pair of operands
Boolean value
Shift
Single operand
Binary word
Conditional
Three operands
Expression

OPERATOR TYPE
OPERATOR SYMBOL
OPERATION PERFORMED
EXAMPLE


Arithmetic
*
Multiply
x= a*b

/
Division
x= a/b

+
Add
x= a+b

-
Subtract
x= a-b

%
Modulus
x= a%b

+
Unary plus
x= a+b

-
Unary minus
x= a-b

Logical
!
Logical negation
!a

&&
Logical and
a && b

||
Logical or
a || b

Relational
Greater than
a>b

Less than
a<b

>=
Greater than or equal
a>=b

<=
Less than or equal
a<=b

Equality
==
Equality
a == b

!=
inequality
a != b

===
CASE equality
a === b

(includes x,z in bit-by-bit basis)

!==
CASE inequality
a !== b

(includes x,z in bit-by-bit basis)

Reduction
~
Bitwise negation
x= ~a

~&
nand
~&a

|
or
x= |a

~|
nor
x= ~|a

^
xor
x= ^a

^~
xnor
x= ^~a

~^
xnor
x= ~^a

Shift
>> 
Right shift
x= a>> n

<< 
Left shift
x= a<< n

Concatenation
{ }
Concatenation
x= {a,b,n}

x={a[3:0],b,a[7:4]}

Conditional
?
conditional
x= a<b?1:0

 
OPERATOR PRECEDENCE
Sign complement
HIGHEST
Multiplication Division Modulus
|
|
|
|
|
|
V
Addition Subtraction
Shift
Relational
Reduction
Logical
Conditional
LOWEST
Click here to download this post in PDF.
If you have any queries regarding this, plz feel free to ask us through admin@elecdude.com.


Readers comments are encouraged.
This helps us to do much more better.
Thankyou.

Category: , ,

About GalleryBloggerTemplates.com:
GalleryBloggerTemplates.com is Free Blogger Templates Gallery. We provide Blogger templates for free. You can find about tutorials, blogger hacks, SEO optimization, tips and tricks here!

0 comments

Search Here...

Loading...

Labels

materials (37) VLSI (31) embedded (24) jobs (24) avr (20) Govtjob (19) NONGOVT (19) Verilog codes (14) circuit ideas (12) Ebook (9) elec softwares (7) vhdl (7) PPT (6) c (5) circuit lab (5) projects (5) General (4) RESULTS (4) avr studio (3) gate (3) placements (3) 8051 self learn (2) Android (2) DIY (2) ISRO (2) SERIAL COMMUNICATION USING AVR ATMEGA8 (2) electronics (2) microcontroller (2) 24Vdc 3A - Voltage regulator - circuit schematic diagram (1) 555 calculator (1) 7 SEGMENT VLSI CODE (1) 8051 programmer serial port (1) 8051 tutorial part1 (1) 8051 tutorial part2 (1) ALU VLSI CODE (1) ANSWER KEY FOR GATE 2012 -GATE 2012 ANSWER KEY (1) APPLICATION ENGINEER -TRAINEE - Corel Technologies (1) AVR SPI (1) About MAX7219 display driver (1) Administrative Officers (Scale-I) - NATIONAL INSURANCE COMPANY LIMITED - ONLINE Recruitment (1) BOOTH MULTIPLIER (1) GROUP DISCUSSION - TECHNIQUES & TIPS (1) GUIDE LINE FOR FRESH ENGINEERING STUDENTS (1) IMAGE FILE TO TEXT FILE CONVERSION MATLAB – TEXT FILE TO IMAGE FILE CONVERSION MATLAB EXAMPLE (1) IMAGE PROCESSING IN VERILOG - ADD IMAGES IN VERILOG - MATLAB XILINX MODELSIM (1) MODELSIM TUTORIAL – WORKING WITH TESTBENCH – GETTING STARTED (1) MatLab Programs - IMPULSE - STEP - SINE - COSINE -TRIANGULAR - SAWTOOTH - EXPONENTIAL SIGNALS GROWING DECAYING (1) Microchip (1) QUALITIES AND PERSONALITIES FOR GOOD PERSON & SOME EMPLOYEE AND GET HIRED (1) SPI Working Modes of Operation - Verilog Code - Applications - Advantages Disadvantages (1) SPI verilog code master code slave code testbench. (1) Simple CGPA Calculator for Engg Colleges Anna university (1) TRAFFIC LIGHT CONTROLLER VLSI CODE (1) TRANSISTOR CODES AND CHOOSING (1) Tanner tutorial P1 (1) UNIVERSAL SHIFT REG VHDL CODE (1) VCD Description - Export VCD in Xilinx Modelsim - Example (1) XILINX 13.2 TUTORIALS (SELF LEARNING MATERIAL ) (1) avr calculator (1) avr serial header (1) chat (1) vhdl image processing add image (1)