如何将std_logic_vector的一位分配给1,其他的分配给0

时间:2018-08-27 00:37:42

标签: vhdl decoder

我从外部print(str(ord(character)) + ' ', end='') 接收二进制值,该二进制值表示应设置为1且其他设置为0的位。据我了解,它是解码器,但使用“ when”语句解决此问题将花费了很多代码,而且它不可重新配置。

示例:

#frame {
    color: white;
}

1 个答案:

答案 0 :(得分:0)

有很多方法可以做到这一点。可以模拟所有(语法和语义上有效的)方式。有些可以合成,有些则不能,但是这取决于您的合成器,很难说。首先,让我们将output重命名为resultoutput不是VHDL语言的关键字,而是std.textio包中定义的标准输出流的名称。因此最好避免将其用作用户标识符。

  1. 具有可变位和寻址位的进程(练习:研究聚合符号并了解(others => '0')):

    process(number)
        variable tmp: std_logic_vector(255 downto 0);
    begin
        tmp := (others => '0');
        tmp(to_integer(unsigned(number))) := '1';
        result <= tmp;
    end process;
    
  2. 等效于没有中间变量(练习:研究信号分配并了解其工作原理):

    process(number)
    begin
        result <= (others => '0');
        result(to_integer(unsigned(number))) <= '1';
    end process;
    
  3. 在VHDL 2002中使用桶形移位器进行处理(可能仍不受您的工具支持):

    architecture foo of bar is
        ...
        constant one: std_logic_vector(255 downto 0) := (0 => '1', others => '0');
        ...
    begin
        ...
        process(number)
        begin
            result <= one sll to_integer(unsigned(number));
        end process;
        ...
    end architecture foo;
    
  4. 在VHDL 2002中使用桶形移位器进行并发信号分配(练习:了解并发信号分配是过程,请想象等效过程):

    architecture foo of bar is
        ...
        constant one: std_logic_vector(255 downto 0) := (0 => '1', others => '0');
        ...
    begin
        ...
        result <= one sll to_integer(unsigned(number));
        ...
    end architecture foo;