Hi guys,
I convert int values to ascii for instance 221 should show up as 32 32 31 but my method pushes onto stack as 31 32 32 which is opposite. any idea what I am doing wrong?
Thanks,
x86 integer to ascii
Page 1 of 13 Replies - 4358 Views - Last Post: 18 April 2013 - 06:55 PM
Replies To: x86 integer to ascii
#2
Re: x86 integer to ascii
Posted 17 April 2013 - 09:46 PM
no idea without seeing your code, my crystal ball is down... post the code you are using
#3
Re: x86 integer to ascii
Posted 17 April 2013 - 09:53 PM
Here is my code while loop is not logic but dont worry about it.
mov ebx,lpStringToStore ;ebx=addr. of the str. mov eax,val ;eax=val mov esi,10d ;esi=10 divisor cdq ;extend edx:eax .while eax!=-1 ;dummy instruction to keep loop alive. .if eax<10 ;single digit no need to be divided. add al,30h mov byte ptr [ebx], al ;save rem. inc ebx ;inc index jmp done .else ;eax>10 cdq idiv esi ;eax/10 add dl,30h mov byte ptr [ebx], dl ;save rem. inc ebx ;inc index .endif ;endif .endw ;end of the loop done: ;done
#4
Re: x86 integer to ascii
Posted 18 April 2013 - 06:55 PM
It has to do with the Endianness of the CPU. INTEL/AMD CPUs are "Little Endian", which means the least significant digit is on the left in the Register (Not how you see it on paper). If you do:
It will be stored in eax as "DCBA"
"Big Endian" however, is stored in the CPU "as it is written on paper". So for a Big Endian CPU, "ABCD" will be stored as "ABCD". After your conversion, you need to reverse the string, this is how almost all DWORD to ASCII routines do it. Your code is basically correct, you just need to reverse the digits when done, and maybe take into account for signed/unsigned numbers.
Endianness on Wikipedia
mov eax, "ABCD"
It will be stored in eax as "DCBA"
"Big Endian" however, is stored in the CPU "as it is written on paper". So for a Big Endian CPU, "ABCD" will be stored as "ABCD". After your conversion, you need to reverse the string, this is how almost all DWORD to ASCII routines do it. Your code is basically correct, you just need to reverse the digits when done, and maybe take into account for signed/unsigned numbers.
Endianness on Wikipedia
Page 1 of 1