赞
踩
The following adder-subtractor with zero flag doesn’t work. Fix the bug(s).
简言之
一个 加减法器,
带有输出零标志 (如果输出out是零,标志信号result_is_zero=1)
Module Declaration
// synthesis verilog_input_version verilog_2001
module top_module (
input do_sub,
input [7:0] a,
input [7:0] b,
output reg [7:0] out,
output reg result_is_zero
);
// synthesis verilog_input_version verilog_2001 /**************分析********** 加减法器, 零标志 (如果out是零,标志信号result_is_zero=1) 1. do_sub=1 做减法 do_sub=0 做加法 2. out=0 result_is_zero=1 *************************/ module top_module ( input do_sub, input [7:0] a, input [7:0] b, output reg [7:0] out, output reg result_is_zero );// /*********有bug*************************** always @(*) begin case (do_sub) 0: out = a+b; 1: out = a-b; endcase if (~out) result_is_zero = 1; end *******************************************/ /***************正确实现**************/ always @(*) begin case (do_sub) 0: out = a+b; 1: out = a-b; endcase if (!out) //out为0满足if 条件 //if (out==8’d0) result_is_zero = 1; else result_is_zero = 0; end endmodule
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。