inter 发表于 2010-6-27 23:54:50

十进制可逆计数器代码中VHDL语言的IF语句语法的问题

process(clk)
begin
   if clr='1' then
    count<="0000";
   ELSif clk'event and clk='1' then
   IF COUNT_EN='0' THEN
       if up='1' and count="1001" then
       count<="0000";
       cout<='1';
       elsif up='0' and count="0000" then
       count<="1001";
      cout<='1';
   else
      ifup='1' then
         count<= count+1;
          cout<='0';
      else
         count<= count-1;
         cout<='0';
      end if;
   end if;
   end if;
end if;
end process;

上面是实现可逆十进制计数器的代码,编译、下载都可以得到正确的结果,想问一下:
两个else对应的条件分别是什么?
end if分别结束的是哪个if?
if语句嵌套使用时,能否以end if结束内部的if语句后,用esle执行其他的代码?

usd 发表于 2010-6-28 01:54:48

第一个else对应的条件是COUNT_EN不等于0<br>
第二个else对应的条件是up不等于1<br>
<br>
end if 你可以这么来看,最大的一个if 对应最后面的end if ,依次类推<br>
<br>
end if 是if 语句的结尾,所以不能在用else了<br>
-------------------------------------------------------------------------------------<br>
以上纯属个人观点

UFP 发表于 2010-6-28 03:45:52

只是为了看看自己换的头像换了没,不好意思啊!

VVC 发表于 2010-6-28 05:35:15

二楼说的没错

interi 发表于 2010-6-28 06:17:13

正在学习,看一下,,,

ups 发表于 2010-6-28 07:36:54

2、3楼说的都不错

purpleheart 发表于 2010-9-14 21:37:34

end if 对应的是离他最近的if语句了啊,ifup='1' then
         count&lt;= count+1;
          cout&lt;='0';
      else
         count&lt;= count-1;
         cout&lt;='0';
      end if;

lianzhe 发表于 2010-9-15 10:56:28

2楼说的不对。
第一个else对应的条件是 if up='1' and count="1001"和elsif up='0' and count="0000" 。
第二个else对应的是ifup='1'
可以做一下仿真来验证
页: [1]
查看完整版本: 十进制可逆计数器代码中VHDL语言的IF语句语法的问题