problem with multiplication of two negative numbers using booth algorithm

Status
Not open for further replies.

maheshkumar.g

Member level 1
Joined
Oct 7, 2012
Messages
35
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,515
hi all,
i have a problem with multplication using booth multiplier.
whenever i multiply two negative numbers i get a wrong answer and when i multiply one positive and one negative i get the correct result.

please help me.................thanks in advance
 

What exactly do you mean?
A multiplication of two negatives gives a positive result , what do you get?
 

What exactly do you mean?
A multiplication of two negatives gives a positive result , what do you get?

Code:
module bm(temp,cy,in1,in2);
input in1,in2;
output temp,cy;
wire [4:0]in1;
wire [4:0]in2;
reg [9:0] temp;
reg [1:0] sel;
reg cy;
integer i;
reg plsb;
always @(in1,in2)
begin
plsb=1'b0;
temp={{5'b00000},{in1[4:0]}};
for(i=0;i<5;i=i+1)
begin
sel={temp[0],plsb};
case(sel)
2'b00:begin
plsb=temp[0];
temp={temp[0],temp[9:1]};
end
2'b01:begin
temp[9:5]=temp[9:5]+in2[4:0];
plsb=temp[0];
temp={temp[0],temp[9:1]};
end
2'b10:begin
temp[9:5]=temp[9:5]-in2[4:0];
plsb=temp[0];
temp={temp[0],temp[9:1]};
end
2'b11:begin
plsb=temp[0];
temp={temp[0],temp[9:1]};
end
endcase
end
cy=temp[9]|temp[8]|temp[7]|temp[6]|temp[5];
end
endmodule

test bench:
Code:
module stimulus;
reg [4:0]in1,in2;
wire [9:0]temp;
wire cy;
bm b(temp,cy,in1,in2);
initial
begin
in1=-5'd5;
in2=-5'd10;
$monitor("in1=%d in1=%b in2=%d in2=%b temp=%d temp=%b carry=%b",in1,in1,in2,in2,temp,temp,cy);
end
endmodule

answer what iam getting is

in1=27 in1=11011 in2=22 in2=10110 temp= 914 temp=1110010010 carry=1

how can we take the result here i am getting a wrong answer
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…