Verilog data types, constant and variable

4 basic data types: reg wire integer parameter

Constant:

1.number

Three ways to express a number

1<bit width><system of numeration><number> Example:8’b10101100   8’ha2

2<system of numeration><number> system uses default bit width which is defined by the system, but it is at least 32bit

3<number> default decimal

x and z value

x means uncertain value, z means high resistance (sometimes written as?).

Example: 4’b10x0 4bits binary and the second bit is unknown

              4’b101z 4bits binary and the first bit is high resistance

              12’dz 12bits decimal with high resistance

              12’d? 12bits decimal with high resistance

How to represent negative number

Only one way to express: example: -8’d5 5 in 2’s completion (8 bits in decimal)

Using underscore_ for better readability, but only between numbers

Example 10’b1010_1011_1111_1010

Using parameter to define constant

Format:

parameter constant name1 = expression, constant name2 = expression, … …, constant name n = expression

Note that RHS must be constant expression (numbers or parameters defined before)

Examples:

parameter msb = 7;

Parameter e = 25, f = 29;

Parameter r = 5.7;

Parameter byte_size = 8, byte_msb = byte_size-1;

Variable

Variable can be changed in the program; main variables are wire reg memory

Wire: The nets variables represent the physical connection between structural entities. These variables do not store values (except trireg); they have the value of their drivers which changes continuously by the driving circuit. Some net data types are wire, tri, wor, trior, wand, triand, tri0, tri1, supply0, supply1 and trireg. Wire is the most frequently used type.

Reg: The register variables are used in procedural blocks which store values from one assignment to the next. An assignment statement in a procedure acts as a trigger that changes the value of the data storage element. Some register data types are: reg, integer, time and real. reg is the most frequently used type. Reg is used for describing logic, integer for loop variables and calculations, real in system modules, and time and real-time for storing simulation times in test benches.

Memory: Memory is a collection of storage cells referenced under common name. These cells are given continuous memory location in the system. Here each cell is the basic storage unit of memory. A basic storage unit of memory is termed as to a unit which can store one bit data.

发表评论

邮箱地址不会被公开。 必填项已用*标注