Ic Overview Session6 Verilog Part1
Ic Overview Session6 Verilog Part1
Fundamental – Part 1
1. Verilog introduction
Data Types and
2. Data type
Operators
. 3. Assignment
4. Operator
1
1. Verilog introduction
2. Data type
. 3. Assignment
4. Operator
2
VERILOG FUNDAMENTAL
What is Verilog ?
3
VERILOG FUNDAMENTAL
Synthesizable and Non-synthesizable
❑ Synthesizable: The code that is written in a way that can be directly translated
into hardware circuit by synthesis tool. It represents the actual logic gates,
flip-flops, and other hardware elements that will be synthesized into a digital
circuit.
module combo ( a b c
input wire a;
input wire b;
input wire c;
output wire z z
);
4
VERILOG FUNDAMENTAL
Synthesizable and Non-synthesizable
reg clk;
initial begin
rst = 0;
#100ns rst =1;
end
endmodule
5
VERILOG FUNDAMENTAL
Numbers
3 2 1 0
Unsigned number: 4’b1110 → decimal 14 1 1 1 0
3 2 1 0
Signed number: 4’sb1110 → decimal -2 1 1 1 0
Signed bit
7
VERILOG FUNDAMENTAL
Numbers
❑ Example
1. Assign the result to a 4-bit signal
4’b1000 + 4’b0100 = 1100
Same bit pattern
4’sb1000 + 4’sb0100 = 1100
8
VERILOG FUNDAMENTAL
Numbers
9
VERILOG FUNDAMENTAL
Numbers
▪ “x” value can only be used in simulation, to check the unknown state of the circuit.
▪ “x” is not appeared in actual chip because the circuits always have a state.
▪ The actual chip only has 3 state: 0,1,z.
10
1. Verilog introduction
2. Data type
. 3. Assignment
4. Operator
11
VERILOG DATA TYPES
Net
▪ Net data types are used to represent connections between hardware elements.
▪ Net data types do not hold values.
▪ Net data types have the value of their drivers. If a net has no driver, then net has
high-impedance value (z)
a a
c c e
b b
d
All signals are net types and have drivers. All signals are net types.
b and d have no driver
→ b & d are un-driven or floating net
and has z (high-impedance) value
12
VERILOG DATA TYPES
Net declaration
▪ Keyword: wire
o Default: One-bit values, can declared as vectors
o Default value: z (high-impedance)
o Examples:
wire a;
wire b,c;
wire [2:0] d; //vector
wire [4:2] e; //vector partial selection
13
VERILOG DATA TYPES
Variable
15
VERILOG DATA TYPES
Vector data type – part select
Example:
Having data[15:0] signal as below, perform the assignment for val[3:0] and write_en from data[15:0]
val[3:0] = data[7:4]
write_en = data[0]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
data[15:0] 1 0 1 1 1 0 0 0 1 1 1 0 0 1 1 1
3 2 1 0 0
val[3:0] 1 1 1 0 write_en 0
VERILOG DATA TYPES
Vector data type – part select
data[15:12] = val[3:0] 3 2 1 0
data[7:4] = data[3:0]
val[3:0] 1 1 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
data[15:0] 0 1 0 1 1 0 0 0 1 1 1 0 0 1 1 1
17
VERILOG DATA TYPES
Vector data type – part select
data[17:14] = val[3:0]
3 2 1 0
val[3:0] 1 0 0 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
data[15:0] 1 1 1 0 1 0 0 0 1 1 1 0 0 1 1 1
18
VERILOG DATA TYPES
Vector data type – part select
tmp[3:0] = data[17:14]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
data[15:0] 1 1 1 0 1 0 0 0 1 1 1 0 0 1 1 1
19
VERILOG DATA TYPES
Vector data type
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
data[15:0] MSB LSB
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
data[0:15] MSB LSB
20
VERILOG DATA TYPES
Vector data type
▪ Practice:
reg [7:0] data_1;
reg [0:7] data_2;
data_1 = 8’b1000_1000;
data_2 = 8’b1000_1000;
21
VERILOG DATA TYPES
Array data type
▪ Arrays can be used to group elements of a data type into multidimensional objects.
▪ Syntax: <data_type> <MSB:LSB> <array_name> [first_element_idx:last_element_idx];
▪ Example:
integer count[7:0]; //array of 8 integer
reg [7:0] data[15:0]; //array of 16 byte reg
MSB LSB
7 6 5 4 3 2 1 0 data[15] first element
7 6 5 4 3 2 1 0 data[14]
7 6 5 4 3 2 1 0 data[13]
… …
7 6 5 4 3 2 1 0 data[0] last element
▪ Only can access 1 element of the array at a time
o data[0]: access to the last byte of the array
o data[15][7]: access to the MSB of the first element of the array
o data[2:0][5]: is illegal
▪ Multi-dimensional array is not mentioned in this course.
▪ Do not use array declaration unless it makes the code become simple and easy to understand. 22
VERILOG DATA TYPES
Array data type
▪ Memory are digital storage that help store a data and information in digital circuits.
▪ RAM and ROM are good example of such memory elements.
▪ Storage elements can be modeled using one-dimensional array of reg type.
▪ Syntax: reg [WIDTH-1:0] <name> [0:DEPTH-1];
WIDTH: width of each memory word (in bits)
DEPTH: depth of size of the memory (number of words)
▪ Can read from and write to specific locations in the memory using indexing.7 0
▪ Example: 0
reg [7:0] mem[0:1023]; //1024x8 memory
reg [7:0] tmp; 1
//write to memory 2 1011_0111
mem[2] = 8’b1011_0111; .
.
tmp = mem[2]; //read mem[2], tmp’s value is 8’b1011_0111
1023
23
1. Verilog introduction
2. Data type
. 3. Assignment
4. Operator
24
VERILOG ASSIGNMENT
Continuous Assignment
▪ Continuous assignment: drive values onto nets. LHS must be net data type.
o Syntax: assign y = expression; //y is wire data type
Example:
wire [3:0] y;
assign y = a + b;
o Range is allowed in the assignment
3 2 1 0
val[3:0] 1 1 1 0
wire [15:0] data;
wire [3:0] val;
…. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
assign data[15:12] = val[3:0]
1 1 1 0 1 0 0 0 0 1 1 1 0 1 1 1
assign data[7:4] = data[3:0]
assign a = b & c; assign b = d | e; When d or e is updated, b will change. The change of b causes a change.
assign b = d | e; assign a = b & c; The order of assignment does not affect the result.
25
VERILOG ASSIGNMENT
Procedural assignment
26
PRACTICE
module1 module2
a e
c d g h
b f
memory element
procedure
27
1. Verilog introduction
2. Data type
. 3. Assignment
4. Operator
28
VERILOG OPERATOR
Bitwise operator
▪ Bit-wise operators:
Syntax: <operand 1> operator <operand 2> (except the bitwise invert)
29
VERILOG OPERATOR
Arithmetic operators
▪ Arithmetic operators:
Syntax: <operand 1> operator <operand 2>
30
VERILOG OPERATOR
Relational operators
▪ Relational operators:
Syntax: <operand 1> operator <operand 2>
31
VERILOG OPERATOR
Equality operators
▪ Equality operators:
Syntax: <operand 1> operator <operand 2>
32
VERILOG OPERATOR
Logical operators
▪ Logical operators:
Syntax: <operand 1> operator <operand 2>
❑ One operand has one bit value is 1 → its value is 1 seen by the logical operator
❑ One operand has all bit value is 0 → its value is 0 seen by the logical operator
❑ If above 2 cases are wrong → its value is x by the logical operator
33
VERILOG OPERATOR
Unary reduction operators
34
VERILOG OPERATOR
Concatenation operators
▪ Concatenation Operators
Operator Name Example
{} Concatenation {a[3:0] , b[2:0]) → to create a 7bit signal that has bit range [2:0]
equal to b[2:0] and bit range [6:3] equal to a[3:0]
3 2 1 0 2 1 0 1 0
a[3:0] 1 0 1 0 b[2:0] 1 1 0 c[1:0] 0 1
Practice:
Find the result of following expressions:
2. { {3{2’b10}}, {5’h8} }
36
VERILOG OPERATOR
Conditional operators
▪ Conditional Operators
▪ Syntax: (cond)? (result if cond true) : (result if cond false)
▪ Example:
assign y = (s==1)? a : b;
→ y is assigned to a if s is 1
→ y is assigned to b if s is 0
37
VERILOG OPERATOR
Precedence
SUMMARY:
❑ There are 4 basic value in Verilog: 0,1,x,z. “x” does not exist in actual silicon.
❑ Net data types are used to represent connections between hardware elements and
can not hold value. Use “wire” for net data type declaration.
❑ Reg data types are used to represents storage elements or combinational logic in
procedure. Use “reg” for reg data type declaration.
❑ Multiple bits are group into vectors and arrays
❑ Need to take care Verilog precedence to avoid issues during simulation
39
VERILOG DATA TYPES
Reg data type
procedure
40
VERILOG DATA TYPES
Reg data type