[英]multiplying two 32-bit operand in verilog
我在verilog中編寫了乘法器,該乘法器獲得兩個32位操作數並返回64位輸出。 我對該代碼進行了5位測試,它可以正常工作,但是當我運行此代碼時,什么也不會發生,並且我無法停止或結束仿真ModelSim。 您對這個問題有任何想法嗎?
module multiplier_always(operand1,operand2,product);
input [31:0] operand1 ,operand2;
output reg [63:0] product;
reg [63:0] op1;
reg [31:0] op2,addres,subres;
reg [64:0] subres2,result,addres2,opp1;
reg [2:0] i=0;
always@(*)
begin
op1 = {32'b0,operand1};
opp1 = {op1,1'b0};
for(i=0;i<32;i=i+1)
begin
case(opp1[1:0])
2'b00:begin
opp1 = {opp1[64],opp1[64:1]};
end
2'b01:begin
addres = opp1[64:6]+ operand2;
addres2 = {addres,opp1[32:0]};
opp1 = {addres2[64],addres2[64:1]};
end
2'b10:begin
subres = opp1[64:6]+ (~operand2+1);
subres2 = {subres,opp1[32:0]};
opp1 = {subres2[64],subres2[64:1]};
end
2'b11:begin
opp1 = {opp1[64],opp1[64:1]};//shift
end
endcase
end
product = opp1[64:1];
end
endmodule
reg [2:0] i
無限循環將始終小於32; 當i==7
時, i+1
為0
。 更改為integer i
或reg [5:0] i
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.