Professional Documents
Culture Documents
1
The VHDL statement generate is a concurrent statement. It is used to
generate multiple instances of a program segment.
The generate statement has two different forms which are unconditional
generate and conditional generate.
2
Unconditional Generate
The unconditional generate as its name implies has no conditional part. Its syntax is as
follows:
The use of Label is a must in generate statement, and the word begin is used if declarative
part is available in the generate statement.
3
Example-2.6: The generate statement in
That is, the same digital logic circuit synthesized for both program segments.
4
Example-2.7: Write a VHDL statement that reverses the elements of an 8-bit logic vector.
Solution-2.7: Let x and y be an 8-bit vectors. We can reverse the content of vector x using
the following VHDL statement:
5
Example-2.8: Write the previous example as a complete VHDL program.
begin
end architecture;
6
PR 2.6 Program 2.6.
Parity Generator
𝑥 = 𝑥0 𝑥1 𝑥2 ⋯ 𝑥𝑁−1
is calculated as
𝑝 = 𝑥0 ⊕ 𝑥1 ⊕ ⋯ ⊕ 𝑥𝑁−1
Note that, xor is an odd function, i.e., if the number of ‘1’s in binary vector 𝑥 is an odd
integer, then 𝑝 = 1, otherwise 𝑝 = 0.
7
Example-2.9: Write a VHDL statement that calculates the parity for 16-bit logic vector.
Solution-2.9: Let x_vec be a 16-bit vector, and parr_vec be another 16-bit vector.
We can calculate the parity bit for x_vec using the following VHDL statement:
parr_vec(0)<=x(0);
p<= parr_vec(15);
8
Example-2.10: Write the previous example as a complete VHDL program.
Solution-2.10: The complete VHDL program is given in PR 2.7.
entity parity_bit_generator is
port( x_vec: in bit_vector(15 downto 0);
p_bit: out bit);
end entity;
begin
parr_vec(0)<= x_vec(0);
10
Example-2.11: Write a VHDL statement that checks a constant positive integer and detects
whether it is an even or odd integer.
11
Example-2.12: Write the previous example as a complete VHDL program.
Solution-2.12: The complete program is depicted in PR 2.8.
entity even_odd_detector is
port( EvenFlag: out bit);
end entity;