flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Integer to string

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
Is there some directive or macros to convert integer constant value to string?
I.e. I have a constant value: SomeInt = 1000
Now I want to define string: SomeStr db '1000'
But I want to use SomeInt value to convert this string Smile

How can I do this?

p.s. I need something like %defstr in NASM.
Post 03 Aug 2018, 19:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
Here is a macro to display integer values. You can convert it to embed integer values by changing all display to db and make it a struc instead of macro to allocate the string to a label name.
Code:
macro display_decimal value {
    local leading_zero,digit,divisor,number
    number=value
    if number=1 shl 63
        display '-9223372036854775808'
    else
        if number<0
            number=-number
            display '-'
        end if
        leading_zero=0
        divisor=1000000000000000000
        while divisor>0
            digit=number/divisor
            leading_zero=leading_zero+digit
            if leading_zero | (divisor=1)
                display digit+'0'
                number=number-digit*divisor
            end if
            divisor=divisor/10
        end while
    end if
}
macro display_unsigned value {
    local number
    number=value
    if number<0
        number=number-10000000000000000000
        if number<0
            number=number+1000000000000000000
            display '9'
        else
            display '1'
        end if
    end if
    display_decimal number
}    
Post 03 Aug 2018, 19:08
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
So, there's no special directive... Sad
Post 03 Aug 2018, 19:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
Not in fasm.
Post 03 Aug 2018, 19:33
View user's profile Send private message Visit poster's website 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-2018, Tomasz Grysztar.

Powered by rwasa.