decode.vhd

来自「包括所有常用算法:加权计算」· VHDL 代码 · 共 74 行

VHD
74
字号
--------------------------------------------------------------------------------- Title       : Decoder-- Project     : VHDL Library of Arithmetic Units--------------------------------------------------------------------------------- File        : Decode.vhd-- Author      : Reto Zimmermann  <zimmi@iis.ee.ethz.ch>-- Company     : Integrated Systems Laboratory, ETH Zurich-- Date        : 1998/01/09--------------------------------------------------------------------------------- Copyright (c) 1998 Integrated Systems Laboratory, ETH Zurich--------------------------------------------------------------------------------- Description :-- Decodes a binary number into a vector with a '1' at the according position.-- Examples: A = "101" -> Z = "00100000".-------------------------------------------------------------------------------library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;library arith_lib;use arith_lib.arith_lib.all;use arith_lib.arith_utils.all;-------------------------------------------------------------------------------entity Decode is  generic (width : integer := 8);  	-- word width  port (A : in std_logic_vector(log2ceil(width)-1 downto 0);  -- encoded input	Z : out std_logic_vector(width-1 downto 0));  -- output vectorend Decode;-------------------------------------------------------------------------------architecture Behavioral of Decode is  signal Aint : integer;  -- integer  signal Zint : integer;  -- integerbegin  -- type conversion: std_logic_vector -> integer  Aint <= conv_integer(unsigned(A));  -- decoding  Zint <= 2**Aint;  -- type conversion: integer -> std_logic_vector  Z <= std_logic_vector(conv_unsigned(Zint, width));end Behavioral;-------------------------------------------------------------------------------architecture Structural of Decode is    signal Aint : integer;  -- integerbegin  -- type conversion: std_logic_vector -> integer  Aint <= conv_integer(unsigned(A));  -- decoding  dec : for i in 0 to width-1 generate    Z(i) <= '1' when Aint = i else '0';  end generate dec;end Structural;-------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?