vhdl codes
vhdl codes
FIGURE 10-5
2-to-1 Multiplexer 1-
- conditional signal assignment statement
F= 10 when A = '0' else 11;
D
F <= A when E = '1'
MUXes else B when D = '1'
else C
Figure 10-7 shows a 4-to-1 MUX with four data inputs and two control inpulsA
and B The control inputs select which one of the data inputs is transmited tou
Anather way to model the 4-to-1 MUX is to use a conditional assignment statement
"00"
F<= 10 when A&B
=
"01
else I1 when A&B
=
else 12 when
A&B =
"10
else 13;
bits A andB
The expression A&B means A concatenated with B, that is, the two the
to form a 2-bit vector. This bit vector is tested, and appro
are merged together
=1' and A&B "10"
B 0',
=
dule. "ider
architecture
module using an
end gatesS
entity entity-name is
port(interface-signal-declaration);]
end lentityl lentity-namel:
The items enclosed in square brackets are optional. The interface-signal-declarat
normally has the following form:
list-of-interface-signals: mode type [: = initial-value
list-of-interface-signals: mode type [ = initial-value|};
FIGURE 10-9
VHDL Program Entity
Architecture
Structure
y
Architecture
Enity Entity
Architecture Architecture
Module
Modute 2 Module N
293
introdur tion to VHOL
declaration
the port
ple.
nort(A, B: in integer
; =
2;C, D: out bit):
that A and Ba
A and B are input signals of type integer that are initially set to L. ana
that
indicates
D are tput
outpl signals of type bit that are initialized by default to
form
architecture-name of entity-name is
architecture
declarations
begin
architecture body
end [architecturel larchitecture-namel
that are used
declarations section,
signals and components describe the
we can declare
n the statements that
The architecture body contains
within the architecture.
of the module. module (refer
operation for a full adder
the entity and architecture
Next, we will write
specifies the inputs and
of a full adder). The entity
4.7 for a description declaration spec
to Section as shown in Figure 10-10. The port
the adder module, and Sum are
outputs of of bit, and that Cout
type
Y and Cin are input signals
ifies that X,
of type bit.
output signals
entity FullAdder is
- Inputs
in bit;
RGURE 10-10
port (X,Y,Cin: Outputs
Full Cout, Sum: out bit);
- -
snty
Declaration
Adder Suni
ira Full Adder end FullAdder;
Module
declaration:
architecture
FullAdder is
architecture Equations of
Concurrent assignment statements
begin Y xor Cin
after 10 ns;
10 ns;
Sum = X xor or (Y and Cin) after
or(X and Cin)
Cout= (X and Y)
end Equations;
name
but the entity
(Equations)
is arbitrary, declaration.
architecture
name
associated entity
the used in the
in this example,
must
match the
name
FullAdder)
294 Unit 10
The VHDL assignt statements for Sum and
out represent the lo0
FIGURE 10-11
4-Bit Binary Adder
C
Full Full Full Full
Adder Adder Adder
Adder
B A2 B, A B Ag B,
entityAdder4 is
METO12 in bit_vector(3 downto
ort (A, B: bit_vector(3 0); Ci: in bit,
Srutra
onon
o
S: out downto 0): Co: out
bit);
- Inputs
Outputs
e n dA d d e r 4 :
com-
in a similar format. We will use the following simulator
duce
produ
output
Adder4:
test
mands to
force Ci 1
-set Ci to1
run the simulation for 50 ns
run 50 ns
force Ci 0
force A 0101
force B 1110
run 50 ns enough
this is m o r e than
simulation for S0 ns because results
to run the simulation
We have
chosen
all of the full adders.The
to propagate through
time for the carry
command list are
for the above
CO
C
delta 0000
ns 0 000
0000 0000 0000
0 0 0001 0 000 1111
1111 001
0001 1101
+0 1111 011
10 0001 1001
1111 111
20 0001 0 0001
1111 111
30 0 0001
1 0001
0 1111 111
40 1110 0101
0101 1 110 0111
50 1110
100 0
0101 1 0011
60 1110 0
0101 100
70 -0 1
1110
0 0101
80