流程控制语句

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;

 3.LOOP语句

a、单个loop语句

[loop标号:] loop

顺序语句

end loop [loop标号];

例:

l2:loop

a:=a+1;

exit l2 when a>10;

end loop l2;

b.for_loop语句

[loop标号:]for 循环变量 in 循环次数范围 loop

顺序语句;

end loop [loop 标号];

例:

library ieee;

use ieee.std_logic_1164.all;

entity jiou is

port(a:in std_logic_vector(7 downto 0);

y:out std_logic

);

end jiou;

architecture bhv of jiou is

signal tmp:std_logic;

begin

process(a)

begin

tmp<='0';

for n in 0 to 7 loop

tmp<=tmp xor a(n);

end loop;

y<=tmp;

end process;

end bhv;

 

 

 

posted on 2019-11-08 21:01  李好123  阅读(195)  评论(0编辑  收藏  举报