当前位置:网站首页>Detailed explanation of the difference between Verilog process assignment
Detailed explanation of the difference between Verilog process assignment
2022-07-02 03:08:00 【Da Xi】
Verilog Process assignment
key word : Block assignment , Nonblocking assignment , parallel
Procedural assignment is in initial or always Assignment in statement block , The assignment object is a register 、 Integers 、 Types such as real numbers .
These variables are assigned , Its value will remain unchanged , Until a new value is assigned .
Continuity assignment is always active , Any change in the operand will affect the result of the expression ; Procedure assignment only occurs when the statement is executed , It works . This is the difference between continuous assignment and procedural assignment .
Verilog Process assignment includes 2 A kind of sentence : Blocking assignment and non blocking assignment .
Block assignment
Blocking assignment belongs to sequential execution , That is, before the execution of the next statement , The current statement must be executed .
Blocking assignment statements use the equal sign = As an assignor .
In the previous simulation ,initial The assignment statements inside are blocking assignment .
Nonblocking assignment
Non blocking assignment is a parallel execution statement , That is, the execution of the next statement and the execution of the current statement are carried out at the same time , It does not block the execution of subsequent statements in the same statement block .
Non blocking assignment statements use the less than or equal sign <= As an assignor .
Use the following code , To block 、 Non blocking assignment for simulation , To illustrate 2 The difference between process assignment .
example
`timescale 1ns/1ns
module test ;
reg [3:0] ai, bi ;
reg [3:0] ai2, bi2 ;
reg [3:0] value_blk ;
reg [3:0] value_non ;
reg [3:0] value_non2 ;
initial begin
ai = 4'd1 ; //(1)
bi = 4'd2 ; //(2)
ai2 = 4'd7 ; //(3)
bi2 = 4'd8 ; //(4)
#20 ; //(5)
//non-block-assigment with block-assignment
ai = 4'd3 ; //(6)
bi = 4'd4 ; //(7)
value_blk = ai + bi ; //(8)
value_non <= ai + bi ; //(9)
//non-block-assigment itself
ai2 <= 4'd5 ; //(10)
bi2 <= 4'd6 ; //(11)
value_non2 <= ai2 + bi2 ; //(12)
end
//stop the simulation
always begin
#10 ;
if ($time >= 1000) $finish ;
end
endmodule
The simulation results are as follows :
sentence (1)-(8) Are blocking assignments , Execute in order .
20ns Before , The signal ai,bi Value change . Due to the characteristics of process assignment ,value_blk = ai + bi It didn't work out to , therefore 20ns Before ,value_blk The value is X( Uncertain state ).
20ns after , The signal ai,bi Value changes again . Execute to value_blk = ai + bi, The signal value_blk Using signals ai,bi The new value of gets the calculation result 7.
sentence (9)-(12) Are non blocking assignments , Parallel execution .
First ,(9)-(12) Although they are all executed concurrently , But the order of execution is also (8) after , So the signal value_non = ai + bi Computation also uses signals ai,bi The new value of , The result is 7.
secondly ,(10)-(12) It's concurrent execution , therefore value_non2 = ai2 + bi2 When calculating , Don't care about signals ai2,bi2 The latest non blocking assignment result of . namely value_non2 Signals are used in the calculation ai2,bi2 The old value , The result is 4'hF.
Use non blocking assignment to avoid competitive risk
The above simulation code is just for readers to better understand the difference between blocking assignment and non blocking assignment . actual Verilog Code design , Remember not to mix blocking assignment with non blocking assignment in a process structure . When two assignment methods are mixed , Timing is not easy to control , It's easy to get unexpected results .
More time , When designing circuits ,always Multi use non blocking assignment in sequential logic blocks ,always Multiple blocking assignment in combinational logic blocks ; When simulating circuits ,initial Blocking assignment is generally used in blocks .
As shown below , To realize switching on the rising edge of the clock 2 Function of register values , stay 2 individual always Block using blocking assignment .
because 2 individual always The statements in the block are performed simultaneously , however a=b And b=a It is impossible to determine the order of execution , This creates a competitive situation .
But whichever comes first ( It has something to do with compilers ), Don't consider timing The question is , They always carry out in order , Last a And b The value of is always equal . Failed to reach the exchange 2 Effect of register values .
example
always @(posedge clk) begin
a = b ;
end
always @(posedge clk) begin
b = a;
end
however , If in always Block using non blocking assignment , Can avoid the above competitive and risky situation .
As shown below ,2 individual always The statements in the block execute in parallel , The right-hand operand of the assignment operation uses the old value of the previous clock cycle , here a<=b And b<=a You can execute without interfering with each other , Achieve the purpose of exchanging register values .
example
always @(posedge clk) begin
a <= b ;
end
always @(posedge clk) begin
b <= a;
end
Of course , The function of exchanging register values can also be realized by using the following code , But it's obviously not as good as in always It is simple and intuitive to directly use non blocking assignment in blocks .
example
always @(posedge clk) begin
temp = a ;
a = b ;
b = temp ;
end
边栏推荐
- spark调优
- [JS reverse series] analysis of a customs publicity platform
- What kind of good and cost-effective Bluetooth sports headset to buy
- 命名块 verilog
- [staff] pitch representation (treble clef | C3 60 ~ B3 71 pitch representation | C4 72 pitch representation | C5 84 pitch representation)
- Baohong industry | what misunderstandings should we pay attention to when diversifying investment
- Qualcomm platform wifi-- WPA_ supplicant issue
- QT使用sqllite
- ZABBIX API creates hosts in batches according to the host information in Excel files
- Special symbols in SAP ui5 data binding syntax, and detailed explanation of absolute binding and relative binding concepts
猜你喜欢
Verilog 状态机
Start a business
Systemserver service and servicemanager service analysis
New programmer magazine | Li Penghui talks about open source cloud native message flow system
2022-2028 global wood vacuum coating machine industry research and trend analysis report
Missing numbers from 0 to n-1 (simple difficulty)
数据传输中的成帧
Framing in data transmission
MSI announced that its motherboard products will cancel all paper accessories
Baohong industry | what misunderstandings should we pay attention to when diversifying investment
随机推荐
Coordinatorlayout + tablayout + viewpager2 (there is another recyclerview nested inside), and the sliding conflict of recyclerview is solved
JS <2>
verilog REG 寄存器、向量、整数、实数、时间寄存器
verilog 并行块实现
[road of system analyst] collection of wrong topics in enterprise informatization chapter
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
Verilog avoid latch
JDBC details
/silicosis/geo/GSE184854_scRNA-seq_mouse_lung_ccr2/GSE184854_RAW/GSM5598265_matrix_inflection_demult
Just a few simple steps - start playing wechat applet
Ten minutes will take you in-depth understanding of multithreading - multithreaded teamwork: synchronous control
小米青年工程师,本来只是去打个酱油
只需简单几步 - 开始玩耍微信小程序
Baohong industry | 6 financial management models at different stages of life
Qualcomm platform WiFi -- Native crash caused by WiFi
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]
QT使用sqllite
How to create an instance of the control defined in SAP ui5 XML view at runtime?
数据传输中的成帧