|
VHDL Tutorial |
Unconstrained array parameter | ||
|
Introduction Fundamental concepts Modelling concepts Elements of behaviour Elements of structure Analysis elaboration Lexical elements Identifiers Numbers Characters and strings Syntax descriptions Constants and variables Scalar type Integer types Floating point types Time type Enumeration types Character types Boolean type Bits type Standard logic Sequential statements Case statements Loop and exit statements Assertion statements Array types & array operations Architecture bodies Entity declarations Behavioral descriptions Wait statements Delta delays Process statements Conditional signal assignment Selected signal assigment Structural descriptions Library and library clauses Procedures Procedure parameters Signal parameters Default values Unconstrained array parameter Functions Package declarations and bodies Subprograms in package Use clauses Resolved signals and subtypes Resolved signals and ports Parameterizing behavior Parameterizing structure
|
Unconstrained Array Parameters
In an earlier chapter we described unconstrained array types, in which the index range of the array was left unspecified using the box (<>) notation. For such a type, we constrain the index bounds when we create an object, such as a variable or a signal. Another use of an unconstrained array type is as the type of a formal param- eter to procedure. This use allows us to write a procedure in a general way, so that it can operate on array values of any size or with any range of index values. When we call the procedure and provide a constrained array as the actual parameter, the index bounds of the actual array are used as the bounds of the formal array parameter.
Want To have highly paid VLSI jobs ?? then you may contact at
Contact : webmaster@freehost7com
Figure 5-6 is a procedure that finds the index of the first bit set to 1 in a bit vector. The formal parameter v is of type bit_vector, which is an unconstrained array type. Note that in writing this procedure, we do not explicitly refer to the index bounds of the formal parameter v, since they are not known. Instead, we use the 'range attribute.
procedure find_first_set ( v : in bit_vector; found : out boolean; first_set_index : out natural ) is begin for index in v'range loop if v(index) = '1' then found := true; first_set_index := index; return; end if; end loop; found := false; end procedure find_first_set;
When the procedure is executed, the formal parameters stand for the actual parameters provided by the caller. So if we call this procedure as follows:
variable int_req : bit_vector (7 downto 0); variable top_priority : natural; variable int_pending : boolean;
find_first_set ( int_req, int_pending, top_priority ); v'range returns the range 7 downto 0, which is used to ensure that the loop pa- rameter index iterates over the correct index values for v. If we make a different call:
variable free_block_map : bit_vector(0 to block_count1); variable first_free_block : natural; variable free_block_found : boolean;
find_first_set ( free_block_map, free_block_found, first_free_block );
v'range returns the index range of the array free_block_map, since that is the actual
|