VHDL顺序语句(Sequential Statements)

来源:互联网 发布:石器时代625极品人算法 编辑:程序博客网 时间:2024/05/09 04:34

VHDL顺序语句(Sequential Statements)

顺序语句的执行顺序是自顶至下顺序执行。顺序语句有:
Sequential statements execute one after the other from top to bottom. The following are sequential statements:

  • Case
  • If
  • For loop
  • Loop
  • While loop
  • Exit
  • Next
  • Assert
  • Null
  • Report
  • Return
  • Wait
  • Procedure call
  • Signal assignment
  • Variable assignment

Case

Case语句根据选择标准为相关联表达式的值,从一系列可供选择的语句中选择一个来执行。
The case statement selects for execution one of several alternative sequences of statements; the alternative is chosen based on the value of the associated expression.

语法(Syntax)

[ 标号: ] case 表达式 is   when 选择值 => 顺序语句   when 选择值 => 顺序语句   ... end case [ 标号 ]; 选择值 = 选择项 | ... 选择项 = 常量表达式 | 范围 | others   -- 最后选择值
[ label: ] case expression is   when choices => sequential_statements   when choices => sequential_statements   ... end case [ label ]; choices = choice | ... choice = constant_expression | range | others   -- the last choice

说明(Description)

Case语句是按照表达式的值,来多从分支中选择一条来执行。
A case statement is a sequential statement which conditionally executes one branch only, depending on the value of the expression at the top of the case statement

Case语句有一个分支列表,分支以when保留字开始,后面是一个或多个选择值和一个顺序执行语句。
The case statement contains a list of alternatives starting with the when reserved word, followed by one or more choices and a sequence of statements.

一个分支可以包含许多选择值,但其类型必须和case语句头的表达式类型相同。对于每个表达式都必须至少有一个本地静态选择项。每个选择项的值必须唯一(不允许有重复值)。
An alternative may contain several choices, which must be of the same type as the expression appearing in the case statement. For each expression there should be at least one locally static choice. The values of each choice must be unique (no duplication of values is allowed).

当所罗列的选择值没有涵盖表达式多有可能值时,必须使用others来代表剩余的其他情况,因为选择语句必须涵盖所有的可能值。
When all explicitly listed choices do not cover all the alternatives (all the values available for an expression of given type) the others choice must be used because the choice statements must cover all the alternatives.

例程(Example)

C1: case Addr is   when 1 =>      A <= '0';   when 2 =>      A <= '1';     B <= '1';   when 3 =>      A <= '0';     B <= '1';   when others =>     A <= '1';     B <= '0'; end case C1; 

注释(Notes)

  • Case条件表达式必须是一个离散类型或者一个一维字符数组类型,
  • The case expression must be of a discrete type or of a
    one-dimensional array type, whose element type is a character type.

  • 选择项必须涵盖条件表达式的所有可能值,而且每个值仅能出现一次。

  • Every possible value of the case expression must be covered by the
    specified alternatives; moreover, every value may appear only once
    (no duplicates or overlapping of ranges is allowed).

  • when others仅能出现一次,且在所有其他选择项的最后。

  • The when others clause may appear only once and only as the very last
    choice.

If

If语句根据相关的一个或多个条件值,来选择是否执行所包围的顺序语句。
The if statement selects for execution one or none of the enclosed sequences of statements, depending on the value of one or more corresponding conditions.

语法(Syntax)

[ 标号: ] if 条件 then   顺序语句 [ elsif 条件 then   顺序语句 ] [ else   顺序语句 ] end if [ 标号 ]; 
[ label: ] if condition then   sequential_statements [ elsif condition then   sequential_statements ] [ else   sequential_statements ] end if [ label ]; 

说明(Description)

当计算完if(elsif)后的条件语句结果为真或假后,才执行if(elseif)后的语句。 最后的else语句等同于elsif 真。
For the execution of an if statement, the condition specified after if (and any conditions specified after elsif) are evaluated in succession until one evaluates to true or all conditions are evaluated to false. The final else is treated as elsif true then.

当条件为真时,才执行相对应的顺序语句。
If one condition is true, then the corresponding sequence of statements is executed.

例程(Example)

if C = "000" then  Y <= A;elsif C = "010" then  Y <= B;elsif C = "100" or C = "110" then  Y <= C;else  Y <= D;end if; 

Loop

Loop语句表示重复执行所包含的语句。
A loop statement includes a sequence of statements that is to be executed repeatedly.

