当前位置:网站首页>命名块 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 功能。
边栏推荐
- Divorce for 3 years to discover the undivided joint property, or
- Pychart creates new projects & loads faster & fonts larger & changes appearance
- Baohong industry | four basic knowledge necessary for personal finance
- Stack - es - official documents - filter search results
- Multi threaded query, double efficiency
- The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
- Actual battle of financial risk control - under Feature Engineering
- A list of job levels and salaries in common Internet companies. Those who have conditions must enter big factories. The salary is really high
- How to create an instance of the control defined in SAP ui5 XML view at runtime?
- Mmsegmentation series training and reasoning their own data set (3)
猜你喜欢

C reflection practice

Connected block template and variants (4 questions in total)

QT实现界面跳转

How to create an instance of the control defined in SAP ui5 XML view at runtime?

Render header usage of El table

結婚後

Which brand of running headphones is good? How many professional running headphones are recommended

PHP notes - use Smarty to set public pages (include, if, else, variable settings)
![[question 008: what is UV in unity?]](/img/f7/5ee0b18d1fe21ff3b98518c46d9520.jpg)
[question 008: what is UV in unity?]
![[liuyubobobo play with leetcode algorithm interview] [00] Course Overview](/img/1c/c8cab92c74b6658c3ef608c5255f1f.png)
[liuyubobobo play with leetcode algorithm interview] [00] Course Overview
随机推荐
4. Find the median of two positive arrays
Es interview questions
[road of system analyst] collection of wrong topics in enterprise informatization chapter
ZABBIX API creates hosts in batches according to the host information in Excel files
旋转框目标检测mmrotate v0.3.1 学习模型
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]
Which brand of sports headset is better? Bluetooth headset suitable for sports
2022安全员-C证考试题及模拟考试
Special symbols in SAP ui5 data binding syntax, and detailed explanation of absolute binding and relative binding concepts
Start a business
How to develop digital collections? How to develop your own digital collections
[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)
Yyds dry goods inventory accelerating vacuum in PG
实现一个自定义布局的扫码功能
Redis set command line operation (intersection, union and difference, random reading, etc.)
Which brand of running headphones is good? How many professional running headphones are recommended
C reflection practice
2022-2028 global wood vacuum coating machine industry research and trend analysis report
JS <2>
Basic 01: print string