flat assembler
Message board for the users of flat assembler.

Index > Main > I found a new way of using FASM.

Author
Thread Post new topic Reply to topic
2



Joined: 26 Sep 2006
Posts: 92
2
I was playing with FASM directives on Linux.
This source makes a text file using no actual assembly instructions.
I found some uses for while loops and assembly time variables.

Code:
x=0
while x<0x100
b=x
z=0
while z<8
b=b and 0xFF
y=b shr 7
db y or 0x30
b=b shl 1
z=z+1
end while
db 0xA
x=x+1
end while
    


BTW,the "db 0xA" is a Linux newline. You might want to add an extra line of "db 0xD"
if you're using DOS/Windows .

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.
Post 26 Mar 2007, 05:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
Very good, you might also be interested in this thread
Post 26 Mar 2007, 11:45
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Check out also the "Using flat assembler as pure interpreter" section of the Understanding fasm article.
Post 26 Mar 2007, 12:04
View user's profile Send private message Visit poster's website Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
Yes,FASM has a bigger use than any program I've ever encountered.

A long time ago,I was looking for the idea of regenerating files which contained many
repeated bytes.

I tried writing C programs which opened a file, wrote bytes to it and closed it.

FASM can do all that in with less. For example,you need only the FASM executable,
you don't need to include any stdio.h or main() .

Seriously,thanks for making FASM great enough to be used as an every day tool !

It's a perfect example of what an assembler should be.
It "assembles" anything. Not just programs!
Post 26 Mar 2007, 20:57
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
Also,thought this might be worth sharing.
It's rather weird,but it ran just fine.
It makes a text file of decimal powers of 2.

Code:
macro dec16dig a
{
b=a
z=0
while z<0x10
while b>9999999999999999
b=b-10000000000000000
end while
y=b / 1000000000000000
db y or 0x30
b=b*0xA
z=z+1
end while
}

d0=1
d1=0
e=0
while e<=64
dec16dig d1
dec16dig d0
db 0xA

d0=d0 shl 1
d1=d1 shl 1
if d0>9999999999999999
d0=d0-10000000000000000
d1=d1+1
end if

e=e+1
end while
    
Post 03 Apr 2007, 03:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
I have been using a similar macro that suppresses leading zeros and you can choose signed or unsigned versions. Another advantage is it will display almost all possible values (64 bits) correctly, see below for the corrected code.
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
}    


Last edited by revolution on 24 Dec 2007, 13:09; edited 1 time in total
Post 03 Apr 2007, 11:11
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
hey revolution, nice one, thanks
Post 03 Apr 2007, 11:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
2 wrote:

This source makes a text file using no actual assembly instructions.

Nice it seems ! But. What's in the text file ? Curious !
Post 05 Apr 2007, 10:59
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
2 wrote:
It makes a text file of decimal powers of 2.
Post 05 Apr 2007, 15:09
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Very nice!
Thanks for the macros revolution!

We can use FASM for testing logical expressions or math:

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
}

x=0001b
y=1111b
z = x or y
display_unsigned z 
    

This can be used for making "LIVE" comments on the source.
Example:
Code:
include "display_macros.inc"

mov eax,2
add eax, 4
; Live comments:
x=2
y=4
z=x+y
display "eax="
display_unsigned x
display "; "
display "eax=eax+"
display_unsigned y
display "; "
display "eax="
display_unsigned z
display "; "   
    

Try it and see the output!
Wrapping it into some macros it can turn into useful debugging tool. Very Happy
Post 30 May 2007, 15:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
A bug found. I didn't properly test all the corner cases. New code:
Code:
macro display_decimal value*,put_zeros {
    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=put_zeros+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'
       display_decimal number
  else
            display '1'
       display_decimal number,1
        end if
    else
  display_decimal number
    end if
}    
The bug only affected numbers between 10000000000000000000 (1e19) and 10999999999999999999 so I assume no one was printing numbers of this size. But still better to be safe than sorry.
Post 24 Dec 2007, 13:03
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.