//extern unsigned char databuf[16];---此缓冲区0-3存放的是被加数,4-7存放的是加数,8-11存放的和。(低字节在前) //扩展此缓冲区,便可以实现任意长度的压缩BCD加法 //*DataOneDptr==>被加数数组的指针 //*DataTwoDptr==>加数的数组指针
//作者:雁舞白沙 void DataAdd(unsigned char *DataOneDptr,unsigned char *DataTwoDptr,unsigned char DataLend) { unsigned char data i,j,k,l; j=0; k=0; l=0; for(i=0;i<DataLend;i++) { databuf=*DataOneDptr; databuf&=0x0f; databuf[i+4]=*DataTwoDptr; databuf[i+4]&=0x0f; for(j=0;j<2;j++) { k=databuf+databuf[i+4]+l; if(k>9) { if(j==1) { k=k+6; k=k<<4; databuf[i+8]=databuf[i+8]+k; } else { databuf[i+8]=databuf[i+8]+k+6; databuf[i+8]&=0x0f; } l=0x01; } else { l=0x00; if(j==1) { k=k<<4; databuf[i+8]=databuf[i+8]+k; } else { k&=0x0f; databuf[i+8]=k; } } databuf=*DataOneDptr; databuf[i+4]=*DataTwoDptr; databuf=databuf>>4; databuf[i+4]=databuf[i+4]>>4; } DataOneDptr++; DataTwoDptr++; } }
程序昨天晚上完成,有不对的地方,欢迎大家更正! |