ahme0307
Member level 1
Please help! Any one knows how to multiply signed 64bit X signed 64 bit number in ARM using C or assembly ,
I input the two numbers as: long long int x,y;
I input the two numbers as: long long int x,y;
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
typedef signed long long int int64;
typedef unsigned long long int int64u;
long int a3=0,b_hi,c_hi,temp2=0;
int64u tempu;
unsigned long a2=0,a1=0,a0=0,b_lo=89,c_lo=89;
int64 temp,tempt;
tempu=(b_lo)*(c_lo);// b_lo*c_lo
a0=tempu;
a1=tempu<<32;
unsigned long int t=tempu;
//a0=64*64;
temp=(b_lo)*(c_hi); //b_lo*c_hi
a1=(a1)+(temp); //res a3,a2,a1,a0 a1+temp_lo
a2=a2+temp<<32; //a2=temp_hi
temp=(b_hi)*(c_lo);//b_hi *c_lo
a3=a3+temp<<32; //a2=a2+temp_hi
a1=a1+temp; //a1=a1+temp_lo
temp2=a2;//b_low=a2;
a2=a2+a3;//a2=a2+a3
a3=temp2+a3;//a3=b_low+a3
temp=(b_hi)*(c_hi);//b_hi*c*hi
a2=a2+temp;// a2=a2+temp_lo
a3=temp<<32+a3;//a3=temp_hi+a3
printf ("The result is :=%lld%lld%lld%lld\n",a3,a2,a1,a0);
/*
to avoid confusion I made here a plain calculation
using many variable. You can simplify the code.
x,y is the 2 multiplier (signed 64 bit)
after sign valuation and (if need) sign inversion
it is split into xh xl yh yl (unsigned 32 bit)
the operations performed are:
xh xl *
yh yl =
-------
xl_yl +
xh_yl +
xl_yh +
xh_yh =
-------------
(sign) z3 z1 z2 z0
*/
short sign=1;
long long x=0x7fffffffffffffff;
long long y=0x7fffffffffffffff;
unsigned long long xl_yl,xh_yl,xl_yh,xh_yh;
unsigned long long xl,xh,yl,yh;
unsigned long z3,z2,z1,z0;
unsigned long long temp_sum;
if (x<0)
{
x=-x;
sign =-sign;
}
if (y<0)
{
y=-y;
sign =-sign;
}
xl=x & 0xffffffff;
xh=x>>32;
yl=y & 0xffffffff;
yh=y>>32;
xl_yl=xl*yl;
xh_yl=xh*yl;
xl_yh=xl*yh;
xh_yh=xh*yh;
z0=xl_yl & 0xffffffff; // result 0
temp_sum=(xl_yl>>32)+(xh_yl & 0xffffffff)+(xl_yh & 0xffffffff);
z1=temp_sum & 0xffffffff; // result 1
temp_sum>>=32; // this is 'carry out' of the previous sum
temp_sum+=(xh_yl>>32)+(xl_yh>>32)+xh_yh;
z2=temp_sum & 0xffffffff; // result 2
z3=temp_sum >>32; // result 3
printf ("The result is :=%lld%lld%lld%lld\n",z3,z2,z1,z0);
sprintf(str,"%llx%llx%llx%llx",z3,z2,z1,z0);
printf ("The result of multiplication is=%s\n",str);