typedef unsigned int u32;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long long u64;
/******************************************************************************
unsigned integer subif underflow, return 1
res = a - b
******************************************************************************/
u32 BigSub(u32 *Res,u32 *Minuend,u32 *Subtrahend,u32 ulLen)
{
u32 carry=0;
u64 _W;
while (ulLen--)
{
_W = ((u64)*Minuend++) - ((u64)*Subtrahend++) - (u64)carry;
*Res++ = (u32)_W;
carry = (u32)(_W >> 32);
carry = ~carry + 1;
}
return carry;
}
// 数据翻转
void top_swap_bottom(u32 *res,u32 resLen)
{
int i;
for (i=0;i<resLen/2;i++)
{
res[i] = res[i] ^res[resLen-i-1];
res[resLen-i-1]= res[i] ^res[resLen-i-1];
res[i] = res[i] ^res[resLen-i-1];
}
}
// 举个例子
int main()
{
u32 res[8]={0x00};
u32 a[8]={0x00223344,0x99887766,0x00223344,0x99887766,0x00223344,0x99887766,0x00223344,0x99887766};
u32 b[8]={0x00223344,0x22113234,0x00223344,0x99887766,0x00223344,0x99887766,0x99776655,0x99776655};
top_swap_bottom(a,8);
top_swap_bottom(b,8);
BigSub(res,a,b,8,8);
top_swap_bottom(res,8);
return 0;
}