语法(Syntax)

[ 标号: ] loop   顺序语句end loop [ 标号 ];
[ loop_label: ] loop   sequential_statementsend loop [ loop_label ]; 

说明(Description)

Loop语句用来重复执行语句。
The loop statement contains a sequence of statements, which are supposed to be repeated many times.
Loop语句可以用不同迭代机制,由loop前面的保留字决定。在这种最简单的格式下,没有指定迭代机制,语句将无休止地重复执行。
A loop statement can have several different forms depending on the iteration scheme preceding the reserved word loop (see while loop and for loop). In its simplest form, no iteration scheme is specified and the loop is repeated indefinitely.
退出loop循环,要使用exit语句。Exit语句可以指定特定的条件下退出loop循环。
In order to exit from an infinite loop, an exit statement has to be used. An exit statement can be specified with a condition that must be met to exit the loop (see Exit).

例程(Example)

L1: loop   Clk <= not Clk after 5 ns; end loop L1; 

For Loop

Forloop语句根据loop语句中的条件,重复执行语句。
The for loop statement includes a sequence of statements that is to be executed repeatedly, zero or more times, depending on the condition mentioned in the header of the loop statement.

语法(Syntax)

[ 标号: ] for 循环参数 in 范围 loop   顺序语句 end loop [ 标号 ]; 
[ loop_label: ] for loop_parameter in range loop   sequential_statements end loop [ loop_label ]; 

说明(Description)

只要循环参数(loop parameter)在规定的范围内,loop语句包含的顺序语句将不停地重复执行。
The for loop statement contains a sequence of statements, which are supposed to be repeated as long as the loop parameter remains within the range mentioned in the the header of the loop statement
For loop语句适用于离散范围可以确定迭代次数时。在loop的开始制定循环参数的范围。从范围最左值开始,每次迭代循环参数加一。
The for loop statement is used when a discrete range can define the number of iterations. In the header of the loop the discrete range for the loop parameter is specified. In each iteration the parameter takes one value from the specified range, starting from the leftmost value within the range.
离散范围可以声明为离散类型格式,包括枚举类型。
The discrete range can also be declared in the form of a discrete type, including an enumerated type.

例程(Example)

L1: for Counter in 1 to 8 loop   Output1(Counter) <= Input1(Counter + 2) after 5 ns; end loop L1;

注释(Notes)

  • 不需要特别指定循环参数——循环参数被loop隐式声明。
  • The loop parameter does not need to be specified - the loop
    declaration implicitly declares it.

  • Loop中的循环参数是个常量,不允许在loop内对其赋值。

  • The loop parameter is a constant within a loop, which means that it may not be assigned any values inside the loop.

While Loop

While loop语句根据loop语句头的条件,来决定是否重复执行顺序语句。
A while loop statement includes a sequence of statements that is to be executed repeatedly, zero or more times, depending on the condition mentioned in the header of the loop statement.

语法(Syntax)

[ 标号: ] while 条件 loop  顺序语句end loop [ 标号 ]; 
[ label: ] while condition loop  sequential_statementsend loop [ label ]; 

说明(Description)

While loop语句下,只要条件为真,则不听地执行其包含的顺序语句。
The while loop statement is a sequential statement that contains a sequence of statements, which are supposed to as long as the condition is true.
在执行顺序语句前都要计算条件的值。如果条件值为假,则不执行loop内的语句而执行end loop后的语句。
The condition is evaluated before each execution of the sequence of statements. If the condition is false, the statements in the loop are not executed and the control is passed to the next statement after the end loop clause.

例程(Example)

while I <= 8 loop   Output1(I) <= Input1(I+2) after 5 ns;   I := I + 1; end loop;

注释(Note)

  • 条件在每次迭代前检测,而不知在执行顺序语句的时候。
  • The condition is tested at the start of the loop and once after each
    iteration, but not during the execution of the statements.

Exit

Exit用来完成或退出loop循环。
A sequential statement which is used to finish or exit the execution of an enclosing loop statement.

语法(Syntax)

[ 标号: ] exit [ 循环标号 ] [ when 条件 ];
[ label: ] exit [ loop_label ] [ when condition ];

说明(Description)

