Microsoft Word - Digital Logic Design v_4_6a

(lily) #1
type type_name is array (type range <> ) of element_type;

The most important array type in VHDL is the IEEE 1164 standard user-defined logic type
std_logic_vector which is defined as an ordered set of std_logic bits. If we want to create
unconstrained array of std_logic_vector with an integer index, use the following
declaration:

type STD_LOGIC_VECTOR is array (integer range <> ) of STD_LOGIC;

 Constant declarations
Constants are used to improve readability, portability and maintainability of the code. Constant name
is typically in capital letters and is descriptive of its use. The constant declaration syntax is shown
below:


constant constant_name : type_name := value;

Below are some examples constant declarations and note the assignment operation is the same as
one used for variable “:= ”:

constant BUS_SIZE: integer := 32; -- Width of component
constant MSB: integer := BUS_SIZE-1; -- Bit number of MSB
constant DEF_OUT : character := ‘Z’; -- Default Output constant as character Z

 Function definitions
A function is a subprogram that accepts a number of parameters (Parameters must be defined with
mode “in”) and returns a result. Each of the parameters and the result must have a pre-determined
type.


Functions may contain local types, constants, variables, nested functions and procedures. All
statements in the function body will be executed sequentially. Below is the simplified syntax of
function definition:

function function-name (
signal_names : signal_type; -- arguments (mode is in )
signal_names : signal_type;

...
signal_names : signal_type;
) return return_type is -- one return value which replaces the function
type declaration
constant declaration
variable declaration
function definitions
procedure definitions
begin -- Start of the main body of the function
sequential_statement
...
sequential_statement
end function_name;


 Example—implementing “A but not B” function

entity AbutNotB is
port (X, Y, in BIT; -- X, Y are input of BIT type
Z: out Bit); -- Z is output of BIT type
end AbutNotB
Free download pdf