Chapter 4 RTL Model
Chapter 4 RTL Model
Chapter 4 RTL Model
Binh Tran-Thanh
1/1
RTL Verilog
2/1
Continuous Assignment
3/1
Full Adder: RTL/Dataflow
4/1
RTL And Structural Combined
Add full
5/1
Continuous Assignment LHS
Examples
6/1
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];
7/1
Implicit Continuous Assignments
8/1
Implicit Wire Declaration
9/1
Verilog Operators
11 / 1
Verilog Operators
12 / 1
Arithmetic Operators (+, −, ∗, /, %)
13 / 1
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 / 1
Logical Operators (||, &&, !)
ABus = 4’b0110;
BBus = 4’b0100;
ABus || BBus// 1
ABus && BBus// 1
!ABus // Similar to !BBus
// 0
16 / 1
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 / 1
Reduction Operators
f X f Z
& 0 & 1
18 / 1
Reduction Operators
& ∼ 0/1
| 1 | 0
19 / 1
Reduction Operators
| ∼ 0/1
20 / 1
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;
// 8’b0000_0001
Shift right Qreg = 4’d1 << 5;
Bn Bn−1 ... B2 B1 B0 // 8’b0010_0000
0 0 Bn ... B3 B2 B1
21 / 1
Conditional Operator Cond_expr ? Expr1: Expr2
22 / 1
Concatenation and Replication Operators
Concatenation {expr1, expr2, ... ,exprN}
Does not work with un-sized constants
23 / 1
Expression Bit Lengths
24 / 1
Example: adder4b
module adder4b (sum, c_out, a, b, c_in);
input[3:0] a, b;
input c_in;
output[3:0] sum;
output c_out;
endmodule
4/
a[3:0] 4/
sum[3:0]
4/
b[3:0] adder4b
c out
c in
25 / 1
Example: Unsigned MAC Unit
26 / 1
Solution: Unsigned MAC Unit
27 / 1
Example: Multiplexer
endmodule
28 / 1
Latches
D Q
Enable
29 / 1
Latches
30 / 1
Example: Rock-Paper-Scissors (optional homework)
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
31 / 1
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;
32 / 1
Take away message
33 / 1