首页 > 其他 > 详细

流程控制语句

时间:2019-11-08 22:42:38      阅读:93      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!