如何更改为when语句

时间:2016-09-21 13:35:27

标签: vhdl

有人可以帮助我如何将此vhdl代码更改为使用'when'语句吗?

这是我写的代码:

library IEEE;
use IEEE.std_logic_1164.all;

entity sel2_1 is
   port( A, B, SEL : in std_logic;
         outsgnl    : out std_logic);
end sel2_1;

architecture EX1 of sel2_1 is
begin
   outsgnl <= (not SEL and A) or (SEL and B);
end EX1;

模拟结果如下: simulation

1 个答案:

答案 0 :(得分:2)

在不同的VHDL分配中使用关键字时。假设SEL仅为'0''1',您可以简单地替换

outsgnl <= (not SEL and A) or (SEL and B);

通过选择的信号分配,通常称为/ select assignment

with SEL select outsgnl <=
    A when '0',
    B when others;

或者,您可以使用条件信号分配,通常称为/ else

outsgnl <= A when SEL = '0' else B;