1、if语句
语法格式
if 表达式 then 声明;
elsif 表达式 then 声明;
else 声明;
end if;
例:
process(a)
begin
if a="00" then f<=d0;
elsif a="01" then f<=d1;
elsif a="10" then f<=d2;
else f<=d3;
end if;
end process;
第一种if语句
语句格式:
if 条件句 then
顺序语句
end if
例:
if(a>b) then
out<=‘1‘;
end if;
第二种if语句
语句格式:
if 条件句 then
顺序语句
else
顺序语句
end if
例:
if(a>b) then
out<=‘1‘;
else
out<=‘0‘;
end if;
第三种if语句
语法格式:
if 条件句 then
顺序语句;
elsif 条件句 then 顺序语句;
elsif 条件语句 then 顺序语句;
else 顺序语句;
end if;
2.case-when语句
作用:根据条件进行相应的赋值操作。
语法格式:
case 表达式 is
when 选择值 =>顺序语句
when 选择值=>顺序语句
...
end case;
case语句根据满足的条件直接选择多项顺序语句的一项执行=>不是信号赋值符号,其意思等价于"THEN"
例:
library ieee;
use ieee.std_logic_1164.all;
entity mux41 is
port(s1,s2:in std_logic;
a,b,c,d:in std_logic;
z:out std_logic
);
end entity mux41;
architecture bhv of mux41 is
signal s:std_logic_vector(1 downto 0);
begin
s<s1&s2;
process(s1,s2,a,b,c,d)
begin
case s is
when "00"=> z<=a;
when "01"=> z<=b;
when "10"=> z<=c;
when "11"=> z<=d;
when others=> z<=‘x‘;
end case;
end process;
end bhv;
原文:https://www.cnblogs.com/lhkhhk/p/11823250.html