Saturday, September 10, 2016

DATA TYPES

Value Set 


The Verilog HDL value set consists of four basic values:
0 - represents a logic zero, or a false condition
1 - represents a logic one, or a true condition
x - represents an unknown logic value
z - represents a high-impedance state
The values 0 and 1 are logical complements of one another.


Net 


The net data types shall represent physical connections between structural entities, such as gates. A net shall not store a value (except for the trireg net). Instead, its value shall be determined by the values of its drivers,  such as a continuous assignment or a gate. If no driver is connected to a net, its value shall be high-impedance (z) unless the net is a trireg, in which case it shall hold the previously driven value. It is illegal to redeclare a name already declared by a net, parameter, or variable declaration.


Variable Or Reg 


A variable is an abstraction of a data storage element. A variable shall store a value from one assignment to the next. An assignment statement in a procedure acts as a trigger that changes the value in the data storage element. The initialization value for reg, time, and integer data types shall be the unknown value, x. The default initialization value for real and realtime variable datatypes shall be 0.0. If a variable declaration assignment is used , the variable shall take this value as if the assignment occurred in a blocking assignment in an initial construct. It is illegal to redeclare a name already declared by a net, parameter, or variable declaration.


Vectors 


A net or reg declaration without a range specification shall be considered 1 bit wide and is known as a scalar. Multiple bit net and reg data types shall be declared by specifying a range, which is known as a vector.


EXAMPLES:
wand w; // a scalar net of type wand
tri [15:0] busa; // a three-state 16-bit bus
trireg (small) storeit; // a charge storage node of strength small
reg a; // a scalar reg
reg[3:0] v; // a 4-bit vector reg made up of (from most to
// least significant) v[3], v[2], v[1], and v[0]
reg signed [3:0] signed_reg; // a 4-bit vector in range -8 to 7
reg [-1:4] b; // a 6-bit vector reg
wire w1, w2; // declares two wires
reg [4:0] x, y, z; // declares three 5-bit regs

Memories 

A one dimensional array with elements of type reg is also called a memory. These memories can be used to model read-only memories (ROMs), random access memories (RAMs), and reg files. Each reg in the array is known as an element or word and is addressed by a single array index. An n-bit reg can be assigned a value in a single assignment, but a complete memory cannot. To assign a value to a memory word, an index shall be specified. The index can be an expression. This option provides a mechanism to reference different memory words, depending on the value of other variables and nets in the circuit. For example, a program counter reg could be used to index into a RAM.


EXAMPLE:
reg [7:0] mema[0:255]; // declares a memory mema of 256 8-bit
// registers. The indices are 0 to 255
reg arrayb[7:0][0:255]; // declare a two dimensional array of
// one bit registers
wire w_array[7:0][5:0]; // declare array of wires
integer inta[1:64]; // an array of 64 integer values
time chng_hist[1:1000] // an array of 1000 time values

mema = 0; // Illegal syntax- Attempt to write to entire array
arrayb[1] = 0; // Illegal Syntax - Attempt to write to elements
// [1][0]..[1][255]
arrayb[1][12:31] = 0; // Illegal Syntax - Attempt to write to
// elements [1][12]..[1][31]
mema[1] = 0; //Assigns 0 to the second element of mema
arrayb[1][0] = 0; // Assigns 0 to the bit referenced by indices
// [1][0]
inta[4] = 33559; // Assign decimal number to integer in array
chng_hist[t_index] = $time; // Assign current simulation time to
// element addressed by integer index

reg [1:n] rega; // An n-bit register is not the same
reg mema [1:n]; // as a memory of n 1-bit registers

Net Types 


There are several distinct types of nets , they are

wire , tri , tri0 , supply0 , wand, triand, tri1, supply1, wor, trior, trireg.

SYNTAX

omments : Verilog comments are the same as in C++. Use // for a single line comment or /*  */ for a multiline comment.

Punctuation : white spaces are ignored in Verilog. A semicolon is used to indicate the end of a command line and commas are typically used to separate elements in a list. Like C++, Verilog is case sensitive.

Identifiers : An identifier is usually a variable. You can use any letter, digit, the underscore, or $. Identifiers may not begin with a digit and may not be the same as a Verilog key word. As in C++ variable names should be chosen to assist in documentation.

Signal values : signals in Verilog have one of four values. These are 0 (logic 0), 1 (logic 1), ?, X, or x ( don<92>t care or unknown), and Z or z for high impedance tri-state.

Parameters : a parameter in Verilog can be any Verilog constant. Parameters are used to generalize a design. For example a 4-bit adder becomes more useful as a design if it is put together as an n-bit adder where n is a parameter specified by the user before compilation. Parameter declarations are done immediately after the module declaration. Here are some typical parameter examples:

EXAMPLE:
parameter n = 12;
parameter [3:0]p1 = 4'b1011;
parameter n = 12, m = 32;

Memory : Verilog allows for two dimensional arrays which typically get used for memory spaces. For example reg[7:0] m[63:0]; declares m to be a two-dimensional array consisting of 64 eight-bit words. You can access any word as m[2] for example but you do not get access to the bits in the word unless you copy the word to another 8-bit reg variable.

Strings : Strings are delimited by " ... ", and cannot be on multiple lines.

        "hello world";   // legal string

Number  :  Numbers in verilog are in the following format. 
The size is always specified as a decimal number. If no is specified then the default size is at least 32bits and may be larger depending on the machine. Valid base formats are 'b , 'B , 'h , 'H 'd , 'D , 'o , 'O for binary, hexadecimal, decimal, and octal. Numbers consist of strings of digits (0-9, A-F, a-f, x, X, z, Z). The X's mean unknown, and the Z's mean high impedance If no base format is specified the number is assumed to be a decimal number. Some examples of valid numbers are:


EXAMPLE: Unsized constant numbers
659 // is a decimal number
'h 837FF // is a hexadecimal number
'o7460 // is an octal number
4af // is illegal (hexadecimal format requires <92>h)


EXAMPLE: Sized constant numbers
4'b1001 // is a 4-bit binary number
5'D 3 // is a 5-bit decimal number
3'b01x // is a 3-bit number with the least
// significant bit unknown
12'hx // is a 12-bit unknown number
16'hz // is a 16-bit high-impedance number



EXAMPLE: Using sign with constant numbers

8'd -6 // this is illegal syntax
-8'd 6 // this defines the two<92>s complement of 6,
// held in 8 bits<97>equivalent to -(8<92>d 6)
4'hf // this denotes the 4-bit number <91>1111<92>, to
// be interpreted as a 2<92>s complement number,
// or <91>-1<92>. This is equivalent to -4<92>h 1
-4'sd15 // this is equivalent to -(-4<92>d 1), or <91>0001<92>.

EXAMPLE: Automatic left padding

reg [11:0] a, b, c, d;
initial begin
= 'h x; // yields xxx
= 'h 3x; // yields 03x
= 'h z3; // yields zz3
= 'h 0z3; // yields 0z3
end
reg [84:0] e, f, g;
= 'h5; // yields {82{1'b0},3'b101}
= 'hx; // yields {85{1'hx}}
= 'hz; // yields {85{1'hz}}

EXAMPLE: Using underscore character in numbers

27_195_000
16'b0011_0101_0001_1111
32'h 12ab_f001

EXAMPLE: Real constants

1.2
0.1
2394.26331
1.2E12 (the exponent symbol can be e or E)
1.30e-2
0.1e-0
23E10
29E-2
236.123_763_e-12 (underscores are ignored)