Docsity

VHDL Array and Record Manipulation, Slides of Computer Science

Partial preview of the text

Download VHDL Array and Record Manipulation and more Slides Computer Science in PDF only on Docsity!

Composite Data Types and Operations

Array

• EBNF:

array_type <= array ( discrete_range { , … } ) of element_subtype_indication ;

discrete_range <= discrete_subtype_indication | expr (to |downto ) expr discrete_subtype_indication <= type_mark [ range expr ( to |downto ) expr ]

  • Example:
    • type word1 is array (0 to 31) of bit;
    • type word2 is array (31 downto 0) of bit;

**entity coeff_ram is port ( rd, wr : in bit; addr : in coeff_ram_address; d_in : in real; d_out : out real ); end entity coeff_ram;


architecture abstract of coeff_ram is begin**

memory : process is type coeff_array is array (coeff_ram_address) of real; variable coeff : coeff_array; begin -- see next page end process memory;

end architecture abstract;

memory : process is type coeff_array is array (coeff_ram_address) of real; variable coeff : coeff_array; begin for index in coeff_ram_address loop coeff(index) := 0.0; end loop; loop wait on rd, wr, addr, d_in; if rd = '1' then d_out <= coeff(addr); end if; if wr = '1' then coeff(addr) := d_in; end if; end loop; end process memory;

Multi-Dimensional Arrays

type point is array (1 to 3) of real; type matrix is array (1 to 3, 1 to 3) of real;

variable p, q : point; variable transform : matrix;

for i in 1 to 3 loop q(i) := 0.0; for j in 1 to 3 loop q(i) := q(i) + transform(i, j) * p(j); end loop; end loop; Docsity.com

Array Aggregates

  • Examples:

type point is array (1 to 3) of real;

constant origin : point := (0.0, 0.0, 0.0); variable view_point : point := (10.0, 20.0, 0.0);


variable view_point : point := (1=>10.0, 2=>20.0, 3=>0.0); variable coeff : coeff_array := (0=>1.6, 1=>2.3, 2=>1.6, 3 to 63 => 0.0); variable coeff : coeff_array := (0=>1.6,1=>2.3, 2=>1.6, others => 0.0); Docsity.com

modem_controller : process is -- Fig 4-3 on page 91

type symbol is ('a', 't', 'd', 'h', digit, cr, other); type symbol_string is array (1 to 20) of symbol; type state is range 0 to 6; type transition_matrix is array (state, symbol) of state; constant next_state : transition_matrix := ( 0 => ('a' => 1, others => 6), 1 => ('t' => 2, others => 6), 2 => ('d' => 3, 'h' => 5, others => 6), 3 => (digit => 4, others => 6), 4 => (digit => 4, cr => 0, others => 6), 5 => (cr => 0, others => 6), 6 => (cr => 0, others => 6) ); variable command : symbol_string; variable current_state : state := 0;

modem_controller : process is -- previous page begin --... for index in 1 to 20 loop current_state := next_state( current_state, command(index) ); case current_state is --... end case;

end process modem_controller;

entity byte_swap is -- useful example 2

port (input : in halfword; output : out halfword);

end entity byte_swap;


architecture behavior of byte_swap is

begin

swap : process (input) begin output(8 to 15) <= input(0 to 7); output(0 to 7) <= input(8 to 15); end process swap;

end architecture behavior;

Array Attributes

  • A’left(n) the left bound of nth dimension of A
  • A’right(n) the right bound of nth dimension of A
  • A’low(n) the lower bound of nth dimension of A
  • A’high(n) the upper bound of nth dimension of A
  • A’range(n) the range of nth dimension of A
  • A’reverse_range(n) the reverse range of nth dimension of A
  • A’length(n) the length of nth dimension of A
  • A’ascending(n) true if index range of nth dimension of A is ascending range, false otherwise

Example

  • Counting the number of ‘ 1 ’ without knowing the actual size

-- free_map is an array of bits count := 0; for index in free_map'range loop if free_map(index) = '1' then count := count + 1; end if; end loop;

Unconstrained array types

• EBNF:

array_type <= array ( type_mark range

<> ) { , … } ) of element_subtype_indication ;

• Example:

type sample is array (natural range <>) of

integer;

variable short_sample_buf: sample (0 to

Strings

• “string” are pre-defined unconstrained

arrays of type character.

type string is array (positive range<>) of character;

• Examples:

constant LCD_DISPLAY_LEN: positive :=20; subtype LCD_display_string is string(1 to LCD_DISPLAY_LEN); variable LCD_display: LCD_display_string := (others => ‘ ‘); constant ready_message : string := "Ready ";

Bit Vectors

• “bit_vector” are pre-defined unconstrained

arrays of type bit.

type bit_vector is array (natural range <>) of bit;

• Examples:

subtype byte is bit_vector(7 downto 0);

variable channel_busy_register : bit_vector(1 to 4);