当前位置:网站首页>命名块 verilog
命名块 verilog
2022-07-02 03:02:00 【嗒曦】
命名块
我们可以给块语句结构命名。
命名的块中可以声明局部变量,通过层次名引用的方法对变量进行访问。
仿真代码如下:
实例
`timescale 1ns/1ns
module test;
initial begin: runoob //命名模块名字为runoob,分号不能少
integer i ; //此变量可以通过test.runoob.i 被其他模块使用
i = 0 ;
forever begin
#10 i = i + 10 ;
end
end
reg stop_flag ;
initial stop_flag = 1'b0 ;
always begin : detect_stop
if ( test.runoob.i == 100) begin //i累加10次,即100ns时停止仿真
$display("Now you can stop the simulation!!!");
stop_flag = 1'b1 ;
end
#10 ;
end
endmodule
仿真结果如下:

命名的块也可以被禁用,用关键字 disable 来表示。
disable 可以终止命名块的执行,可以用来从循环中退出、处理错误等。
与 C 语言中 break 类似,但是 break 只能退出当前所在循环,而 disable 可以禁用设计中任何一个命名的块。
仿真代码如下:
实例
`timescale 1ns/1ns
module test;
initial begin: runoob_d //命名模块名字为runoob_d
integer i_d ;
i_d = 0 ;
while(i_d<=100) begin: runoob_d2
# 10 ;
if (i_d >= 50) begin //累加5次停止累加
disable runoob_d3.clk_gen ;//stop 外部block: clk_gen
disable runoob_d2 ; //stop 当前block: runoob_d2
end
i_d = i_d + 10 ;
end
end
reg clk ;
initial begin: runoob_d3
while (1) begin: clk_gen //时钟产生模块
clk=1 ; #10 ;
clk=0 ; #10 ;
end
end
endmodule
仿真结果如下:
由图可知,信号 i_d 累加到 50 以后,便不再累加,以后 clk 时钟也不再产生。
可见,disable 退出了当前的 while 块。

需要说明的是,disable 在 always 或 forever 块中使用时只能退出当前回合,下一次语句还是会在 always 或 forever 中执行。因为 always 块和 forever 块是一直执行的,此时的 disable 有点类似 C 语言中的 continue 功能。
边栏推荐
- [JSON] gson use and step on the pit
- QT environment generates dump to solve abnormal crash
- Use the open source project [banner] to achieve the effect of rotating pictures (with dots)
- Baohong industry | four basic knowledge necessary for personal finance
- Mathematical calculation in real mode addressing
- CoordinatorLayout + TabLayout + ViewPager2(里面再嵌套一个RecyclerView),RecyclerView的滑动冲突解决
- 设置状态栏颜色
- QT使用sqllite
- [question 008: what is UV in unity?]
- 3124. Word list
猜你喜欢
![[road of system analyst] collection of wrong topics in enterprise informatization chapter](/img/c4/0bb4823ca85c440b4e0587a91b2585.jpg)
[road of system analyst] collection of wrong topics in enterprise informatization chapter
![[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)](/img/96/8c4baa1dd8e35e2cab67461e7c447b.jpg)
[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)
![寻找重复数[抽象二分/快慢指针/二进制枚举]](/img/9b/3c001c3b86ca3f8622daa7f7687cdb.png)
寻找重复数[抽象二分/快慢指针/二进制枚举]

AcWing 245. Can you answer these questions (line segment tree)

Delphi xe10.4 installing alphacontrols15.12

Analysis of FLV packaging format

QT environment generates dump to solve abnormal crash

使用 useDeferredValue 进行异步渲染

MongoDB非关系型数据库

Baohong industry | what misunderstandings should we pay attention to when diversifying investment
随机推荐
GB/T-2423.xx 环境试验文件,整理包括了最新的文件里面
[road of system analyst] collection of wrong topics in enterprise informatization chapter
STM32__05—PWM控制直流电机
Coordinatorlayout + tablayout + viewpager2 (there is another recyclerview nested inside), and the sliding conflict of recyclerview is solved
Cache processing scheme in high concurrency scenario
PMP personal sprint preparation experience
C shallow copy and deep copy
OSPF LSA message parsing (under update)
LFM signal denoising, time-frequency analysis, filtering
32, 64, 128 bit system
Missing numbers from 0 to n-1 (simple difficulty)
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
Is bone conduction earphone better than traditional earphones? The sound production principle of bone conduction earphones is popular science
Soul app released the annual report on generation Z behavior: nearly 20% of young people love shopping in the vegetable market
Mmsegmentation series training and reasoning their own data set (3)
How to run oddish successfully from 0?
Basic 01: print string
Use the open source project [banner] to achieve the effect of rotating pictures (with dots)
Divorce for 3 years to discover the undivided joint property, or
GB/T-2423. XX environmental test documents, including the latest documents