Verilog Data Types
Verilog Data Types
Introduction
What is Verilog?
Introduction to Verilog
Data Types
Verilog Syntax
Verilog Arrays
Building Blocks
Verilog Module
Verilog Port
Verilog Operators
Verilog Concatenation
Verilog in a nutshell
Verilog generate
Behavioral modeling
Verilog Blocking/Non-blocking
Verilog if-else-if
Verilog Functions
Verilog Tasks
Verilog Parameters
Gate/Switch modeling
Gate Delays
User-Defined Primitives
Simulation
Verilog Testbench
Verilog Timescale
Verilog Timeformat
Code Examples
Hello World!
JK Flip-Flop
D Flip-Flop
T Flip-Flop
D Latch
Counters
4-bit counter
Ripple Counter
Johnson Counter
Mod-N Counter
Gray Counter
Misc
Priority Encoder
4x1 multiplexer
Full adder
Almost all data-types can only have one of the four different
values as given below except for real and event data
types.
Nets and variables are the two main groups of data types which
represent different hardware structures and differ in the way
they are assigned and retain values.
Nets
1 module design;
2 wire abc;
3 wire a;
4 wire b;
5 wire c;
6
7 wire abc; // Error: Identifier "abc" pre
8
9 assign abc = a & b | c;
10 endmodule
Variables
Other data-types
integer
real
Datatypes Example
1 module testbench;
2 integer int_a; // Integer variab
3 real real_b; // Real variable
4 time time_c; // Time variable
5
6 initial begin
7 int_a = 32'hcafe_1234; // Assign an inte
8 real_b = 0.1234567; // Assign a float
9
10 #20; // Advance simulat
11 time_c = $time; // Assign current
12
13 // Now print all variables using $display syst
14 $display ("int_a = 0x%0h", int_a);
15 $display ("real_b = %0.5f", real_b);
16 $display ("time_c = %0t", time_c);
17 end
18 endmodule
Simulation Log
ncsim> run
int_a = 0xcafe1234
real_b = 0.12346
time_c = 20
ncsim: *W,RNQUIE: Simulation is complete.
Verilog Strings
1 module testbench;
2 reg [8*11:1] str1;
3 reg [8*5:1] str2;
4 reg [8*20:1] str3;
5
6 initial begin
7 str1 = "Hello World";
8 str2 = "Hello World";
9 str3 = "Hello World";
10
11 $display ("str1 = %s", str1);
12 $display ("str2 = %s", str2);
13 $display ("str3 = %s", str3);
14 end
15 endmodule
Note that str1 has the right size to store all 11 bytes of the
string "Hello World" and hence the whole string gets printed.
However str2 can store only 5 bytes and hence the upper 6
bytes get truncated and end up with storing only "World". The
third variable str3 is larger than 11 bytes and pads empty
spaces to the left and hence the value stored in it becomes
" Hello World".
Simulation Log
ncsim> run
str1 = Hello World
str2 = World
str3 =
Hello World
ncsim: *W,RNQUIE: Simulation is complete.
Download Driver
Updater
Ad PC Helpsoft
Interview Questions
Digital Fundamentals
Verilog Tutorial
Verification
SystemVerilog Tutorial
UVM Tutorial
Verilog Testbench
Synchronous FIFO