Exit语句用来终止loop循环语句。如果exit后有条件,则根据条件值来决定是否执行exit语句。当条件为真时(或者没有条件时)执行exit语句,退出loop循环执行end loop后的语句。
The exit statement terminates entirely the execution of the loop in which it is located. If a condition is placed on the exit statement, then the execution of the exit statement depends on the condition placed at the end of the statement. When the condition is true (or if there is no condition at all) the exit statement is executed and the control is passed to the first statement after the end loop.
Exit语句后的loop标号可有可无,仅适用于那些已标号的loop循环。如果没有标号,则exit语句结束包含exit的loop循环。如果用exit来退出高层的loop循环,则需要使用明确的标号来退出循环。
The loop label in the exit statement is optional and can be used only in case of labeled loops. If no label is present then it is assumed that the exit statement relates to the innermost loop containing it. If an exit from a loop on a higher level of hierarchy is needed then the loop has to be assigned a label, which will be used explicitly in the exit statement.

例程(Example)

L1: loop   L2: for I in B'range loop     if B(I) = 'U' then       exit L1;     end if;     exit when I = M;   end loop L2;   ...end loop L1;

注释(Notes)

  • Exit和next的区别在于。exit退出loop循环,而next语句只是跳过本次迭代。
  • The exit statement is often confused with the next statement. The
    difference between the two is that the exit statement “exits” the
    loop entirely, while the next statement skips to the “next” loop
    iteration (in other words, “exits” only the current iteration of the
    loop).

Next

Next语句用来完成一次loop循环中的迭代,而跳至loop循环顶部。Next后可以有条件语句,来决定是否执行next。
The next statement is used to complete execution of one of the iterations of an enclosing loop statement, making it jump back to the top of that loop. The completion is conditional if the statement includes a condition.

语法(Syntax)

[ 标号: ] next [ 循环标号 ] [ when 条件 ];
[ label: ] next [ loop_label ] [ when condition ];

说明(Description)

Next语句允许跳过一次loop迭代。如果指定的条件值为真,或没有条件,则执行next语句。Next的执行结果为,跳过下面所有的语句至到loop结尾,然后执行下一次迭代的第一条语句。
The next statement allows to skip a part of an iteration loop. If the condition specified after the when reserved word is true, or if there is no condition at all, then the statement is executed. This results in skipping all statements below it until the end of the loop and passing the control to the first statement in the next iteration.
Next语句可以指定他希望影响的loop名。如果没有标号,则仅对包含他的loop有效。
A next statement may specify the name of the loop it is expected to influence. If no label is supported then the statement applies to the innermost enclosing loop.

例程(Example)

L1: loop   k:= 0;  L2: for CountValue in 1 to 8 loop    next when CountValue = N;    -- jump to next itteration of loop L2    if A(k):= 'U' then      next L1;                   -- jump to top of loop L1    end if;    k:= k + 1;  end loop L2;end loop L1;

Assert

Assert 语句用来检测指定的条件是否为真,如果为假则报告错误。
A statement that checks that a specified condition is true and reports an error if it is not.

例程(Syntax)

[ 标号: ] assert 条件   [ report 字符串表达式 ]   [ severity 表达式 ]; 
[ label: ] assert condition   [ report string_expression ]   [ severity expression ]; 

说明(Description)

断定语句有三个可选项,通常都要使用。
The assertion statement has three optional fields and usually all three are used.
断定语句中的条件必须是一个布尔值(真或假)。如果条件为假,叫做发生断言违例。
The condition specified in an assertion statement must evaluate to a Boolean value (true or false). If it is false, it is said that an assertion violation occurred.
Report子句中指定的表达式必须是字符串类型,是发生断言违例时报告的信息。
The expression specified in the report clause must be of predefined type String and is a message to be reported when assertion violation occurred.
如果使用severity子句,则必须指定预定义类型Severity_Level,用来决定断言违例的严重级别。在标准包中指定了Severity_Level以下几种值:注释,警告,错误和失效。如果省略severity子句,则默认指定为错误级别。
If the severity clause is present, it must specify an expression of predefined type Severity_Level, which determines the severity level of the assertion violation. The Severity_Level type is specified in the Standard package and contains the following values: Note, Warning, Error, and Failure. If the severity clause is omitted it is implicitly assumed to be Error.

例程(Example)

assert not (Reset = '0' and Set = '0') report "set-reset conflict" severity Failure;assert result = ExpectedResults report "results differ from expected results" severity Warning;

