当前位置:网站首页>Verilog 过程连续赋值
Verilog 过程连续赋值
2022-07-02 03:02:00 【嗒曦】
Verilog 过程连续赋值
关键词:deassign,force,release
过程连续赋值是过程赋值的一种。这种赋值语句能够替换其他所有 wire 或 reg 的赋值,改写了 wire 或 reg 型变量的当前值。
与过程赋值不同的是,过程连续赋值的表达式能被连续的驱动到 wire 或 reg 型变量中,即过程连续赋值发生作用时,右端表达式中任意操作数的变化都会引起过程连续赋值语句的重新执行。
过程连续性赋值主要有 2 种,assign-deassign 和 force-release。
assign, deassign
assign(过程赋值操作)与 deassign (取消过程赋值操作)表示第一类过程连续赋值语句。赋值对象只能是寄存器或寄存器组,而不能是 wire 型变量。
赋值过程中对寄存器连续赋值,寄存器中的值被保留直到被重新赋值。
例如,一个带复位端的 D 触发器可以用下面代码描述:
实例
module dff_normal(
input rstn,
input clk,
input D,
output reg Q
);
always @(posedge clk or negedge rstn) begin
if(!rstn) begin //Q = 0 after reset effective
Q <= 1'b0 ;
end
else begin
Q <= D ; //Q = D at posedge of clock
end
end
endmodule
下面,用 assign 与 deassign 改写,完成相同的功能。
即在复位信号为 0 时,Q 端被 assign 语句赋值,始终输出为 0。
复位信号为 1 时,Q 端被 deassign 语句取消赋值,在时钟上升沿被重新赋值。
实例
module dff_assign(
input rstn,
input clk,
input D,
output reg Q
);
always @(posedge clk) begin
Q <= D ; //Q = D at posedge of clock
end
always @(negedge rstn) begin
if(!rstn) begin
assign Q = 1'b0 ; //change Q value when reset effective
end
else begin //cancel the Q value overlay,
deassign Q ; //and Q remains 0-value until the coming of clock posedge
end
end
endmodule
force, release
force (强制赋值操作)与 release(取消强制赋值)表示第二类过程连续赋值语句。
使用方法和效果,和 assign 与 deassign 类似,但赋值对象可以是 reg 型变量,也可以是 wire 型变量。
因为是无条件强制赋值,一般多用于交互式调试过程,不要在设计模块中使用。
当 force 作用在寄存器上时,寄存器当前值被覆盖;release 时该寄存器值将继续保留强制赋值时的值。之后,该寄存器的值可以被原有的过程赋值语句改变。
当 force 作用在线网上时,线网值也会被强制赋值。但是,一旦 release 该线网型变量,其值马上变为原有的驱动值。
为直观的观察两种类型变量强制赋值的区别,利用第一节中的计数器 counter10 作为设计模块,testbench 设计如下。
实例
`timescale 1ns/1ns
module test ;
reg rstn ;
reg clk ;
reg [3:0] cnt ;
wire cout ;
counter10 u_counter (
.rstn (rstn),
.clk (clk),
.cnt (cnt),
.cout (cout));
initial begin
clk = 0 ;
rstn = 0 ;
#10 ;
rstn = 1'b1 ;
wait (test.u_counter.cnt_temp == 4'd4) ;
@(negedge clk) ;
force test.u_counter.cnt_temp = 4'd6 ;
force test.u_counter.cout = 1'b1 ;
#40 ;
@(negedge clk) ;
release test.u_counter.cnt_temp ;
release test.u_counter.cout ;
end
initial begin
clk = 0 ;
forever #10 clk = ~ clk ;
end
//finish the simulation
always begin
#1000;
if ($time >= 1000) $finish ;
end
endmodule // test
仿真结果如下。
由图可知,在 cnt_temp 等于 4 时(80ns), cnt_temp 被强制赋值为 6,cout 被强制赋值为 1。
release 时(120ns), cnt_temp 为寄存器类型,仍然保持原有值不变,直到时钟上升沿对其进行加法赋值操作,值才变为 7 。
而 120ns 时,由于 cout 是线网型变量,其值不能保存。原码 counter10 模型中存在驱动语句: assign cout = (cnt_temp==4'd9) ,所以 cout 值变为 0 。

边栏推荐
- 小米青年工程师,本来只是去打个酱油
- 自定义组件的 v-model
- 2022-2028 global human internal visualization system industry research and trend analysis report
- Just a few simple steps - start playing wechat applet
- Feature query of hypergraph iserver rest Service
- QT uses sqllite
- 高并发场景下缓存处理方案
- 多线程查询,效率翻倍
- [staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)
- Mongodb non relational database
猜你喜欢

2022-2028 global wood vacuum coating machine industry research and trend analysis report

Soul app released the annual report on generation Z behavior: nearly 20% of young people love shopping in the vegetable market

Formatting logic of SAP ui5 currency amount display

Après le mariage

Coordinatorlayout + tablayout + viewpager2 (there is another recyclerview nested inside), and the sliding conflict of recyclerview is solved

2022-2028 global soft capsule manufacturing machine industry research and trend analysis report
Face++ realizes face detection in the way of flow

AcWing 245. Can you answer these questions (line segment tree)
![[liuyubobobo play with leetcode algorithm interview] [00] Course Overview](/img/1c/c8cab92c74b6658c3ef608c5255f1f.png)
[liuyubobobo play with leetcode algorithm interview] [00] Course Overview

LeetCode刷题(十)——顺序刷题46至50
随机推荐
【做题打卡】集成每日5题分享(第二期)
Feature query of hypergraph iserver rest Service
After marriage
[learn C and fly] 3day Chapter 2 program in C language (exercise 2.3 calculate piecewise functions)
Baohong industry | 6 financial management models at different stages of life
Basic 01: print string
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
Xiaomi, a young engineer, was just going to make soy sauce
New programmer magazine | Li Penghui talks about open source cloud native message flow system
Provincial election + noi Part IV graph theory
Redis cluster
What is the principle of bone conduction earphones and who is suitable for bone conduction earphones
What are the characteristics of common web proxy IP
Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field
Unit · elementary C # learning notes
[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)
What is the difference between an intermediate human resource manager and an intermediate economist (human resources direction)?
2022-2028 global wood vacuum coating machine industry research and trend analysis report
Yyds dry goods inventory accelerating vacuum in PG
STM32__ 05 - PWM controlled DC motor