flat assembler
Message board for the users of flat assembler.
Index
> Windows > [SOLVED] - Convert integer to hexadecimal |
Author |
|
typedef 19 Jun 2011, 15:18
it is atoi or atof...atof sounds like float ?
|
|||
19 Jun 2011, 15:18 |
|
ctl3d32 19 Jun 2011, 15:28
I think 'atoi' is for dword.
|
|||
19 Jun 2011, 15:28 |
|
typedef 19 Jun 2011, 15:37
ctl3d32 wrote: I think 'atoi' is for dword. Ooh.. My mistake, forgive me. Somehow I was thinking ascii to integer but then after I re-read the title it says Convert integer to hexadecimal Sorry. Last edited by typedef on 19 Jun 2011, 19:48; edited 1 time in total |
|||
19 Jun 2011, 15:37 |
|
LocoDelAssembly 19 Jun 2011, 16:38
I've just checked and the number is almost correct. The problem is that the input number is 59 bits long and your 64-bit double has a mantissa of only 52 bits long.
|
|||
19 Jun 2011, 16:38 |
|
ctl3d32 19 Jun 2011, 17:13
So, how can i do it without using SSE registers?
|
|||
19 Jun 2011, 17:13 |
|
LocoDelAssembly 19 Jun 2011, 20:38
Code: format PE GUI 4.0 entry start include 'win32a.inc' section '.text' code readable executable start: invoke GetModuleHandle,0 mov [h_process],eax cinvoke wsprintf,string1,fmt1,dword[number+4],dword[number] ccall atoll,strnum cinvoke wsprintf,string2,fmt1,edx,eax cinvoke wsprintf,caption,fmt2,string1,string2 invoke MessageBox,HWND_DESKTOP,caption,title,MB_OK exit: invoke ExitProcess,0 ; WARNING: Works on unsigned integers only (fixable, but I left it as an exercise) proc atoll c uses esi ebx edi, pStr mov esi, [pStr] .skip: lodsb test al, al jz .error cmp al, ' ' jbe .skip sub al, '0' cmp al, 10 jae .error movzx eax, al xor ebx, ebx xor ecx, ecx mov edi, 10 jmp .grabDigit .addDigit: imul ecx, edi jc .error mul edi add ecx, edx jc .error add eax, ebx adc ecx, 0 jc .error .grabDigit: mov bl, [esi] inc esi sub bl, '0' cmp bl, 10 jb .addDigit .success: mov edx, ecx .return: ret .error: xor eax, eax xor edx, edx jmp .return endp ; I know the error signaling is stupid, I'm just following what I've seen at http://www.cppreference.com/wiki/string/c/atoi section '.bss' data readable writable h_process dd ? ;handles to the executable process. string1 rb 40h string2 rb 40h caption rb 40h section '.data' data readable writable title db 'Convert Decimal to Hexadecimal',0 fmt1 db '%X%X',0 fmt2 db 'number = 328839641925923849',10,13,\ 'wsprintf: %s',10,13,10,13,\ 'number = "328839641925923849"',10,13,\ 'atof(msvcrt.dll): %s',0 number dq 328839641925923849 strnum db '328839641925923849',0 section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'API\KERNEL32.INC' include 'API\USER32.INC' Please review my code carefully, I may doing something wrong and it took my a while to get it (apparently) right. I think I'm getting so old... |
|||
19 Jun 2011, 20:38 |
|
ctl3d32 19 Jun 2011, 21:21
Thanks a lot for the code. It works perfectly.
I'm going to study it right now! Cheers, ctl3d32 |
|||
19 Jun 2011, 21:21 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.