verilog - 在 Verilog 中实现 floor 函数
问题描述
我在 Verilog 中实现需要整数的硬件。例如,如果 7 除以 3,则答案为 1。数字也可以是负数。任何人都知道如何实现该功能?
module test(clk, a, b, c);
input [4 : 0] a,b;
output [4 : 0] c;
wire [4 : 0] x;
always @(posedge clk)
begin
x = a / b;
*c = floor(x);*
end
endmodule
解决方案
尝试使用重复减法执行除法算法。下面是一个伪代码。
//Example :- 7/2
temp1 = 7; cntr = 'd0; temp2 = 2 //Store the number in a register and init counter
//Perform temp1-temp2 and increment cntr until temp1>=temp2
if(temp1 >= temp2)
begin
temp1 <= temp1 - temp2;
cntr <= cntr + 1'd1;
end
//cntr holds the quotient, which is 3 for our case.
floor_val = (temp1 == 'd0) ? cntr : cntr - 1'd1; //Final divided value
推荐阅读
- winforms - 氪WinForm控件在vs2010中是只读的
- html - 将 html 模板转换为矢量 PDF
- r - 如何制作比较多列的二进制矩阵
- python - 如何在没有所有包版本的情况下创建requirement.txt
- angularjs - 特殊字符不会从输入表单中显示在 AngularJS 中,例如 % & ? @
- elasticsearch - 使用logstash句柄删除场景的增量索引
- javascript - 将动态背景设置为引导模式
- python - Python- 在整个数据帧中丢弃小时:分钟:秒形式 timedelta64[ns] 数据
- html - 我正在尝试在网格视图中显示图像,但我不能这样做只有图像名称正在显示,请建议我解决方案
- matlab - arrayfun 输出的串联