当前位置:网站首页>命名块 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 功能。
边栏推荐
- Use usedeferredvalue for asynchronous rendering
- JS introduction < 1 >
- 2022-2028 global human internal visualization system industry research and trend analysis report
- 使用 useDeferredValue 进行异步渲染
- 实现一个自定义布局的扫码功能
- STM32__ 05 - PWM controlled DC motor
- Baohong industry | what misunderstandings should we pay attention to when diversifying investment
- [staff] pitch representation (treble clef | C3 60 ~ B3 71 pitch representation | C4 72 pitch representation | C5 84 pitch representation)
- Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field
- 2022-2028 global deep sea generator controller industry research and trend analysis report
猜你喜欢
MongoDB非關系型數據庫
QT implementation interface jump
A list of job levels and salaries in common Internet companies. Those who have conditions must enter big factories. The salary is really high
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
What is the principle of bone conduction earphones and who is suitable for bone conduction earphones
2022-2028 global human internal visualization system industry research and trend analysis report
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
浅谈线程池相关配置
[JVM] detailed description of the process of creating objects
批量检测url是否存在cdn—高准确率
随机推荐
寻找重复数[抽象二分/快慢指针/二进制枚举]
[punch in questions] integrated daily 5-question sharing (phase II)
[staff] the direction of the symbol stem and the connecting line (the symbol stem faces | the symbol stem below the third line faces upward | the symbol stem above the third line faces downward | the
el-table的render-header用法
What is hybrid web containers for SAP ui5
Mathematics in Sinorgchem: computational geometry
C reflection practice
Calculation of page table size of level 2, level 3 and level 4 in protection mode (4k=4*2^10)
2022-2028 global aluminum beverage can coating industry research and trend analysis report
Face++ realizes face detection in the way of flow
Golang configure export goprivate to pull private library code
PMP personal sprint preparation experience
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]
How to create an instance of the control defined in SAP ui5 XML view at runtime?
Soul app released the annual report on generation Z behavior: nearly 20% of young people love shopping in the vegetable market
Realize the code scanning function of a custom layout
[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)
Addition without addition, subtraction, multiplication and division (simple difficulty)
Kibana controls es
[road of system analyst] collection of wrong topics in enterprise informatization chapter