idea icon Tip of the Month


We can update you automatically when our Tip of the Month changes.
To receive regular notification of updates to our Tip of the Month section, click here.


Re-using Code Snippets

Code re-use is often thought to mean designing re-usable components as parameterisable design entities. However, code re-use is a valid concept at all levels of abstraction.

In this example, we have a parity generator coded as a for loop. In the commented out code, the parity generator structure is fixed by the range constraint in the loop statement. In the uncommented code, the VHDL range attribute is used to create a parity generator structure which is proportional to the wordlength of the input data (a, in this case).

  signal p_out : std_logic;
  
  process (a)
    variable y : std_logic;
  begin
    y := '0';
  
    -- fixed width code
    -- for i in 0 to 7 loop
    --   y := y xor a(i);
    -- end loop;
  
    -- parameterisable code
    for i in a'RANGE loop
      y := y xor a(i);
    end loop;
  
    p_out <= y;
  
  end process;

The advantage of the parameterisable code is that changes in the wordlength of a do not require a re-write of the parity process. Next month, we will see how use of the range constraint is essential in creating a function with an unconstrained array parameter.


Previous Tips of the Month can be downloaded from here...


wand iconComprehensive VHDL for FPGA / ASIC
chip iconAdvanced VHDL for Synthesis


river sceneDoulos Home Page

Copyright 1995-1996 Doulos
This page was last updated 27th October 1996.

mail iconWe welcome your e-mail comments. Please contact us at: webmaste@doulos.co.uk