注释(Notes)

  • 信息只要在条件为假时才显示,所以信息为条件的相面。
  • The message is displayed when the condition is false, therefore the
    message should be an opposite to the condition.

  • 并发断言语句是被动进程,所以可以在实体中指定。

  • The concurrent assertion statement is a passive process and as such can be specified in an entity.
  • 并发断言语句可以不停地监测指定的条件。
  • The concurrent assertion statement monitors the specified condition continuously.
  • 综合语句通常忽略断言语句。
  • Synthesis tools generally ignore assertion statements.

Null

Null语句是不做任何动作的语句,也是门卫信号或访问型变量值。
A statement which does not perform any action. A value of a guarded signal or an access variable.

语法(Syntax)

[ 标号: ] null;  -- 顺序语句null              -- 值
[ label: ] null;  -- sequential_statementnull              -- value

说明(Description)

顺序语句null不执行任何操作。通常在if或case语句中,表示在特定条件下不执行任何操作
The null statement is a sequential statement that does not perform any action and its only function is to pass on to the next statement. It is normally used within an if or case statement as an explicit way to take no action under certain conditions.

Null也可以给守卫信号赋值,表示没有连接。也可以给访问类型变量赋值,通过执行解除分配(Deallocate(ptr))进程。
Null is also the value assigned to a guarded signal to mean disconnection, and the value assigned to an access variable by the procedure Deallocate(ptr).
Null语句不是强制性的,通常不写语句代表他。
The null statement is not mandatory, it is possible to leave a blank instead.

例程(Example)

case Action is   when "001" => C := A and B;   when "010" => Q := null;      -- null value   when "100" => C := not A;   when others => null;          -- null statement end case;

Report
Report语句用来显示信息。
A statement that displays a message.

语法(Syntax)

[ label: ] report string_expression [ severity expression ]; 

说明(Description)

断言语句和报告语句的不同之处,在于报告语句时无条件显示信息的。
The main difference between the report statement and the assertion statement is that the message in the report statement is displayed unconditionally.
Severity子句必须制定其级别。预定义的Severity_Level有:注释,警告,错误和失效。
If the severity clause is present, it must specify an expression of predefined type Severity_Level, which has the values: Note, Warning, Error, and Failure.

例程(Example)

report "End of simulation" severity note;

注释(Notes)

  • 省略severity子句时,默认报告语句的级别为注释(Note)。
  • If the severity clause is omitted in a report statement it is
    implicitly assumed to be Note.

  • 如果有severity子句,则默认为错误(Error)。

  • If the severity clause is used then the default is Error.

Return

返回语句用来完成函数或进程主体的运行。
The return statement is used to complete the execution of the innermost enclosing function or procedure body.

语法(Syntax)

[ label: ] return [ expression ];

说明(Description)
子程序(进程或函数)遇到返回语句是结束。也可导致无条件跳转到子程序的结尾。
The return statement ends the execution of a subprogram (procedure or function) in which it appears. It causes an unconditional jump to the end of the subprogram.
返回语句只允许在子进程或函数中使用。进程中的返回语句可以没有返回值,但是函数中的返回语句必须有一个对应于函数类型的返回值。
The return statement is only allowed in a procedure or function body. The return statement in a procedure may not return any value, while a return in a function must return a value consistent with the return type of the function.

例程(Example)

return X + Y;

Wait
等待语句来暂停一个程序或进程。
The wait statement is a statement that causes suspension of a process or a procedure.

语法(Syntax)

[ 标号: ] wait [ on 信号列表 ] [ until 条件 ] [ for 时间表达式 ]; 
[ label: ] wait [ on signal_list ] [ until condition ] [ for time_expression ]; 

说明(Description)

Wait语句用来暂停执行程序或进程。是否继续程序或进程取决于wait语句指定的条件。
The wait statement suspends the execution of the process or procedure in which it is specified. Resuming the process or procedure depends on meting the condition(s) specified in the wait statement.
等待语句可以没有条件。这种情况下等同于 wait until true,也就是说永远暂停一个进程不再继续。
The syntax of the wait statement allows to use it without any condition. Such a statement is equivalent to wait until true, which suspends a process forever and will never resume.

例程(Example)

Pr1: processbegin  wait until Clk'event and Clk = '1';  Q <= A;  wait for 10 ns;  Q <= B;  wait on C;  Q <= C;  wait;end process;   

