除assign-deassign外另一种形式的过程连续赋值是force和release过程语句,它们和assign-deassign对有类似的作用,但是force既可以对变量使用,也可以对线网使用。force过程连续的使用规则如下。\\ - 赋值的LHS可以是variable、net、constant bit-select of vector net、part-select of vector net或concatenation,但不可以是memory word、bit-select or part-select of vector variable。 - 对变量的force过程连续赋值优先于(overide)过程赋值和assign过程连续赋值,直到在此变量上执行release语句。 - 如果release此变量时,在此变量上没有active的assign过程连续赋值,那么此变量就保持不变,直到在此变量上发生过程赋值或assign过程连续赋值。 - 如果release此变量时,恰好在此变量上有assign过程连续赋值,那么此assign过程连续赋值马上起效。 - 对一个线网的force语句将优先于所有对线网的drives(包含门输出、模块输出和连续赋值),直到在此线网上执行release语句。在release时,此线网马上被drives赋值。 例子:在下面的代码中,通过使用force过程语句,与门被“patched”成了或门,一个是针对“assign d = a & b & c;”,另一个是针对“and and1(e,a,b,c);”。\\ module test; reg a, b, c, d; wire e; and and1 (e, a, b, c); initial begin $monitor("%d d=%b,e=%b", $stime, d, e); assign d = a & b & c; a = 1; b = 0; c = 1; #10; force d = (a | b | c); force e = (a | b | c); #10; release d; release e; #10 $finish; end endmodule 运行结果: 0 d=0,e=0 10 d=1,e=1 20 d=0,e=0 assign过程连续赋值和force语句的RHS可以是一个表达式,如同连续赋值一样,这就意味着如果RHS中的变量发生变化,而且assign或force正在有效,那么赋值就会被重新计算。\\ 例子:如果b或c发生变化,那么a就会被强制更改为新值。\\ force a = b + f(c); 注意:建议不要使用force,而是使用仿真器提供的系统函数$deposit,具体用法请参考仿真器的手册。