顺序语句及并行语句.docVIP

  • 26
  • 0
  • 约2.21千字
  • 约 4页
  • 2017-05-13 发布于北京
  • 举报
顺序语句及并行语句

顺序语句与并行语句中你应该知道的  2007-11-13 22:18 顺序语句是指仿真角度看,每一条语句的执行是按书写顺序进行的。顺序语句只能在进程、函数、过程内部使用。 VHDL有一下几种基本顺序语句:变量赋值语句、流程控制语句、等待语句、子程序调用语句、返回语句、空操作语句。常用的顺序语句有if_then_else,case_when,loop_for等。 并行语句是硬件描述语言与编写软件程序的最大区别所在,所有并行语句在结构体中的执行都是同时进行,即它们的执行与语句书写的顺序无关。这种并行性是由硬件本身的并行性所决定的,即一旦电路接通电源,他的各部分就会按照事先设计好的方案同时工作。 VHDL有一下几种主要并行语句:进程语句、块语句、并行信号赋值语句、元件例化语句、生成语句、并行过程调用语句。 大家要注意,把进程语句(process)当作并行语句,是因为进程与进程间的执行是并行的(一个architecture里的不同process是同时执行的)。但进程内部是顺序执行的,大家千万不要因为进程语句是并行语句就误认为是同时执行的。 本人刚开始学习时也困惑过一阵,为什么有些有些顺序语句在实际使用时却表现出“并行特性“。这有两个程序和大家分享一下使大家少走弯路。 程序(1) library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity test is port (clk,reset:in std_logic ); end test; architecture Behavioral of test is signal a,b:integer range 0 to 7; begin process(reset,clk) begin if reset=1 then a=1; b=0; elsif rising_edge(clk) then if a=1 then --(a) b=3; --(a) end if; --(a) if b=3 then --(b) a=6; --(b) end if; --(b) end if; end process; end Behavioral; 程序(2)library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity test is port (clk,reset:in std_logic ); end test; architecture Behavioral of test is signal a,b:integer range 0 to 7; begin process(reset,clk) begin if reset=1 then a=1; b=0; elsif rising_edge(clk) then if b=3 then --(b) a=6; --(b) end if; --(b) if a=1 then --(a) b=3; --(a) end if; --(a) end if; end process; end Behavioral; 可以说两个程序几乎一样,只是将a if_then语句 和 b if_then 语句整体调换位置颠倒。但前面提到if_then_else语句是顺序语句,执行会受语句顺序影响,即两个程序执行结果不一样。但仿真发现,进程1与进程2 的结果是一模一样波形如下图。本人当时很困惑,后来看了一

文档评论(0)

1亿VIP精品文档

相关文档