当前位置:网站首页>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 。

边栏推荐
- Mathematical calculation in real mode addressing
- [question 008: what is UV in unity?]
- es面試題
- [staff] pitch representation (treble clef | C3 60 ~ B3 71 pitch representation | C4 72 pitch representation | C5 84 pitch representation)
- What are the characteristics of common web proxy IP
- 使用开源项目【Banner】实现轮播图效果(带小圆点)
- 只需简单几步 - 开始玩耍微信小程序
- 2022-2028 global soft capsule manufacturing machine industry research and trend analysis report
- ZABBIX API creates hosts in batches according to the host information in Excel files
- [staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)
猜你喜欢
![[pit] how to understand](/img/e9/f5315a03b6f3da07021f915bb18af8.jpg)
[pit] how to understand "parameter fishing"

【JVM】创建对象的流程详解

PHP notes - use Smarty to set public pages (include, if, else, variable settings)

How to turn off the LED light of Rog motherboard

The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added

Jointly developed by nailing, the exclusive functions of glory tablet V7 series were officially launched
![[Chongqing Guangdong education] Sichuan University concise university chemistry · material structure part introductory reference materials](/img/ae/7edbdf55795400166650c795c8bd58.jpg)
[Chongqing Guangdong education] Sichuan University concise university chemistry · material structure part introductory reference materials
![[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)](/img/96/8c4baa1dd8e35e2cab67461e7c447b.jpg)
[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)

批量检测url是否存在cdn—高准确率
![[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)](/img/39/42b1726e5f446f126a42d7ac673dce.png)
[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)
随机推荐
[JS reverse series] analysis of a customs publicity platform
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
设置状态栏颜色
[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
[JVM] detailed description of the process of creating objects
只需简单几步 - 开始玩耍微信小程序
高并发场景下缓存处理方案
Leetcode question brushing (10) - sequential question brushing 46 to 50
[learn C and fly] day 5 chapter 2 program in C language (Exercise 2)
Es interview questions
[learn C and fly] 4day Chapter 2 program in C language (exercise 2.5 generate power table and factorial table
A list of job levels and salaries in common Internet companies. Those who have conditions must enter big factories. The salary is really high
连通块模板及变式(共4题)
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
Feature query of hypergraph iserver rest Service
旋转框目标检测mmrotate v0.3.1 学习模型
Questions d'entrevue
How to create an instance of the control defined in SAP ui5 XML view at runtime?
Addition without addition, subtraction, multiplication and division (simple difficulty)
QT实现界面跳转