kyalama
Newbie level 3
Hi,
I was trying to implement the algorithm for multiplication first in matlab and then in verilog and would like to quote from Andraka's paper to illustrate an example. My basic problem is that when I implement the modified equations for multiplication from the paper all i get is x*2 and not x*z (so irrespective of whatever value I initialize z it always does x*2). I find this true when i do it by hand and not just in matlab and want to know where I am going wrong.
So from Andraka's paper:
x(i+1)=x(i)-0*y(i)d(i)*2^-i; which is basically x(i) or just x0 (the initial value)
y(i+1)=y(i)+x(i)*d(i)*(2^-(i)); where d(i)=-1 for z(i)<0,+1 otherwise
z(i+1)=z(i)-d(i)*(2^-(i));
So in the end it says I should get:
x=x0
y=y0+x0*z0
z=0
Lets take an example : x0=3, y0=0, z0=3 (expected result --> y = 9, z = 0)
i=0: x(1)= x0 (this doesnt matter i guess), also d0=1 since z0 is +ve
y(1)= 0 + 3*1*2^-0 = 3
z(1)= 3 - 1*2^-0 = 2
i=1: y(2)= 3+ 3*1*2^-1 = 3+3/2
z(2)= 2 - 1*2^-1 = 2 - 1/2
so on further iterations we notice that
y = 3+ 3/2 + 3/4 + 3/8 +... = 3*( 1+1/2+1/4+1/8+...) isn't this equal to 3 *2 = 6 ?
z = 2 - (1/2+1/4+1/8...) = 2-1 = 1 ?
So can someone tell me where am I going wrong in these iterations and why I am not getting the expected result.
Thanks in advance.
I was trying to implement the algorithm for multiplication first in matlab and then in verilog and would like to quote from Andraka's paper to illustrate an example. My basic problem is that when I implement the modified equations for multiplication from the paper all i get is x*2 and not x*z (so irrespective of whatever value I initialize z it always does x*2). I find this true when i do it by hand and not just in matlab and want to know where I am going wrong.
So from Andraka's paper:
x(i+1)=x(i)-0*y(i)d(i)*2^-i; which is basically x(i) or just x0 (the initial value)
y(i+1)=y(i)+x(i)*d(i)*(2^-(i)); where d(i)=-1 for z(i)<0,+1 otherwise
z(i+1)=z(i)-d(i)*(2^-(i));
So in the end it says I should get:
x=x0
y=y0+x0*z0
z=0
Lets take an example : x0=3, y0=0, z0=3 (expected result --> y = 9, z = 0)
i=0: x(1)= x0 (this doesnt matter i guess), also d0=1 since z0 is +ve
y(1)= 0 + 3*1*2^-0 = 3
z(1)= 3 - 1*2^-0 = 2
i=1: y(2)= 3+ 3*1*2^-1 = 3+3/2
z(2)= 2 - 1*2^-1 = 2 - 1/2
so on further iterations we notice that
y = 3+ 3/2 + 3/4 + 3/8 +... = 3*( 1+1/2+1/4+1/8+...) isn't this equal to 3 *2 = 6 ?
z = 2 - (1/2+1/4+1/8...) = 2-1 = 1 ?
So can someone tell me where am I going wrong in these iterations and why I am not getting the expected result.
Thanks in advance.