Sintaxis Verilog
Sintaxis Verilog
Carlos A. Angulo J.
OPERATORS
▪ BITWISE ▪ LOGICAL
The operations are performed on each bit of the bus. All buses The following logical operators are used in conditional
(output and inputs) must have same size. TRUE/FALSE statements to specify the condition for the
~ // NOT: Invert a single-bit signal or each bit in a bus operation.
& // AND two single bits or each bit between two buses
! // Not True
| // OR two single bits or each bit between two buses
&& // Both Inputs True
^ // XOR two single bits or each bit between two buses
|| // Either Input True
▪ ARITHMETIC == // Inputs Equal
+ // Addition != // Inputs Not Equal
- // Subtraction < // Less-than
<= // Less-than or Equal
▪ UNARY REDUCTION > // Greater-than
& // AND all bits in the busl >= // Greater-than or Equal
| // OR all bits in the busl
▪ BIT SWIZZLING
▪ COMPARATORS To select and to rearrange the elements of a vector.
== // Equal {A, B, C} // Concatenate “A”, “B” and “C” into a bus
!= // Not Equal {3{A}} // Replicate “A” 3 times
> // Greater-than {{5{A}}, B} // Replicate “A” 5 times and concatenate to “B”
>= // Greater-than or Equal A[4] // Select bit 4 of bus A
< // Less-than A[3:1] // Select bits 3, 2 and 1 (3 to 1) of bus A
<= // Less-than or Equal
SYNTHESIS CONSTRUCTS
▪ CONTINUOUS ASSIGNMENT ▪ CONDITIONAL ASSIGNMENT
assign _wire = signal_or_value; assign _wire= 1bit_sel? signal_for_1: signal_for_0;
▪ GENERATE
genvar var;
generate
for (var_initialization; condition; step)
begin: label
statement or instantiation
end
endgenerate
▪ PROCEDURAL ASSIGNMENTS
Assignments made inside “always” procedural blocks. All variables on the left-hand side must be register data type.
◦ case PROCEDURAL STATEMENT
always @(event_list)
always @(event_list) case (expression)
case (expression) 1: statement_for_1;
0: statement_for_0; 2: statement_for_2;
1: statement_for_1; 6: statement_for_6;
2: statement_for_2; default: default_statement;
3: statement_for_3; endcase
4: statement_for_4;
5: statement_for_5; always @(event_list)
6: statement_for_6; case (expression)
7: statement_for_7; 0,2,4: statement_for_0_2_4;
default: default_statement; 3,7 : statement_for_3_7;
endcase 6 : statement_for_6;
default: default_statement;
endcase
◦ if PROCEDURAL STATEMENT
always @(event_list) always @(event_list)
if (condition) if (condition)
statement_for_true; statement;
else else if (condition)
statement_for_false; statement;
else
statement;
Sistemas Digitales I
Carlos A. Angulo J.
SIMULATION CONSTRUCTS
$finish is a system task that ends simulation.
$monitor is a system task that outputs the value of the variables if they change. Only one $monitor task can be active at a time.
▪ LOOP STATEMENTS
There are several ways to create a looping statement within a Verilog
testbench. Each of these constructs must appear within an “initial” or
“always” block.
• initial: procedural block that executes once at start of simulation and stop.
This construct is not supported by the synthesis standard.
• always: procedural block that acts like a continuous loop.
The testbench must include the following statements to display the results of the simulation in gtkwave:
initial begin
$dumpfile("ARCHIVO.vcd");
$dumpvars;
end