flat assembler
Message board for the users of flat assembler.

Index > Windows > Input an Integer

Author
Thread Post new topic Reply to topic
Pjuu



Joined: 03 Apr 2005
Posts: 2
Location: England, UK
Pjuu
Hiya

I am writing a very simple compiler just as a small project and it is going
to translate to FASM assembly language. I have most of it sorted i was
just wondering how i can get a few things sorted.

How can i check what has been inputted into a buffer from the ReadFile
routine in Kernel32 is a valid integer? And how i could convert this string
into an integer. I have been trying for a while now and can not do it i need
it to take into account negative numbers and if the input is not an integer
to throw a nice error message. Could any one please help?

Thanks in advance Wink

_________________
Pjuu ^__^
Post 03 Apr 2005, 15:58
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
Post 03 Apr 2005, 19:36
View user's profile Send private message Reply with quote
kidscracker



Joined: 29 Oct 2004
Posts: 46
Location: Peru
kidscracker
Here is a code that will work, i tok it from an old 16bit library and adapt it, I forgot the part where it detects if it's and negative number Confused , but i will post it later. te code is:
Code:
proc    STR_ToLong,lptrString
        enter
        push    ecx edx esi
        pushfd
        cld
        xor     ecx,ecx

        mov     esi,[lptrString]

;
.lp:
        lodsb
        xor     al, '0'
        cmp     al, 10
        ja      .NotDigit
        shl     ecx, 1
        jc      .Error
        mov     edx, ecx
        shl     ecx, 1
        jc      .Error
        shl     ecx, 1
        jc      .Error
        add     ecx, edx
        jc      .Error
        add     cl, al
        adc     ch, 0
        jc      .Error
        jmp     .lp
;
.NotDigit:
        mov     eax,ecx
        popfd
        pop     esi edx ecx
        clc
        return
;
.Error:
        popfd
        pop     esi edx ecx
        stc
        return
endp
    

I hope it will be helpufull
Post 03 Apr 2005, 19:47
View user's profile Send private message MSN Messenger ICQ Number Reply with quote
Pjuu



Joined: 03 Apr 2005
Posts: 2
Location: England, UK
Pjuu
Thanks this has been a big help. I am happy that you have shown me a quicker comparison way in my failed attempts the code was kinda huge Razz

THANKS!

_________________
Pjuu ^__^
Post 05 Apr 2005, 10:03
View user's profile Send private message Visit poster's website MSN 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-2020, Tomasz Grysztar.

Powered by rwasa.