Introduction To Verilog: Dr. Ahmad Almulhem
Introduction To Verilog: Dr. Ahmad Almulhem
Introduction To Verilog: Dr. Ahmad Almulhem
edited from
http://www.ee.nmt.edu/~elosery/fall_2008/ee231L/
1. In order to write an Verilog HDL description of any circuit you will need to write a module which is
the fundamental descriptive unit in Verilog. A module is a set of text describing your circuit and is
enclosed by the keywords module and endmodule.
2. As the program describes a physical circuit you will need to specify the inputs, the outputs, the behavior
of the circuit and how the gates are wired. To accomplish this, you need the keywords input, output,
and wire to define the inputs, outputs and the wiring between the gates, respectively.
• gate-level modeling,
• data ow modeling,
• behavioral modeling,
• or a combination of the above.
4. A simple program modeling a circuit (see Figure 2) at the gate-level, is provided below.
and G1(w1,A,B);
not G2(E,C);
or G3(D,w1,E);
endmodule // no semi-colon
5. As seen above the outputs come first in the port list followed by the inputs.
A
G1
B
G3 D
C G2 E
endmodule
10. You can identifiers describing multiple bits known as vectors. For example you may write Program 2
as
Program 3 Simple program in Verilog modeling a circuit using data ow using vectors
module simple_circuit(output [1:0] Y, input [0:2] X);
endmodule
In this example, we have the input as three bits representing A, B, C and we have denoted them
as [0:2] X which means we have three bits with the index 0 representing the MSB. We could have
specified it as [2:0] X in which case the index 2 represents the MSB.
2. Target output is of type reg. Unlike a wire, reg is updated only when a
new value is assigned. In other words, it is not continuously updated as
wire data types.
3. always may be followed by an event control expression.
6. The list of variables are separated by logical operator or and not bitwise
OR operator ”—”.
always @(A or B)
.
.
.
output out;
input s,A,B;
reg out;
.
.
.
.
.
.