Data Flow Modeling
Data Flow Modeling
Continuous Assignments
• A continuous assignment is the most basic statement in dataflow modeling,
used to drive a value onto a net
2. Operands
• Operands can be constants, integers, real numbers, nets, registers, times, bit-
select (one bit of vector net or a vector register), part-select (selected bits of the
vector net or register vector), and memories or function calls).
Operands examples
reg ret_value;
ret_value = calculate_parity(A, B);//calculate_parity is a
//function type operand
3. Operators
• arithmetic,
• logical,
• relational,
• equality,
• bitwise,
• reduction,
• shift,
• concatenation,
• conditional.
Operator Type Operator Symbol Operation Performed Number of Operands
* multiply two
/ divide two
+ add two
Arithmetic
- subtract two
% modulus two
** power (exponent) two
! logical negation one
Logical && logical and two
|| logical or two
> greater than two
< less than two
Relational
>= greater than or equal two
1. Binary operators
Binary arithmetic operators are multiply (*), divide (/), add (+), subtract (-),
power (**), and modulus (%). Binary operators take two operands.
A = 4'b0011; B = 4'b0100; // A and B are register
vectors
D = 6; E = 4; F=2 // D and E are integers
• Logical operators are logical-and (&&), logical-or (||) and logical-not (!). Operators
&& and || are binary operators. Operator ! is a unary operator
// Logical operations
A = 3; B = 0;
A && B // Evaluates to 0. Equivalent to (logical-1 &&
logical-0)
A || B // Evaluates to 1. Equivalent to (logical-1 ||
logical-0)
!A // Evaluates to 0. Equivalent to not(logical-1)
!B // Evaluates to 1. Equivalent to not(logical-0)
// Unknowns
A = 2'b0x; B = 2'b10;
A && B // Evaluates to x. Equivalent to (x && logical 1)
// Expressions
(a == 2) && (b == 3) // Evaluates to 1 if both a == 2
and b == 3 are true.
// Evaluates to 0 if either is false.
Relational Operators
// A = 4, B = 3
// X = 4'b1010, Y = 4'b1101, Z = 4'b1xxx
A <= B // Evaluates to a logical 0
A > B // Evaluates to a logical 1
Y >= X // Evaluates to a logical 1
Y < Z // Evaluates to an x
Equality Operators
• Equality operators are logical equality (==), logical inequality (!=), case equality
(===), and case inequality (!==).
• When used in an expression, equality operators return logical value 1 if true, 0 if
false.
• These operators compare the two operands bit by bit, with zero filling if the
operands are of unequal length
Possible Logical
Expression Description Value
// A = 4, B = 3
// X = 4'b1010, Y = 4'b1101
// Z = 4'b1xxz, M = 4'b1xxz, N = 4'b1xxx
A == B // Results in logical 0
X != Y // Results in logical 1
X == Z // Results in x
Z === M // Results in logical 1
(all bits match,
including x and z)
Z === N // Results in logical 0 (least significant bit
does not match)
M !== N // Results in logical 1
Bitwise Operators
• Bitwise operators are negation (~), and(&), or (|), xor (^), xnor (^~, ~^).
• Bitwise operators perform a bit-by-bit operation on two operands.
• They take each bit in one operand and perform the operation with the
corresponding bit in the other operand.
• If one operand is shorter than the other, it will be bit-extended with zeros to match
the length of the longer operand.
• A z is treated as an x in a bitwise operation.
• Logic tables for the bit-by-bit computation are shown in below
Truth Tables for Bitwise Operators
Examples of bitwise operators
// X = 4'b1010, Y = 4'b1101
// Z = 4'b10x1
// X = 4'b1010, Y = 4'b0000
// X = 4'b1010
&X //Equivalent to 1 & 0 & 1 & 0. Results in 1'b0
|X //Equivalent to 1 | 0 | 1 | 0. Results in 1'b1
^X //Equivalent to 1 ^ 0 ^ 1 ^ 0. Results in 1'b0
//A reduction xor or xnor can be used for even or odd
//parity generation of a vector.
Shift Operators
• Shift operators are right shift ( >>), left shift (<<), arithmetic right shift (>>>), and
arithmetic left shift (<<<).
• Regular shift operators shift a vector operand to the right or the left by a specified
number of bits
// X = 4'b1100
Y = {B , C} // Result Y is 4'b0010
Y = {A , B , C , D , 3'b001} // Result Y is
11'b10010110001
Y = {A , B[0], C[1]} // Result Y is 3'b101
Replication Operator
reg A;
reg [1:0] B, C;
reg [2:0] D;
A = 1'b1; B = 2'b00; C = 2'b10; D = 3'b110;
Reduction ^ ^~
|, ~|
&&
Logical
||
Conditional ?: Lowest precedence
Example 1 : 4-to-1 Multiplexer
output out;
input i0, i1, i2, i3;
input s1, s0;
assign out = (~s1 & ~s0 & i0)|(~s1 & s0 & i1) | (s1 & ~s0 & i2) |
(s1 & s0 & i3) ;
endmodule
Method 2: Multiplexer, Using conditional operator
output out;
input i0, i1, i2, i3;
input s1, s0;
endmodule
Example 1: 4-bit Full Adder
Method 1: Using dataflow operators
// Define a 4-bit full adder by using dataflow
statements.
module fulladd4(sum, c_out, a, b, c_in);
endmodule
4-bit Full Adder
// Internal wires
assign c1 =
g0 | (p0 & c_in),
c2 = g1 |
(p1 & g0) | (p1 & p0 & c_in),
c3 = g2 |
(p2 & g1) | (p2 & p1 & g0) | (p2 & p1 & p0 & c_in),
c4 = g3 |
(p3 & g2) | (p3 & p2 & g1) | (p3 & p2 & p1 & g0) |
(p3 & p2 & p1 & p0 & c_in);
// Compute Sum
assign sum[0] = p0 ^ c_in, sum[1] = p1 ^
c1, sum[2] = p2 ^ c2, sum[3] = p3 ^
c3;
endmodule
Thank you