当前位置: 代码迷 >> 综合 >> 005 程序声明和控制流(Procedural Statements And Control Flow)
  详细解决方案

005 程序声明和控制流(Procedural Statements And Control Flow)

热度:38   发布时间:2024-02-27 03:13:29.0

程序声明

  • initial:仿真开始初始化,仅执行1次
  • final:仿真结束执行
  • always:SV中新引入always_comb, always_latch, always_ff
  • task:任务
  • function:函数

选择声明

unique、priority

可加在 if … else … if前,表示一定意义,条件分支不全,匹配不到会报错

  • unique:条件分支不能有重复
  • priority:条件分支有优先级,按照顺序执行
module unique_priority ();byte a = 0;// unique
always @ (*)
begin unique if ((a==0) || (a==1)) begin$display("Unique if : 0 or 1"); end else if (a == 2) begin$display("Unique if : 2"); end else if (a == 4) begin$display("Unique if : 4"); end
end
// priority
always @ (*)
beginpriority if (a[2:1]==0) begin$display("Priority if : 0 or 1"); end else if (a[2] == 0) begin$display("Priority if : 2 or 3"); end else  begin$display("Priority if : 4 to 7"); end
end
// unique case
always @ (*)
beginunique case(a) 0,1: $display("Unique Case 0 or 1");2  : $display("Unique Case 2");4  : $display("Unique Case 4");endcase
end
// priority case
always @ (*)
beginpriority casez(a) 3'b00?: $display("Priority Casez 0 or 1");3'b0??: $display("Priority Casez 2 or 3");endcase
end
// unique case inside
always @ (*)
beginunique case(a) inside[0 : 3]: $display("Unique Case inside 0 to 3");2  : $display("Unique Case inside 2");4  : $display("Unique Case inside 4");endcase
endinitial beginrepeat (7) begin#1  a ++;end#1  $finish;
endendmodule
 Unique if : 0 or 1Unique Case 0 or 1Priority Casez 0 or 1Unique Case inside 0 to 3Unique if : 2Unique Case 2Priority Casez 2 or 3Warning: More than one conditions match in 'unique case' statement."unique_priority.sv", line 47,. Line    48 &    49 are overlapping at time   2.Unique Case inside 0 to 3Priority if : 2 or 3Warning: No condition matches in 'unique if' statement."unique_priority.sv", line 8, at time   3.Warning: No condition matches in 'unique case' statement."unique_priority.sv", line 30, at time   3.Priority Casez 2 or 3Unique Case inside 0 to 3Unique if : 4Unique Case 4Warning: No condition matches in 'priority case' statement."unique_priority.sv", line 39, at time   4.Unique Case inside 4Priority if : 4 to 7Warning: No condition matches in 'unique if' statement."unique_priority.sv", line 8, at time   5.Warning: No condition matches in 'unique case' statement."unique_priority.sv", line 30, at time   5.Warning: No condition matches in 'priority case' statement."unique_priority.sv", line 39, at time   5.Warning: No condition matches in 'unique case' statement."unique_priority.sv", line 47, at time   5.Warning: No condition matches in 'unique if' statement."unique_priority.sv", line 8, at time   6.Warning: No condition matches in 'unique case' statement."unique_priority.sv", line 30, at time   6.Warning: No condition matches in 'priority case' statement."unique_priority.sv", line 39, at time   6.Warning: No condition matches in 'unique case' statement."unique_priority.sv", line 47, at time   6.Priority if : 4 to 7Warning: No condition matches in 'unique if' statement."unique_priority.sv", line 8, at time   7.Warning: No condition matches in 'unique case' statement."unique_priority.sv", line 30, at time   7.Warning: No condition matches in 'priority case' statement."unique_priority.sv", line 39, at time   7.Warning: No condition matches in 'unique case' statement."unique_priority.sv", line 47, at time   7.

循环

  • do while
  • for
  • foreach

跳转

  • break
  • continue
  • return

序列(sequence)

待补充

  相关解决方案