当前位置:网站首页>命名块 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 功能。
边栏推荐
猜你喜欢
結婚後
Mongodb non relational database
What kind of good and cost-effective Bluetooth sports headset to buy
Systemserver service and servicemanager service analysis
Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field
Design details of SAP e-commerce cloud footernavigationcomponent
【JVM】创建对象的流程详解
[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)
Face++ realizes face detection in the way of flow
Baohong industry | 6 financial management models at different stages of life
随机推荐
[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)
CoordinatorLayout + TabLayout + ViewPager2(里面再嵌套一个RecyclerView),RecyclerView的滑动冲突解决
The video number will not be allowed to be put on the shelves of "0 yuan goods" in the live broadcasting room?
QT使用sqllite
Redis cluster
高并发场景下缓存处理方案
STM32__ 05 - PWM controlled DC motor
多线程查询,效率翻倍
How to create an instance of the control defined in SAP ui5 XML view at runtime?
What are the common proxy servers and what are the differences?
Addition without addition, subtraction, multiplication and division (simple difficulty)
QT implementation interface jump
C shallow copy and deep copy
2022-2028 global soft capsule manufacturing machine industry research and trend analysis report
Remote connection to MySQL under windows and Linux system
批量检测url是否存在cdn—高准确率
[untitled]
ZABBIX API creates hosts in batches according to the host information in Excel files
QT uses sqllite
连通块模板及变式(共4题)