I managed to write a code that accepts a 32-bit integer and converts it to a digit-array to represent it in another number system
Question: How can i expand this to 64-bit?
In the Digital Mars C/C++ compiler:
void get_digits_asm()
{
__asm
{
pushf
movd xmm0,eax
movd xmm1,ebx
movd xmm2,ecx
movd xmm3,edx
movd xmm4,edi
mov eax,[variable_x]
mov ebx,[number_system]
mov ecx,0h
mov edi,0h
begin_loop:
mov edx,0h
div ebx
lea edi,digits
mov [edi+ecx*4],edx
add ecx,01h
cmp eax,ebx
ja begin_loop
mov edx,0
div ebx
lea edi,digits
mov [edi+ecx*4],edx
inc ecx
mov [digits_total],ecx
movd edi,xmm4//pop edi
movd edx,xmm3//pop edx
movd ecx,xmm2//pop ecx
movd ebx,xmm1//pop ebx
movd eax,xmm0//pop eax
popf
}
}
When this function returns, it gives the LSB to MSB arranged array of digits.
Example: 5 is 101 in the number-system 2. 232343435 is 54545… in system 8. I want to learn how can i make this in 64 bit. My OS is 32 bit. My CPU is pentium-M centrino-laptop How can i do this?
You use
before
in your
begin_loop:.If you want to process 64-bit numbers, then use the EDX register to store the upper 32 bits of you number. So, if you number is
then load it into EDX/EAX pair.
Instead of
do
I hope you get it. Sorry if I forgot the exact addressing rules of x86.
Of course, since you destroy the EDX on each iteration, you might use the stack or one more register to store it.
Your problem has nothing to do with the 64-bit long mode, DIV instruction supports 64-bit integers. They are just stored as pairs.