flat assembler
Message board for the users of flat assembler.
Index
> Main > how to parse the number(ASCII code)? |
Author |
|
r22 01 Apr 2005, 03:13
That's kind of a pain in the butt to do in ASM.
BIN -> ASCII representation can be done using the wsprintf function But ASCII -> BIN I don't think there's a descent function for that. Code: ;This will only work for 32bit unsigned integers 0-4294967295 ASC2BIN_Integer: .strNum equ ebp+8 push ebp mov ebp,esp xor eax, eax mov esi, [.strNum] ;ptr to null terminated ASCII number ie'123',0 .Next: movzx ecx, byte [esi] xor ecx, 30h ;subtract 48 from ascii '0' = 48 - 48 = 0, '9' = 57 -4 8 = 9 add esi,1 mov edx, 10 mul edx ;multiply EAX by 16 (first pass it does nothing) add eax, ecx cmp byte [esi], 0 ;if null there's no more chars in string so done je .done jmp .Next .done: mov esp,ebp pop ebp retn 4 numb db '100',0 push numb call ASC2BIN_Integer ;EAX = 64h |
|||
01 Apr 2005, 03:13 |
|
r22 02 Apr 2005, 02:53
my comment was flawed
" mul edx ;multiply EAX by 16 (first pass it does nothing) " I meant <<10>> not <<16>> |
|||
02 Apr 2005, 02:53 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.