注释(Notes)

  • 一个有敏感列表的进程不能有任何wait语句。
  • A process with a sensitivity list may not contain any wait
    statements.

  • wait for, wait on 和 wait时异步的。

  • wait for, wait on and wait are not synthesizable
  • 只有在一个同步时钟延进程中,wait until才是同步的。(如:wait until clock = ‘1’)
  • wait until is synthesizable only when used to synchronize a process
    to a clock edge (e.g.: wait until Clock = ‘1’)

Procedure call
一个程序调用成为程序。
A procedure call calls a procedure.

语法(Syntax)

[ label: ] procedure_name [ ( [ parameter => ] expression, ... 0 ]

说明(Description)

程序参数列表可以按照位置进行传递也可按照命名传递。也可混合使用两种方法(但是位置传递必须在按名传递前)。
The procedure parameters can be listed in both positional association and named association. Both methods can be mixed in one procedure call (although positional association must become before named association).
程序调用可以是顺序语句也可以是并行语句,去决定于他使用的位置。当运行到该位置时,执行顺序程序调用。当程序中的in或者inout参数值改变时,则引发并行程序调用。
A procedure call is a sequential or concurrent statement, depending on where it is used. A sequential procedure call is executed whenever control reaches it, while a concurrent procedure call is activated whenever any of its parameters of in or inout mode changes its value.
建议使用按名传递参数来增强代码可读性,并减少出错风险。
Named association is advised to improve readability and reduce the risk of making mistakes.

例程(Example)

Proc1 (Clock, A, Sig1, Sig2, Var1, Var2, Period);READ (L => BufLine, VALUE => Q);

注释(Notes)

  • 时钟进程中的程序调用可能导致寄存器值改变。
  • A procedure call in a clocked process may result in inferring
    registers from signal assignments within the procedure.

Signal Assignment

信号赋值语句用来修改目标信号。
A signal assignment statement modifies the target signal

语法(Syntax)

[ label: ] target_signal <= [ options ] expression [ after time_expression ] [ when condition ]; options = guarded { in a guarded block } | transport | reject time_expression inertial

说明(Description)

信号赋值语句可以在进程中(顺序语句)或者直接在结构体中(并行语句)。目标信号可以是名也是一个是集合。
A Signal assignment statement can appear inside a process (sequential statement) or directly in an architecture (concurrent statement). The target signal can be either a name (simple, selected, indexed, or slice) or an aggregate.
没有延迟的信号赋值将导致delta delay事件,也就是说当进程完全执行完后将发生该事件。
A signal assignment with no delay (or zero delay) will cause an event after delta delay, which means that the event happens only when all of the currently active processes have finished executing (i.e. after one simulation cycle).
默认延迟模式(inertial)意味着忽略小于延迟的脉冲。Transport意味着赋值在一个纯延迟线上进行。
The default delay mode (inertial) means that pulses shorter than the delay (or the reject period if specified) are ignored. Transport means that the assignment acts as a pure delay line.

VHDL’93 定义的关键字unaffected意味着信号不会被赋新值。大致等同于case语句中的null语句。
VHDL’93 defines the keyword unaffected which indicates a choice where the signal is not given a new assignment. This is roughly equivalent to the use of the null statement within case (see Examples).

例程(Example)

W <= A * B; X <= transport C after Delay;     Y <= '0', '1' after 10 ns, '0' after 20 ns;Z <= reject 2 ns inertial Inp after 10 ns;P <= E1 when C1 else     E2 when C2 else     E3;Q <= D when Enable = '1' else unaffected;

注释(Note)

  • 延迟通常被综合工具忽略。
  • Delays are usually ignored by synthesis tool.

Variable Assignment

变量赋值用来改变变量的当前值。
A variable assignment statement replaces the current value of a variable with a new value specified by an expression.

语法(Syntax)

[ label: ] target_variable := expression; 

说明(Description)

赋给变量的值类型必须和变量的类型相同。语句左边的目标可以是一个变量名也可以是集合。
The expression assigned to a variable must give results of the same type as the variable. The target at the left-hand side of the assignment can be either a name of a variable or an aggregate.
变量名可以是简单名,选择名,索引名或片名。
A variable name can be in the form of simple name, selected name, indexed name or slice name.
如果目标是集合,必须从上下文中得知集合类型。
If the target is an aggregate, then the type of the aggregate must be determinable from the context.

例程(Example)

A := A + 1; (X, Y):= Z;

注释(Notes)

  • 变量赋值立即生效。
  • Variable assignment takes effect immediately.
  • 变量赋值不能指定延迟。
  • Variable assignment can not be specified with a delay.
0 0
原创粉丝点击