-
Notifications
You must be signed in to change notification settings - Fork 0
Verilog Examples
Leonard Pfeiffer edited this page Oct 25, 2023
·
40 revisions
.v // Verilog 2001 standard
.sv // SystemVerilog 2006 standard ❰ We us dis
module <name> #(
<params>
)(
<ports>
);
<params>
<regs>
<wires>
<ints>
<proc>
<ass>
endmodule
input <name>, // Input
input [x:y] <name>, <name>, // Multiple array "x downto y" inputs
inout reg <name>, // Simultaneus in- and output register
output <name> // Output
reg <type> <name>, <name>; // Registers (Save Data at end of clock cycle)
wire <type> [x:y] <name>; // Wire "from x downto y" (Transmits data almost instantly)
reg a = 0; // With initial value this time (mostly for sim)
parameter <type> <name>; // Generic (in port definition)
parameter <type> <name> = <value>; // Constant
localparam <type> <name> = <value>; // Constant inside module (can be computed from generics)
// Ports & params separated by ","
<module> #(
<params>
) <instance> (
<ports>
);
.<port>(<connection/value>)
.<parameter(<connection/value>)
0 // Logical zero
1 // Logical one
x // Unknown/undefined
z // What the actual f*ck
-7 46 123 // Integer
1.3 0.2 3e-5 // Real
"Hello kitty!" // String
d46 D23 // Decimal
hFA HAE // Hexadecimal
o17 O77 // Octal
b10 b01 // Binary
32'd46 // 32 bit filled with (one!) decimal 46
8'b10101010 // "10101010" in binary as 8 bit-value
18'o777777 // 18 bits of ones from octal code
// Can be interpreted by totally not stupid compiler that will totally not produce untraceable errors
real
string
time // For simulations
event // Complex (probably represents change of value of sens list connections / sens list itself)
integer
always @ (<condition>) <actions>
initial <stmt>
initial begin
<stmts>
end
posedge clk // Rising edge of clock
negedge clk // Falling edge o clock
posedge rst // Rising edge of reset
if (<condition1>) begin
<stmts>
end else if (<condition>) begin
<stmts>
end else begin
<stmts>
end
case (<expr>)
<value> : begin
<stmts>
end
<value> : begin
<stmts>
end
default : begin
<stmts>
end
endcase
case (<expr>)
2'bxz : <expr>;
2'bzx : <expr>;
2'bxx : <expr>;
default : <expr>;
endcase
assign x = '1; // Assign all indexes to logical one (works with logic zero too
assign x = 25'd69; // lol
assign x = a ? b : c; // Best of them all: Assign a if b (condition) else assign c to x
package <name>
<params>
<funcs?>
<types>
endpackage
// Elements separated by ","
typedef logic [x:y] <name>; // Arrays
typedef enum state {<e>} <name>; // For united states machines
typedef enum {<e>} <name>; // Not a state enum bruh
typedef enum [x:y] {<e>} <name>; // Enum with specified range