第10章设计的优化.ppt

第10章设计的优化

10.7 阻塞赋值与非阻塞赋值 3)在可综合的硬件设计中,使用阻塞和非阻塞赋值语句时,应注意以下原则: (1)当用“always”块来描述组合逻辑时,既可以用阻塞赋值,也可以采 用非阻塞赋值,应尽量使用阻塞赋值(=)。 module wytest(a,b,c,out1,out2); input a,b,c; output out1,out2; reg out1,out2; always@(a or b or c) begin out1=a+b; out2=out1+c; end endmodule module wytest(a,b,c,out1,out2); input a,b,c; output out1,out2; reg out1,out2; always@(a or b or c) begin out1=a+b; out2=out1+c; end endmodule (2)对时序逻辑描述和建模,使用非阻塞赋值方式(=); (3 ) 对锁存器建模,应尽量使用非阻塞型赋值(=); (4)若在同一个“always”过程块中既为组合逻辑建模,又为时序逻辑建 模,最好使用非阻塞赋值(=)方式。 (5)在一个“always”过程块中,最好不要混合使用阻塞赋值(=)和非 阻塞赋值(=) ,虽然同时使用这两种赋值方式在综合时并不一定 会出错. 对同一个变量不能既进行阻塞赋值,又进行非阻塞赋值,这样在综 合时会报错。 (6)不能在两个个或两个以上的“always”过程块中对同一个变量赋值, 这样会引发冲突,在综合时会报错。 (7)使用$strobe显示非阻塞赋值的变量。 10.7 阻塞赋值与非阻塞赋值 4)时序逻辑建模 (1)当always块中的赋值语句间不存在数据交互,即一个语句中计算出 来的值不会赋给后面的语句使用时,=和=得到的结果是相同的。 10.7 阻塞赋值与非阻塞赋值 module wytest(Q0,Q1,Q2,Q3,din,clk); input clk,din; output Q0,Q1,Q2,Q3; reg Q0,Q1,Q2,Q3; always@(posedge clk) begin Q3=Q2; Q2=Q1; Q1=Q0; Q0=din; end endmodule module wytest(Q0,Q1,Q2,Q3,din,clk); input clk,din; output Q0,Q1,Q2,Q3; reg Q0,Q1,Q2,Q3; always@(posedge clk) begin Q3=Q2; Q2=Q1; Q1=Q0; Q0=din; end endmodule 10.7 阻塞赋值与非阻塞赋值 移位寄存器电路综合结果 (2)若将(1)中阻塞赋值语句的顺序颠倒,则实现的功能,综合出 的电路会发生很大的变化。 10.7 阻塞赋值与非阻塞赋值 module wytest(Q0,Q1,Q2,Q3,din,clk); input clk,din; output Q0,Q1,Q2,Q3; reg Q0,Q1,Q2,Q3; always@(posedge clk) begin Q0=din; Q1=Q0; Q2=Q1; Q3=Q2; end endmodule Q0=din; Q1=Q0; Q2=Q1; Q3=Q2; (3)一个较复杂的例子: 10.7 阻塞赋值与非阻塞赋值 module wytest(clk,a,b,c,out1,out2); input clk,a,b,c; output out1,out2; reg out1,out2; always@(posedge clk) begin out1=a+b; out2=out1+c; end endmodule 10.7 阻塞赋值与非阻塞赋值 module wytest(clk,a,b,c,out1,out2); input clk,a,b,c; output out1,out2; reg out1,out2; always@(posedge clk) begin out1=a+b; out2=out1+c; end endmodule out1=a+b; out2= a+

文档评论(0)

1亿VIP精品文档

相关文档