Chapter 4 RTL Model: Digital Design With The Verilog HDL
Chapter 4 RTL Model: Digital Design With The Verilog HDL
Binh Tran-Thanh
January 5, 2022
1 / 36
RTL Verilog
2 / 36
Continuous Assignment
3 / 36
Full Adder: RTL/Dataflow
4 / 36
RTL And Structural Combined
Add full
5 / 36
Continuous Assignment LHS
Examples
6 / 36
Continuous Assignment RHS
Use operators
Arithmetic, Logical, Relational, Equality, Bitwise, Reduction, Shift,
Concatenation, Replication, Conditional
Same set as used in Behavioral Verilog
assign a = stimulus[16:9];
assign b = stimulus[8:1];
assign cin = stimulus[0];
Note: “aliasing” is only in one direction
Cannot give ‘a’ a new value elsewhere to set stimulus[16:9]!
7 / 36
Implicit Continuous Assignments
8 / 36
Implicit Wire Declaration
9 / 36
Verilog Operators
11 / 36
Verilog Operators
12 / 36
Arithmetic Operators (+, −, ∗, /, %)
13 / 36
Relational Operators (<, >, <=, >=)
In1
f True/False(0/1)
In2
In1 = 52
f X
In2 = 8’Hx5
In1 = 3’b001
< True(1)
In2 = 3’b011
Data = 4’b11x0;
Addr = 4’b11x0;
Data == Addr //x
Data === Addr //1
15 / 36
Logical Operators (||, &&, !)
ABus = 4’b0110;
BBus = 4’b0100;
ABus || BBus// 1
ABus && BBus// 1
!ABus // Similar to !BBus
// 0
16 / 36
Bit-wise Operators (&, |, ∼, ∧, ∧ ∼)
∧ (xor) 0 1 x z ∧ ∼ (xnor) 0 1 x z
0 0 1 x x 0 1 0 x x
1 1 0 x x 1 0 1 x x
x x x x x x x x x x
z x x x x z x x x x
∼ (not) 0 1 x z
1 0 x x
17 / 36
Reduction Operators
f X f Z
& 0 & 1
18 / 36
Reduction Operators
& ∼ 0/1
| 1 | 0
19 / 36
Reduction Operators
| ∼ 0/1
20 / 36
Shift Operators (<<, >>)
Shift the left operand the number of times represented by the right
operand
Shift left
Bn Bn−1 ... B2 B1 B0
reg [0:7] Qreg;
Qreg = 4’b0111;
Bn−1 Bn−2 ... B1 B0 0 0 // 8’b0000_0111
Qreg >> 2;
Shift right // 8’b0000_0001
Qreg = 4’d1 << 5;
Bn Bn−1 ... B2 B1 B0 // 8’b0010_0000
0 0 Bn ... B3 B2 B1
21 / 36
Conditional Operator Cond_expr ? Expr1: Expr2
22 / 36
Concatenation and Replication Operators
23 / 36
Expression Bit Lengths
24 / 36
Example: adder4b
endmodule
4
a[3:0] 4
4 sum[3:0]
b[3:0] adder4b
Cout
Cin
25 / 36
Example: Unsigned MAC Unit
26 / 36
Solution: Unsigned MAC Unit
27 / 36
Example: Multiplexer
endmodule
28 / 36
Solution: Multiplexer
assign output =
endmodule
29 / 36
Latches
D Q
Enable
30 / 36
Latches
31 / 36
Example: Rock-Paper-Scissors
module rps(win, player, p0guess, p1guess);
Assumptions:
Input: p0guess, p1guess = 0 for rock, 1 for paper, 2 for scissors
Output: player is 0 if p0 wins, 1 if p1 wins, and don’t care if there is a
tie
Output: win is 0 if there is a tie and 1 if a player wins
Reminders
Paper beats rock, scissors beats paper, rock beats scissors
Same values tie
Two possible approaches
Figure out the Boolean equations for win and player and implement
these using continuous assignments
Use bitwise operators
Examine what the various items equal and do logical operations on
these
Use equality and logical operators
32 / 36
Example: Rock-Paper-Scissors
33 / 36
Solution 1: Rock-Paper-Scissors
endmodule
34 / 36
Solution 2: Rock-Paper-Scissors
endmodule
What is are the advantages of each approach?
35 / 36
Draw synthesized hardware of following verilogHDL
wire [3:0] a, b, c;
wire [7:0] d;
assign c = d[7:4] + b;
assign d = a * b;
wire [3:0] a, b, c;
assign c = !a && b ? a + b: a - b;
36 / 36