Professional Documents
Culture Documents
ECEn 224
A2 VERILOG Page 1
2003-2008 BYU
Motivation
Structural design can be cumbersome
Lots of typing
32-bit busses & logic
ECEn 224
A2 VERILOG Page 2
2003-2008 BYU
Much simpler, less typing, familiar C-like syntax. Synthesizer turns it into optimized gate-level design.
ECEn 224
A2 VERILOG Page 3
2003-2008 BYU
ECEn 224
A2 VERILOG Page 4
2003-2008 BYU
Dataflow Operators
Operator Type Operator Symbol Operation Performed Arithmetic *, /, +, % Logical ! && || Bitwise ~ & | ^ ~^ Relational <, >, <=, >= Equality ==, != Reduction & ~& | ~| ^ ~^ Shift << >> Concat { } Replicate { { } } Cond ?: As expected Modulo Logic NOT Logic AND Logic OR Bitwise NOT Bitwise AND Bitwise OR Bitwise XOR Bitwise XNOR As expected As expected Red. AND Red. NAND Red. OR Red. NOR Red. XOR Red. XNOR Left shift Right shift Concatenate Replicate As expected Comments * and / take LOTS of 2 hardware 2 1 As in C 2 As in C 2 As in C 1 As in C 2 As in C 2 As in C 2 As in C 2 2 As in C 2 As in C 1 Multi-bit input 1 Multi-bit input 1 Multi-bit input 1 Multi-bit input 1 Multi-bit input 1 Multi-bit input 2 Fill with 0's 2 Fill with 0's Any number Any number 3 As in C
A2 VERILOG Page 5 2003-2008 BYU
# of Operands
ECEn 224
1101
a
4
<
q
1
Use &&, ||, ! for 1-bit quantities (results of comparisions) Use &, |, ~ for bit-by-bit logical operations
ECEn 224
A2 VERILOG Page 6 2003-2008 BYU
Reduction Operators
ECEn 224
A2 VERILOG Page 7
2003-2008 BYU
ECEn 224
A2 VERILOG Page 8
2003-2008 BYU
Operator Precedence
Similar to C
Higher precedence Unary -, unary +, !, ~ *, /, % +, <<, >> <, <=, >, >= ==, != &, ~& ^, ~^ |, ~| && || ?: Lower precedence
ECEn 224
A2 VERILOG Page 9
2003-2008 BYU
Why?
ECEn 224
A2 VERILOG Page 10
2003-2008 BYU
It turns the sel and ~sel values into 4-bit versions for AND-ing and OR-ing A more elegant version:
wire[3:0] a, b, q; wire sel; assign q = sel ? b: a;
ECEn 224
A2 VERILOG Page 11 2003-2008 BYU
Can you see how to make a 3:8 or 4:16 decoder in the same fashion?
ECEn 224
A2 VERILOG Page 12
2003-2008 BYU
ECEn 224
A2 VERILOG Page 13
2003-2008 BYU
a b
16 16
16
Key Ideas: The predicate must evaluate to true or false (1 or 0) The parts getting assigned must be all same widths.
ECEn 224
A2 VERILOG Page 14
2003-2008 BYU
Using Parameterization
Careful planning often allows you to write one design which can be reused Reuse is a common goal in design
Simplifies your work Eliminates errors Saves time later
ECEn 224
A2 VERILOG Page 16
2003-2008 BYU
Parameterization Exercise
Design a 4:1 MUX that works with any size operands (arbitrary bit-width) Either:
Build arbitrary bit-width 2:1 MUX Structurally instance 3 of these to make a 4:1 MUX or Write an arbitrary bit-width 4:1 MUX using the ?: operator
ECEn 224
A2 VERILOG Page 17 2003-2008 BYU
If the mux21n cells are parameterizable for bit-width this works If not, it doesnt work
ECEn 224
A2 VERILOG Page 18
2003-2008 BYU
ECEn 224
A2 VERILOG Page 19
2003-2008 BYU
Behavioral Verilog
ECEn 224
A2 VERILOG Page 20
2003-2008 BYU
You can use this as a DFF for your design. Figure out how to parameterize it for arbitrary input/output widths Remainder of behavioral design not covered in this class
ECEn 224
A2 VERILOG Page 21
2003-2008 BYU
Conclusion
With what you know
You can do reasonable designs Must structurally instance all storage elements (flip flops)
Behavioral Design
A number of nuances with respect to timing semantics Not recommended beyond simple FFs for this class
You will learn full range of behavioral design in later courses
ECEn 224
A2 VERILOG Page 22 2003-2008 BYU