flat assembler
Message board for the users of flat assembler.

Index > Main > how to parse the number(ASCII code)?

Author
Thread Post new topic Reply to topic
Theo



Joined: 19 Mar 2005
Posts: 7
Theo 31 Mar 2005, 23:13
how to parse the decimal number inputed from keyboard (ASCII code) into binary code and parse the binary code to decimal number?

i just want to get 2 numbers from keyboard and show the sum of them.
Post 31 Mar 2005, 23:13
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
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
Post 01 Apr 2005, 03:13
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
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>>
Post 02 Apr 2005, 02:53
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.