Difference between revisions of "Verilog"
(New page: ==Literals== '''Base Symbol Legal Values''' binary b or B 0, 1, x, X, z, Z, ?, _ octal o or O 0-7, x, X, z, Z, ?, _ decimal d or D 0-9, _ hexad...) |
|||
Line 1: | Line 1: | ||
+ | ==Replication {n{}}== | ||
+ | my_bus = {4{2'b01}} = 8'b01010101 | ||
+ | |||
+ | ==Concatenation {,}== | ||
+ | my_bus = {2'b01, 4'hF, 1'b1, 1'b0} = 8'b01111110 | ||
+ | |||
==Literals== | ==Literals== | ||
'''Base Symbol Legal Values''' | '''Base Symbol Legal Values''' | ||
Line 27: | Line 33: | ||
where each statement is a procedural assignment line terminated by a semicolon. | where each statement is a procedural assignment line terminated by a semicolon. | ||
+ | ==Testbench== | ||
+ | reg clk; | ||
+ | |||
+ | initial // clock generation | ||
+ | begin | ||
+ | clk = 0; | ||
+ | forever #10 clk = ~clk; | ||
+ | end | ||
+ | |||
+ | initial | ||
+ | begin | ||
+ | @(posedge clk); | ||
+ | while(value==0) @(posedge clk); | ||
+ | repeat(100) @(posedge clk); | ||
+ | |||
+ | $stop; | ||
+ | $finish; | ||
+ | end | ||
[[Category:Computing]] | [[Category:Computing]] |
Revision as of 19:37, 6 February 2007
Replication {n{}}
my_bus = {4{2'b01}} = 8'b01010101
Concatenation {,}
my_bus = {2'b01, 4'hF, 1'b1, 1'b0} = 8'b01111110
Literals
Base Symbol Legal Values binary b or B 0, 1, x, X, z, Z, ?, _ octal o or O 0-7, x, X, z, Z, ?, _ decimal d or D 0-9, _ hexadecimal h or H 0-9, a-f, A-F, x, X, z, Z, ?, _
Arrays
reg [3:0] mem_array [31:0];
The above describes an array of 32 Elements each, 4 bits wide which can be assigned via behavioral verilog code.
Blocks
Block statements are used to group statements together. XST only supports sequential blocks. Within these blocks, the statements are executed in the order listed. Parallel blocks are not supported by XST. Block statements are designated by begin and end keywords, and are discussed within examples later in this chapter.
Modules
In Verilog a design component is represented by a module. The connections between components are specified within module instantiation statements. Such a statement specifies an instance of a module. Each module instantiation statement must be given a name (instance name). In addition to the name, a module instantiation statement contains an association list that specifies which actual nets or ports are associated with which local ports (formals) of the module declaration.
All procedural statements occur in blocks that are defined inside modules. There are two kinds of procedural blocks: the initial block and the always block. Within each block, Verilog uses a begin and end to enclose the statements. Since initial blocks are ignored during synthesis, only always blocks are discussed. Always blocks usually take the following format:
always begin statement ... end
where each statement is a procedural assignment line terminated by a semicolon.
Testbench
reg clk; initial // clock generation begin clk = 0; forever #10 clk = ~clk; end initial begin @(posedge clk); while(value==0) @(posedge clk); repeat(100) @(posedge clk); $stop; $finish; end