除法器勘误

1、c时序逻辑 除法器勘误
原文链接:https://blog.csdn.net/aaaaaaaa585/article/details/118300782

module Divider_0#(
	 parameter	DIVISOR_WIDTH		= 32,
	 parameter	DIVIDEND_WIDTH		= 32
)(
	input									clk_i,
	input									rst_i,
	//------------------------------------------------//
	input			[DIVISOR_WIDTH-1:0]		divisor_i,
	input			[DIVIDEND_WIDTH-1:0]	dividend_i,
	input									cal_en_i,
	//------------------------------------------------//
	output	reg		[DIVISOR_WIDTH-1:0]		quotient_o,	
	output	reg		[DIVIDEND_WIDTH-1:0]	remainders_o,
	output	reg								cal_valid_o
);

(* keep = "TRUE" *) reg	[DIVISOR_WIDTH+DIVIDEND_WIDTH:0]		tempa	[DIVISOR_WIDTH : 0];
(* keep = "TRUE" *) reg	[DIVISOR_WIDTH+DIVIDEND_WIDTH-1:0]		tempb	[DIVISOR_WIDTH : 0];
(* keep = "TRUE" *) reg	[DIVISOR_WIDTH:0]		cal_valid_dly;
//integer	i;
genvar i;
generate

always @(posedge clk_i)begin 
	if(rst_i == 1'b1)begin
		tempa[0] <= 'd0; 
		tempb[0] <= 'd0;
	end
	else if(cal_en_i == 1'b1)begin
		tempa[0] <= {{DIVIDEND_WIDTH{1'b0}},divisor_i,1'b0};
		tempb[0] <= {dividend_i,{DIVISOR_WIDTH{1'b0}}}; 
	end
	else begin
		tempa[0] <= tempa[0];
		tempb[0] <= tempb[0];
	end 
end

reg	[DIVISOR_WIDTH:0] dbg;

for(i = 0;i < DIVISOR_WIDTH;i = i + 1)begin
	always @(posedge clk_i)begin 
		if(tempa[i][DIVISOR_WIDTH + DIVIDEND_WIDTH : DIVISOR_WIDTH ] >= tempb[i][DIVISOR_WIDTH +: DIVIDEND_WIDTH])begin
			tempa[i+1] <= ((tempa[i] - tempb[i] )<<1) + 1'b1;
			tempb[i+1] <= tempb[i];
			dbg[i+1] <= 1'b1;
		end
		else begin
			tempa[i+1] <= tempa[i]<<1;
			tempb[i+1] <= tempb[i];
			dbg[i+1] <= 1'b0;
		end
	end
end

always @(posedge clk_i)begin 
	quotient_o	<= tempa[DIVISOR_WIDTH][0 +: DIVISOR_WIDTH];
	remainders_o	<= tempa[DIVISOR_WIDTH][DIVISOR_WIDTH+1 +: DIVIDEND_WIDTH];
end

always @(posedge clk_i)begin 
	cal_valid_dly <= {cal_valid_dly[0 +: DIVISOR_WIDTH],cal_en_i};
	cal_valid_o <= cal_valid_dly[DIVISOR_WIDTH];
end	

endgenerate

endmodule 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值