当前位置:网站首页>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&#
边栏推荐
- Vivado IP核之RAM Block Memery Generator
- 虹科教您 | 想进入TSN领域?虹科教您如何搭建TSN测试系统
- Learning notes of bit operation
- 什么是撞库及撞库攻击的基本原理
- Official tutorial redshift 09 camera
- STP生成树原理及选举规则举例
- Vivado IP核之复数浮点数乘法 Floating-point
- [beauty of software engineering - column notes] 14 | project management tools: all management problems should be considered whether they can be solved by tools
- Leetcode 26. delete duplicates in the ordered array
- Computer network interview questions
猜你喜欢

Leetcode 35. search insertion location

Leetcode 7. integer inversion

虹科案例 | PAC:一种整合了softPLC控制逻辑、HMI和其他服务功能的集成控制解决方案
![[leetcode skimming] array 2 - binary search](/img/50/c006cbe5a91774c99eb782d9203fa0.png)
[leetcode skimming] array 2 - binary search

SQL Developer图形化窗口创建数据库(表空间和用户)

NoClassDefFoundError processing
![[leetcode skimming] array 1 - double pointer](/img/c3/a671395e20fad58f1c7f6abc6e1a39.png)
[leetcode skimming] array 1 - double pointer

浅谈缺陷描写样式

Navicat for Oracle Cannot create oci environment

基于udp通信的在线多人聊天室
随机推荐
[beauty of software engineering - column notes] 20 | how to deal with the headache of requirement change?
电脑系统没有standard tcp/ip port端口的处理操作
虹科分享 | 带你全面了解“CAN总线错误”(三)——CAN节点状态与错误计数器
NoClassDefFoundError processing
c语言问题
Navicat for Oracle Cannot create oci environment
虹科分享 | 测试与验证复杂的FPGA设计(2)——如何在IP核中执行面向全局的仿真
官方教程 Redshift 05 system参数详细解释
虹科Automation softPLC | MoDK运行环境与搭建步骤(1)——运行环境简介
Merkle Tree 存在性功能第一次修改
Webshell管理工具的流量特征
基于FPGA的4位减法器设计及仿真代码
官方教程 Redshift 08 Light
Ue5 light shadow basic shadow full resolution sawtooth shadow solution lumen
右值引用和移动构造
Official tutorial redshift 05 system parameter detailed explanation
虹科Automation softPLC | 虹科KPA MoDK运行环境与搭建步骤(3)——MoDK例程测试
虹科教您 | 想进入TSN领域?虹科教您如何搭建TSN测试系统
官方教程 Redshift 01 基础理论知识和基础特性学习
DDoS详解