VHDL Language Reference: Appendix B
VHDL Language Reference: Appendix B
1. VHDL Basics
1.1. Valid Names
1.2. Comments
1.3. Entity and Architecture
1.4. Ports
1.5. Signals and Variables
1.6. Type
1.6.1. STD_LOGIC
1.6.2. Enumerated Type
1.7. Libraries and Packages
1.2 Comments
A comment is explanatory text that is ignored by the VHDL compiler. It is indicated by
two consecutive hyphens.
689
690 A P P E N D I X B • VHDL Language Reference
Syntax:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY __entity_name IS
GENERIC(define parameters);
PORT(define inputs and outputs);
END __entity_name;
ARCHITECTURE a OF __entity_name IS
SIGNAL and COMPONENT declarations;
BEGIN
statements;
END a;
ENTITY majority IS
PORT(
a, b, c: IN STD_LOGIC;
y : OUT STD_LOGIC);
END majority;
ARCHITECTURE a OF majority IS
BEGIN
y <= (a and b) or (b and c) or (a and c);
END a;
ENTITY decoder IS
PORT(
d : IN STD_LOGIC_VECTOR (1 downto 0);
y : OUT STD_LOGIC_VECTOR (3 downto 0));
END decoder;
ARCHITECTURE a OF decoder IS
BEGIN
WITH d SELECT
y <= “0001” WHEN “00”,
“0010” WHEN “01”,
“0100” WHEN “10”,
“1000” WHEN “11”,
“0000” WHEN others;
END a;
❘❙❚
A P P E N D I X B • VHDL Language Reference 691
1.4 Ports
A port in VHDL is a connection from a VHDL design entity to the outside world. The
direction or directions in which a port may operate is called its mode. A VHDL port
may have one of four modes: IN (input only), OUT (output only), INOUT (bidirec-
tional), and BUFFER (output, with feedback from the output back into the design en-
tity). The mode of a port is declared in the port statement of an entity declaration or
component declaration.
ENTITY srg8 IS
PORT(
clock, reset : IN STD_LOGIC;
q : BUFFER STD_LOGIC_VECTOR (7 downto 0));
END srg8;
❘❙❚
1.6 Type
The type of a port, signal, or variable determines the values it can have. For example, a sig-
nal of type BIT can only have values ‘0’ and ‘1’. A signal of type INTEGER can have any
692 A P P E N D I X B • VHDL Language Reference
integer value, up to the limits of the bit size of the particular computer system for which the
VHDL compiler is designed. Some common types are:
1.6.1 STD_LOGIC
The STD_LOGIC (standard logic) type, also called IEEE Std.1164 Multi-Valued Logic,
gives a broader range of output values than just ‘0’ and ‘1’. Any port, signal, or variable of
type STD_LOGIC or STD_LOGIC_VECTOR can have any of the following values.
‘U’, —— Uninitialized
‘X’, —— Forcing Unknown
‘0’, —— Forcing 0
‘1’, —— Forcing 1
‘Z’, —— High Impedance
‘W’, —— Weak Unknown
‘L’, —— Weak 0
‘H’, —— Weak 1
‘-’, —— Don’t care
“Forcing” levels are deemed to be the equivalent of a gate output. “Weak” levels are
specified by a pull-up or pull-down resistor. The ‘Z’ state is used as the high-impedance
state of a tristate buffer.
The majority of applications can be handled by ‘X’, ‘0’, ‘1’, and ‘Z’ values.
To use STD_LOGIC in a VHDL file, you must include the following reference to the
VHDL library called ieee and the std_logic_1164 package before the entity declaration.
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
type.
Syntax:
LIBRARY __ library_name;
USE __library_name.__package_name.ALL;
2. Concurrent Structures
2.1. Concurrent Signal Assignment Statement
2.2. Selected Signal Assignment Statement
2.3. Conditional Signal Assignment Statements
2.4. Components
2.4.1. Component Declaration
2.4.2. Component Instantiation
2.4.3. Generic Clause
2.5. Generate Statement
2.6. Process Statement
A concurrent structure in VHDL acts as a separate component. A change applied to multi-
ple concurrent structures acts on all affected structures at the same time. This is similar to
a signal applied to multiple components in a circuit; a change in the signal will operate on
all the components simultaneously.
Syntax:
__signal <= __expression;
signal, based on the value of a selecting signal. It can be used to implement a truth table or
a selecting circuit like a multiplexer.
Syntax:
label: WITH __expression SELECT
__signal <= __expression WHEN __constant_value,
__expression WHEN __constant_value,
__expression WHEN __constant_value,
__expression WHEN __constant_value;
Syntax:
__label:
__signal <= __expression WHEN __boolean_expression ELSE
__expression WHEN __boolean_expression ELSE
__expression;
❘❙❚
2.4 Components
A VHDL file can use another VHDL file as a component. The general form of a design en-
tity using components is:
ENTITY entity_name IS
PORT ( input and output definitions);
END entity_name;
Syntax:
COMPONENT __component_name
GENERIC(__parameter_name : string := __default_value;
__parameter_name : integer := __default_value);
PORT(
__input name, __input_name : IN STD_LOGIC;
__bidir name, __bidir_name : INOUT STD_LOGIC;
__output name, __output_name : OUT STD_LOGIC);
END COMPONENT;
assigned explicitly with the ⫽⬎ operator, or implicitly by inserting the user port name in
the position of the corresponding port name within the component declaration.
Syntax:
__instance_name: __component_name
GENERIC MAP (__parameter_name => __parameter_value ,
__parameter_name => __parameter_value)
PORT MAP (__component_port => __connect_port,
__component_port => __connect_port);
Syntax:
— — parameters defined in entity declaration of component file
ENTITY entity_name IS
GENERIC(__parameter_name : type := __default_value;
A P P E N D I X B • VHDL Language Reference 697
— — srt8_bhv.vhd
— — 8-bit shift register that instantiates srt_bhv
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY srt8_bhv IS
PORT(
data_in, clock : IN STD_LOGIC;
qo : BUFFER STD_LOGIC_VECTOR(7 downto 0));
END srt8_bhv;
END COMPONENT;
(example continues)
BEGIN
— — component instantiation
Shift_right_8: srt_bhv
GENERIC MAP (width=> 8)
PORT MAP (serial_in => data_in,
clk => clock,
q => qo);
END right_shift;
❘❙❚
Syntax:
__generate_label:
FOR __index_variable IN __range GENERATE
__statement;
__statement;
END GENERATE;
Syntax:
__process_label:
PROCESS (sensitivity list)
variable declarations
BEGIN
sequential statements
A P P E N D I X B • VHDL Language Reference 699
3. Sequential Structures
3.1. If Statement
3.1.1. Evaluating Clock Functions
3.2. Case Statement
A sequential structure in VHDL is one in which the order of statements affects the opera-
tion of the circuit. It can be used to implement combinational circuits, but is primarily used
to implement sequential circuits such as latches, counters, shift registers, and state ma-
chines. Sequential statements must be contained within a process.
3.1 If Statement
An IF statement executes one or more statements if a Boolean condition is satisfied.
Syntax:
IF __expression THEN
__statement;
__statement;
ELSIF __expression THEN
__statement;
__statement;
ELSE
__statement;
__statement;
END IF;
END PROCESS;
❘❙❚
Syntax:
CASE __expression IS
WHEN __constant_value =>
__statement;
__statement;
WHEN __constant_value =>
__statement;
__statement;
WHEN OTHERS =>
__statement;
__statement;
END CASE;
x <= “1111”;
END CASE;