Beruflich Dokumente
Kultur Dokumente
Format is [MSB:LSB]
w0
w3
w4 s2
s3
w7
w8
w11
The Verilog code for mux4x1 must be either in
the same file as mux16x1, or in a separate file
w12 (called mux4x1.v) in the same directory as
mux16x1
w15
Hierarchical Design of a 4 to 16 Decoder
w0 y0 y4
w1 y1 y5
y2 y6
w2 w0 y0 En y3 y7
w3 w1 y1
y2
En En y3 w0 y0 y8
w1 y1 y9
y2 y10
En y3 y11
w0 y0 y12
w1 y1 y13
y2 y14 dec2to4 to be presented soon ….
En y3 y15
Behavioral Style in Verilog
begin
You won’t find much use for begin … end
… most constructs really do include just a single
… statement
end
Negative numbers:
-4'b101 the 4 bit 2’s complement of 5 1011
The Verilog compiler chooses the size to fit with the other
operands in the expression
Case Statement
casex vs case
Case, Casez, Casex
No match here
Casex treats 0 and 1 literally
Casex treats both x and z as don’t cares
Example: 4’b0110 matches 4’b01xx and also 4’b01xz
BCD to 7 Segment Display Converter
For Loop
xn –1 yn – 1 x1 y1 x0 y0
c1
cn FA cn -1 c2 FA FA c0
sn – 1 s1 s0
MSB position LSB position
Behavioral Style Full Adder
behavioral style
Behavioral Style Ripple-Carry Adder
Can have many inputs (must have > 0), but only one output
Function is called like C++ functions that have a non-void
return value
generate … endgenerate
yn – 1 y1 y0
Add Sub
control
xn – 1 x1 x0
cn n-bit adder c0
sn – 1 s1 s0
Macrofunctions
Multi-bit signals
must be named
with [MSB..LSB]
Sample Application: BCD Adder
Examples:
X= 0010 X= 1000 X= 0110
Y= 0110 Y= 1001 Y= 0101
Binary Sum= 1000 Binary Sum= 0001 Binary Sum= 1011
BCD Sum= 1000 BCD Sum= 0111 BCD Sum= 0001
Cout= 0 Cout= 1 Cout= 1
c in
4-bit adder
carry-out
Detect if
sum 9>
6 0
MUX
Adjust
cout
compute ccout
out 4-bit adder 0
Adjust = (carry-out) |
cout
(Z[3] & (Z[2] | Z[1]))
S
Structural Verilog for BCD Adder
Z from adder1
control operation
[S2:S0]
000 clear (0000)
001 B-A-cin
010 A-B-cin
011 A+B+cin
100 AB
101 A|B
110 A&B
111 set (1111)
for use with carry-lookahead adders
Verilog for the 74381 TTL 4-Bit ALU