Professional Documents
Culture Documents
The logic of a module can be described in anyone (or a combination) of the following modeling styles:
Summary:
• Gate-level modeling using instantiations of predefined and user-defined primitive gates. It is
very intuitive to a designer with a basic knowledge of digital logic circuit
• Dataflow modeling using continuous assignment statements with the keyword assign.
• Behavioral modeling using procedural assignment statements with the keyword always.
reg [7:0] x, y;
reg [3:0] z;
reg a;
a = x[7] & y[7]; // bit-selects
z = x[7:4] + y[3:0]; // part-selects
There are three (3) modelling style in Verilog. All examples’ programs use identifiers having multiple bit widths,
called vectors. The syntax specifying a vector includes within square brackets two numbers separated with a
colon.
output [0: 3] D;
➔ The statement declares an output vector D with four bits, 0 through 3.
➔ The statement declares a wire vector SUM with eight bits numbered 7 through
0.7 → 0 (total of 8 bits)
MSB LSB
2^ 7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
128 64 32 16 8 4 2 1
Example:
11111111 = 8 bits
255= 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
= 256 -1
= 255 → 11111111
The individual bits are specified within square brackets, so D [2] specifies bit 2 of D. It is also possible to address
parts (contiguous bits) of vectors.
Example:
module definition
module and4 (x, y, z);
input [3:0] x, y;
output [3:0] z;
assign z = x | y;
end module
output a;
reg a;
begin
a = ((~(W) & ~(X) & ~(Z)) | (~(W)&Y) | (~(W) & X & Z) | (W & ~(X) &~(Y))) ;
// w'x’z’ + w’y + w’xz + wx’y’
end
endmodule
module TestBench;
reg W, X, Y, Z;
wire a;
initial
begin
Here is the following step to solve the given combinational logic design:
1. Specification, you must know the following specification in a circuit. Assume the inputs are W, X,
Y and Z.
where:
• Variable W is the most significant bit (MSB)
• Variable Z is the least significant bit (LSB)
WXYZ = 4 variables
2 ^ 4 = 16 rows / lines
2. Formulation – you need to convert the specifications into a variety of forms. The form is to
construct a Truth table. The table below shows the conversion of binary number to decimal number.
➔ K=mapping
m0 m1 m2 m3
m4 m5 m7 m6
m 12 m 13 m 15 m14
m8 m9 m 11 m10
Figure 3 shows the combinational Gates. The circuit shows the display in binary coded
decimal using 7-segment display as shown on figure 1.
Add
files
Requirements:
• Circuit Diagram as shown on figure 2 and figure 3.
• Verilog program either dataflow or behavioral Modeling
styles
• Documentation with figure and description
Circuit Diagram
K Mapping + Boolean
Output a: X’ Z’ + X’ Y + XZ
YZ
00 01 11 10
0 1 0 1 1
X
1 0 1 1 0
Output b: X’ + Y’ Z’ + YZ
YZ
00 01 11 10
0 1 1 1 1
X
1 1 0 1 0
Output c: Y’ + Z + X
YZ
00 01 11 10
0 1 1 1 0
X
1 1 1 1 1
Output d: X’ Z’ + X’ Y + Y Z’ + X Y’ Z
YZ
00 01 11 10
0 1 0 1 1
X
1 0 1 0 1
Output e: X’ Z’ + Y Z’
YZ
00 01 11 10
0 1 0 0 1
X
1 0 0 0 1
Output f: Y’ Z’ + X Y’ + X Z’
YZ
00 01 11 10
0 1 0 0 0
X
1 1 1 0 1
Output g: X’ Y + X Y’ + X Z’
YZ
00 01 11 10
0 0 0 1 1
X
1 1 1 0 1
Verilog Program W/ Output