Verilog elementary tutorial (13) block statements in Verilog

Li Rui Bowen 2020-11-13 10:28:19
verilog elementary tutorial block statements


Preface

So called block statements , It's just a set of sentences , For example, in initial perhaps always in , Use begin…end perhaps fork…join Package statement , Can be called block statements . There are two kinds of block statements :

  • Serial statement
  • Parallel statements
    Here are the introduction .

Text

Serial statement

Statements use begin and end Keywords to wrap , And will follow the given order , Carry out one by one .
The delay value is processed relative to the execution time of the previous statement . After all statements in the block have been executed , Control can be transferred to other places .

for example :

module design0;
reg [31:0] data;
// "initial" block starts at time 0
initial begin
// After 10 time units, data becomes 0xfe
#10 data = 8'hfe;
$display ("[Time=%0t] data=0x%0h", $time, data);
// After 20 time units, data becomes 0x11
#20 data = 8'h11;
$display ("[Time=%0t] data=0x%0h", $time, data);
end
endmodule

As in the above example , The first sentence starts from begin Start at , after 10 Unit delay , Execute the first statement ;
after 20 Time unit delay , Execute the second statement . This is the statement executed serially .

The above simulation log File for :

[Time=10] data=0xfe
[Time=30] data=0x11

Parallel statements

Parallel blocks can execute statements concurrently , Delay control can be used to provide a chronological order of assignments . By wrapping sentences in fork and join Keyword to start in parallel .
for example :

initial begin
#10 data = 8'hfe;
fork
#20 data = 8'h11;
#10 data = 8'h00;
join
end

The implementation diagram is as follows :

 Parallel statement execution diagram

be located fork…join The statement in is a parallel block of statements , Every sentence in it ( Use a semicolon or begin…end Division ) All in parallel , For example, in the example above fork…join Internal statements , Even if :

#20 data = 8'h11;

In front of , But it's going to be in the statement :

#10 data = 8'h00;

Carry out later .

The picture above also clearly illustrates ,fork Start ,10 Time units , perform :

#10 data = 8'h00;

In a 10 Units of time :

#20 data = 8'h11;

This is parallel execution .

The case where a parallel block contains a serial block

Here's an example :

initial begin
#10 data = 8'hfe;
fork
#20 data = 8'h11;
#10 data = 8'h00;
join
end

In the example above ,fork-join The block will be in 10 Start after executing the statement in units of time . The statements in this block will be executed in parallel , The first statement to be started will be that the data is assigned to 8’h00 The sentence of , Because the delay is in fork-join After startup 10 Time units . In another 10 In time units , The first statement will be started , The data will get 8’h11 Value .

We also said above , Each statement in a parallel block is executed in parallel , Let's explain each sentence here , Use begin…end The statement block of a package also belongs to a statement , That is, block statements .
and begin…end The statements in are executed serially , So there's a case where parallelism involves serialization , Here's an example :

initial begin
#10 data = 8'hfe;
fork
#10 data = 8'h11;
begin
#20 data = 8'h00;
#30 data = 8'haa;
end
join
end

Well understood. , Here's the picture :

 In the case of parallelism involving serialization

sentence :

#10 data = 8'h11;

And :

begin
#20 data = 8'h00;
#30 data = 8'haa;
end

It's a parallel relationship .

fork After the start 10 Time units to execute statements :

#10 data = 8'h11;

And

begin
#20 data = 8'h00;
#30 data = 8'haa;
end

Because the block itself ( The first statement in the block ) Start in parallel with other statements ;
After that, the statements inside the block are executed serially :
in other words fork After 20 Units of time :

//begin
#20 data = 8'h00;
// #30 data = 8'haa;
//end

It goes without saying , In a 30 Time units , That is to say fork After 50 Time unit execution :

//begin
// #20 data = 8'h00;
#30 data = 8'haa;
// end

notes : The emphasis here is on fork After the time point , instead of initial begin After , If you emphasize initial After , You need to count the first sentence 10 Time units .

Block name

Both sequential blocks and parallel blocks can be passed in the keyword begin and fork Add later :name_of_block Named after the . such , You can go to disable Statement refers to the block .

for example :

begin : name_seq
[statements]
end
fork : name_fork
[statements]
join

Review of previous articles

Verilog Junior course (12)Verilog Medium generate block

Verilog Junior course (11)Verilog Medium initial block

Verilog Junior course (10)Verilog Of always block

Verilog Junior course (9)Verilog Operator

Verilog Junior course (8)Verilog Medium assign sentence

Verilog Junior course (7)Verilog Modularization and handling of suspended ports

Verilog Junior course (6)Verilog Module and port

Verilog Junior course (5)Verilog Multidimensional arrays and memory in

Verilog Junior course (4)Verilog Scalars and vectors in

Verilog Junior course (3)Verilog data type

Verilog Junior course (2)Verilog HDL The Elementary Grammar of

Verilog Junior course (1) know Verilog HDL

Abstract layer of chip design and its design style

Verilog as well as VHDL The code principles advocated by

FPGA/ASIC Beginners should learn Verilog still VHDL?

  • WeChat official account : FPGA LAB

Make a friend

版权声明
本文为[Li Rui Bowen]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple