• VHDL之concurrent之generate


    GENERATE

      It is another concurrent statement (along with operators and WHEN). It is equivalent to the sequential statement LOOP in the sense that it

    allows a section of code to be repeated a number of times, thus creating several instances of the same assignments. 

      1)  FOR / GENERATE: notice that GENERATE must be labeled.

    label: FOR identifier IN range GENERATE
      (concurrent assignments)
    END GENERATE;

      2)  IF/GENERATE

       An irregular form is also available, which uses IF/GENERATE (with an IF equivalent; recall that originally IF is a sequential statement). Here ELSE is not allowed.  

    label1: FOR identifier IN range GENERATE
      ...
    label2: IF condition GENERATE
      (concurrent assignments)
    END GENERATE;
    ...
    END GENERATE;

    Example 1

    SIGNAL x: BIT_VECTOR (7 DOWNTO 0);
    SIGNAL y: BIT_VECTOR (15 DOWNTO 0);
    SIGNAL z: BIT_VECTOR (7 DOWNTO 0);
    ...
    G1: FOR i IN x'RANGE GENERATE
      z(i) <= x(i) AND y(i+8);
    END GENERATE;

    Example 2  Vector Shifter

      The output vector must be a shifted version of the input vector, with twice its width and an amount of shift specified by another input.

    For example, if the input bus has width 4, and the present value is ‘‘1111’’, then the output should be one of the lines of the following

    matrix (the original vector is underscored):

      row(0): 0 0 0 0 1 1 1 1

      row(1): 0 0 0 1 1 1 1 0

      row(2): 0 0 1 1 1 1 0 0

      row(3): 0 1 1 1 1 0 0 0

      row(4): 1 1 1 1 0 0 0 0

    1 ------------------------------------------------
    2 LIBRARY ieee;
    3 USE ieee.std_logic_1164.all;
    4 ------------------------------------------------
    5 ENTITY shifter IS
    6 PORT ( inp: IN STD_LOGIC_VECTOR (3 DOWNTO 0);
    7     sel: IN INTEGER RANGE 0 TO 4;
    8     outp: OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
    9 END shifter;
    10 ------------------------------------------------
    11 ARCHITECTURE shifter OF shifter IS
    12   SUBTYPE vector IS STD_LOGIC_VECTOR (7 DOWNTO 0);
    13   TYPE matrix IS ARRAY (4 DOWNTO 0) OF vector;
    14   SIGNAL row: matrix;
    15 BEGIN
    16   row(0) <= "0000" & inp;
    17   G1: FOR i IN 1 TO 4 GENERATE
    18     row(i) <= row(i-1)(6 DOWNTO 0) & '0';
    19   END GENERATE;
    20   outp <= row(sel);
    21 END shifter;
    22 ------------------------------------------------
  • 相关阅读:
    P3254 圆桌问题
    P4868 Preprefix sum
    2021sd省选游记
    P4145 上帝造题的七分钟2 / 花神游历各国
    P2801 教主的魔法
    P4147 玉蟾宫(悬线法)
    P1944 最长括号匹配
    CF1214D Treasure Island
    Loadrunner与kylinPET的能力对比测试--web动态请求
    Summer——从头开始写一个简易的Spring框架
  • 原文地址:https://www.cnblogs.com/mengdie/p/4518568.html
Copyright © 2020-2023  润新知