3,verilog仿真语法模版_循环

Loops

1.递减for循环语法

   // Below is a usage to repeat a statement multiple times in a loop

   // If you want to instantiate a module use for-generate template

   integer <var>;

   for (<var> = <initial_value>; <var> >= <final_value>; <var>=<var>-1) begin

      <statement>;

        end

2.递增for循环语法  

// Below is a usage to repeat a statement multiple times in a loop

   // If you want to instantiate a module use for-generate template

   integer <var>;

   for (<var> = <initial_value>; <var> <= <final_value>; <var>=<var>+1) begin

      <statement>;

   end

3.forever循环语法  

 forever begin

      <statement>;

         end

4.repeat循环语法  

 repeat (<value>) begin

      <statements>;

   end

5.while循环语法  

 while (<condition>) begin

      <statement>;

   end

6.disable循环语法

 disable <loop_identifier>;

7.循环语法举例

// information for Verilog Looping Statements (i.e. while, repeat, forever, for, etc.)

====================================================

/ /Repeat - A repeat loop is generally the easiest construct if it is desired

//          to perform an action a known, finite number of times and the loop

//          variable is not needed for the function.

//

//          Example: The following example will apply random data to the

//                   DATA_IN signal 30 times at each clock signal.

initial begin

   repeat (30) begin

      @(posedge CLK);

      #1 DATA_IN = $random;

   end

end



// While - The while loop is a good way to create a conditional loop that will

//         execute as long as a condition is met.

//

//         Example: The following example will read from a FIFO as long as the

//                  EMPTY flag is true.



initial begin

   while (EMPTY==1'b0) begin

      @(posedge CLK);

      #1 read_fifo = 1'b1;

   end



// for - The for loop is generally used when a finite loop is desired and it

//       is necessary to key off the loop variable.  Depending on how the for

//       condition is created, an incrementing or decrementing loop can be created.

//

//       Example: The following will assign a 1'b0 to each bit in the 32 bit

//                DATA signal at time zero. An incrementing for loop will be used.



parameter WIDTH=32;

reg [WIDTH-1:0] DATA;

integer i;

initial

   for (i=0; i<WIDTH; i=i+1)

      DATA[i] = 1'b0;



// forever - The forever loop is a construct generally used to create an infinite

//           loop for simulation.

//

//           Example: The following will create a clock using a forever loop with

//                    a period of 10 ns and a 50% duty cycle.



`timescale 1ns/1ps

initial

   forever begin

      CLK = 1'b0;

      #5 CLK = 1'b1;

      #5;

   end



// Disable - Any loop can be disabled by using the disable construct.  In order

//           to disable a loop, a loop identifier or label must be used on the

//           loop to be disabled.

//

//           Example: The following will stop a clock created in a forever loop

//                    if a signal called stop_clock is 1'b1.



`timescale 1ns/1ps

initial

   forever begin : clock_10ns

      CLK = 1'b0;

      #5 CLK = 1'b1;

      #5;

   end



always @(posedge stop_clock)

   if (stop_clock)

      disable clock_10ns;

点赞加关注博主(ID:FPGA小飞)的博文,咱们一起学习、一起进步吧~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Verilog是一种硬件描述语言(HDL),广泛应用于数字电路设计和仿真。借助Verilog,设计人员可以使用代码描述电路的行为和结构,以及进行功能验证和综合。 Verilog IEEE官方标准手册是Verilog的官方规范,2005是其发行的年份。该手册详细规定了Verilog语法、语义和设计规则,并提供了标准库和常见硬件元素的代码模板。这个手册是Verilog设计人员的主要参考资源,以确保他们的设计符合语法规范并能被正确综合和仿真Verilog IEEE官方标准手册-2005包括以下主要内容: 1. Verilog基本语法:包括模块声明和端口定义、数据类型、运算符、控制结构等。 2. 模块层次结构:描述模块的嵌套关系、实例化其他模块以及信号的连接。 3. 行为建模:描述电路的行为,包括使用时序或组合逻辑来定义电路的功能。 4. 结构建模:描述电路的结构,如寄存器、多路器、加法器等常见硬件元素。 5. 仿真和测试:使用Verilog进行电路功能验证和时序仿真,以及运行测试向量。 6. 综合和优化:将Verilog代码综合成硬件电路,并优化电路的面积、功耗、时序等参数。 7. 验证和调试:通过调试技术来验证Verilog设计的正确性,并解决可能出现的问题。 使用Verilog IEEE官方标准手册-2005,设计人员可以遵循标准规范,编写符合语法Verilog代码,并通过仿真和综合验证设计的正确性。这个手册对于学习Verilog和进行Verilog设计的工程师非常有用,能够提供设计的一致性和规范性,提高设计的可靠性和可维护性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值