flat assembler
Message board for the users of flat assembler.

Index > Main > Integer to string

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 03 Aug 2018, 19:02
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: 20292
Location: In your JS exploiting you and your system
revolution 03 Aug 2018, 19:08
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: 133
Location: Russia
Jin X 03 Aug 2018, 19:28
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: 20292
Location: In your JS exploiting you and your system
revolution 03 Aug 2018, 19:33
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.