|
算法常见基本的问题:signed data的加法运算,该如何用硬件电路来实现?若处理不好,debug是很费时费力。这边跟大家分享不同于软件(ex. C)的写法。
使用Verilog实现 “signed_add.v”(for 4-bit input and 5-bit output)
module signed_add (
iclk,
ia,
ib,
osum
);
input iclk;
input [3:0] ia;
input [3:0] ib;
output [4:0] osum;
reg [4:0] osum;
wire [4:0] sum_temp;
assign sum_temp = {ia[3], ia} + {ib[3], ib}; // Note here!!
always@(posedge iclk)
osum <= sum_temp;
endmodule |
|