在VHDL中,IF...THEN...ELSE是顺序语句,只能出现在行为描述中(进程体或者子程序中);而WHEN...ELSE是并行语句,可以直接出现在结构体中,但却不能出现在行为描述中。
WHEN...ELSE等效于一个进程体为IF...THEN...ELSE语句的进程。
四选一
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mm is
PORT(A,B,C,D: IN STD_LOGIC;
S0,S1:IN STD_LOGIC;
Z: OUT STD_LOGIC);
end ENTITY mm;
architecture bhv of mm is
BEGIN
Z<=A WHEN S0='0' AND S1='0' ELSE
B WHEN S0='0' AND S1='1' ELSE
C WHEN S0='1' AND S1='0' ELSE
D WHEN S0='1' AND S1='1' ELSE
'Z';
END bhv;