当前位置:网站首页>Verilog中for语句的使用
Verilog中for语句的使用
2022-07-29 05:25:00 【qq_46475176】
在C语言中,经常用到for循环语句,但在硬件描述语言中for语句的使用较C语言等软件描述语言有较大的区别。
在Verilog中除了在Testbench(仿测试激励)中使用for循环语句外,在Testbench中for语句在生成激励信号等方面使用较普遍,但在RTL级编码中却很少使用for循环语句。主要原因就是for循环会被综合器展开为所有变量情况的执行语句,每个变量独立占用寄存器资源,每条执行语句并不能有效地复用硬件逻辑资源,造成巨大的资源浪费。简单的说就是;for语句循环几次,就是将相同的电路复制几次,因此循环次数越多,占用面积越大,综合就越慢。
在RTL硬件描述中,遇到类似的算法,推荐的方法是先搞清楚设计的时序要求,做一个rea型计数器。在每个时钟沿累加,并在每个时钟沿判断计数器情况,做相应的处理,能复用的处理模块尽量复用,即使所有的操作不能复用,也采用case语句展开处理。
对于下面的for循环语句:
1 for(i=0;i<16;i++)
2 DoSomething();
可以采用如下代码实现:
reg [3:0] counter;
always @(posedge clk)
if(syn_rst)
counter<=4'b0;
else
counter<=counter+1:
always @(posedge clk)
begin
case(counter)
4'b0000:
4'b0001:
......
default:
endcase
end
另外,有几个语法的细节需要注意一下。for(i&#
边栏推荐
- [beauty of software engineering - column notes] 20 | how to deal with the headache of requirement change?
- 虹科案例 | PAC:一种整合了softPLC控制逻辑、HMI和其他服务功能的集成控制解决方案
- Leetcode 876. Intermediate node of linked list
- Vivado IP核之浮点数乘除法 Floating-point
- MerkleTree 构建QT实现UI
- Single chain surface test questions
- [beauty of software engineering - column notes] 14 | project management tools: all management problems should be considered whether they can be solved by tools
- 电脑鼠标右键单击总是转圈圈怎么回事
- FIR滤波器设计(2)——Vivado调用IP核设计FIR滤波器
- 软件测试的优势有哪些?看看你了解多少.....
猜你喜欢
五、 无线通信网
Dynamic planning summary
Leetcode 19. delete the penultimate node of the linked list
虹科分享 | 如何测试与验证复杂的FPGA设计(1)——面向实体或块的仿真
虹科为您分享EtherCAT demo,教您如何从其他协议快速过渡到EtherCAT工业总线
官方教程 Redshift 03 各种GI的参数和常规使用说明
Leetcode 13. Roman numeral to integer
Leetcode 189. rotation array
Vivado IP核之浮点数加减法 Floating-point
Leetcode - Tips
随机推荐
Vivado IP核之浮点数开方 Floating-point
虹科分享 | 测试与验证复杂的FPGA设计(2)——如何在IP核中执行面向全局的仿真
虹科案例 | PAC:一种整合了softPLC控制逻辑、HMI和其他服务功能的集成控制解决方案
虹科 | 使用JESD204串行接口高速桥接模拟和数字世界
如何判断业务被DDoS攻击?又会造成哪些危害?
Scanbasepackages scanning range configuration
基于TCP的在线词典
官方教程 Redshift 02 4中GI引擎概述及总结
Webshell管理工具的流量特征
通过os-shell引发的mysql拿shell的思考
Vivado IP核之浮点数乘除法 Floating-point
Leetcode notes 452. minimum number of arrows to burst balloons (medium) 452. detonate balloons with the minimum number of arrows (medium)
Merkle Tree 存在性功能第一次修改
[leetcode brush questions] array 3 - divide and conquer
Leetcode 3. longest substring without repeated characters
day14_单元测试&日期常用类&字符串常用类
虹科分享 | 为什么说EtherCAT是提高控制系统性能的最佳解决方案?
Leetcode 189. rotation array
OSPF理论介绍
官方教程 Redshift 09 Camera