Professional Documents
Culture Documents
Verilog Basic Concepts
Verilog Basic Concepts
Today program
Lexical Conventions
Data Types
Digital System Design System Tasks and Compiler Directives
Verilog® HDL
Basic Concepts
Verilog HDL 2
1
08-03-2018
Verilog HDL 11
2
08-03-2018
Registers Vectors
Registers represent data storage elements Net and register data types can be declared as
Retain value until next assignment vectors (multiple bit widths)
NOTE: this is not a hardware register or flipflop
Syntax:
Keyword: reg
wire/reg [msb_index : lsb_index] data_id;
Default value: x
Example: Example
reg reset; wire a;
initial wire [7:0] bus;
begin
wire [31:0] busA, busB, busC;
reset = 1’b1;
#100 reset=1’b0; reg clock;
end reg [0:40] virtual_addr;
Verilog HDL 17 Verilog HDL 18
3
08-03-2018
Arrays Memories
Only one-dimensional arrays supported RAM, ROM, and register-files used many times in digital
Allowed for reg, integer, time systems
Not allowed for real data type
Syntax: Memory = array of registers in Verilog
<data_type> <var_name>[start_idx : end_idx]; Word = an element of the array
Examples:
Can be one or more bits
integer count[0:7];
reg bool[31:0]; Examples:
time chk_point[1:100]; reg membit[0:1023];
reg [4:0] port_id[0:7];
reg [7:0] membyte[0:1023];
integer matrix[4:0][4:0]; // illegal
membyte[511]
count[5] Note the difference (as in arrays):
chk_point[100]
reg membit[0:127];
port_id[3]
Note the difference between vectors and arrays reg [0:127] register;
Verilog HDL 23 Verilog HDL 24
4
08-03-2018
Parameters Strings
Similar to const in C Strings are stored in reg variables.
But can be overridden for each module at compile-time 8-bits required per character
Syntax: The string is stored from the least-significant part to the
parameter <const_id>=<value>; most-significant part of the reg variable
Example:
Gives flexibility reg [8*18:1] string_value;
Allows to customize the module initial
Example: string_value = “Hello World!”;
parameter port_id=5; Escaped characters
parameter cache_line_width=256; \n: newline \t: tab
parameter bus_width=8; %%: % \\: \
wire [bus_width-1:0] bus; \”: “ \ooo: character number in octal
Verilog HDL 25 Verilog HDL 26
System Tasks
Verilog HDL 28
5
08-03-2018
6
08-03-2018
What we learned
Verilog HDL 37