一个96位的二进制数,分三部分分别存储在 eax, ebx, ecx。怎么转化为96位二进制对应的十进制输出?
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
先给出所有源代码
- C/C++ code
#include "stdio.h"#include "stdlib.h"typedef unsigned long DWORD;//pn[0], the lowest 32bits//pn[1], the middle 32bits//pn[2], the highest 32bitsvoid uint96_to_string(DWORD *pn, char *szString){ _asm { push esi push edi push ecx mov esi,pn mov edi,szString mov ecx,10 jmp check_ndiv_h_32bit: mov eax,dword ptr [esi+8] div ecx mov dword ptr [esi+8], eaxdiv_m_32bit: mov eax,dword ptr [esi+4] div ecx mov dword ptr [esi+4], eaxdiv_l_32bit: mov eax,dword ptr [esi] div ecx mov dword ptr [esi], eax add dl,'0' mov byte ptr [edi],dl inc edicheck_n: xor edx,edx cmp [esi+8],0 jnz div_h_32bit cmp [esi+4],0 jnz div_m_32bit cmp [esi],0 jnz div_l_32bit //now, the whole 96bit number is full 0 cmp edi,szString jne invert_n //if uint96 is 0, then edi == szString, in this case, we need put '0' to szString and return mov byte ptr [edi],'0' //put 0 to buffer mov byte ptr [edi+1],0 //c language string terminating symbol jmp thisExit invert_n: mov byte ptr [edi],0 //c language string terminating symbol dec edi //the edi point to the tail of string mov esi,szString //the esi point to the head of string jmp invert_cmpinvert_loop: mov al,[esi] mov dl,[edi] mov [edi],al mov [esi],dl inc esi dec ediinvert_cmp: cmp esi,edi jb invert_loopthisExit: pop ecx pop edi pop esi }}void test_uint96_to_string(){ DWORD n[3]; char result[32]; int case_id=1;//case 1: n[0]=0; n[1]=0; n[2]=0; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;//case 2: n[0]=9; n[1]=0; n[2]=0; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;//case 3: n[0]=10; n[1]=0; n[2]=0; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;//case 4: n[0]=0xffffffff; n[1]=0; n[2]=0; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;//case 4: n[0]=0; n[1]=1; n[2]=0; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;//case 6: n[0]=1; n[1]=1; n[2]=0; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;//case 7: n[0]=0; n[1]=0; n[2]=1; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;//case 8: n[0]=1; n[1]=0; n[2]=1; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;//case 9: n[0]=0xffffffff; n[1]=0xffffffff;; n[2]=0xffffffff;; uint96_to_string(n,result); printf("run case %d,result is %s\n",case_id,result); case_id++;}int main(int argc, char* argv[]){ test_uint96_to_string();}