flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > File as DB sequence

Author
Thread Post new topic Reply to topic
NEASM



Joined: 13 Apr 2018
Posts: 7
I have a problem. I want to include files in my FASM program, like this:

file db 0x30, 0x1A, 0xCB,
db 0x45, 0xA3, 0x6C....

Exist a program that makes stuff like this? Or exist another method? Thanks in advance. (Sorry for my english, i'm italian).
Post 05 May 2018, 13:49
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6902
Location: Kraków, Poland
The simplest method is to use FILE directive:
Code:
my_file FILE 'name.ext'    
This way you include the binary data directly (some other assemblers, like NASM, have a directive named INCBIN that does the same).

But if for some reason you need to have your entire source in text form, you can also use fasm to convert any binary file into DB definitions:
Code:
BYTES_PER_LINE = 16

virtual at 0
        buffer:: file 'name.ext'
        size = $
end virtual

repeat size
        if (%-1) mod BYTES_PER_LINE = 0
                if %-1 > 0
                        db 13,10
                end if
                db 'DB '
        else
                db ','
        end if
        load a byte from buffer:%-1
        h = a shr 4
        l = a and 0Fh
        if h >= 10
                db '0', 'A' + h - 10
        else
                db '0' + h
        end if
        if l >= 10
                db 'A' + l - 10
        else
                db '0' + l
        end if
        db 'h'
end repeat    
Note: this source works the same with either fasm 1 or fasmg.
Post 05 May 2018, 14:01
View user's profile Send private message Visit poster's website Reply with quote
NEASM



Joined: 13 Apr 2018
Posts: 7
Thanks, Grysztar. I really appreciate your hard work to create a fast, portable and multiplatform assembler. And I have to say, the job succeeded perfectly. In fact, FASM is one of the best assemblers that exist. And, as icing on the cake, one of the best forums there are. Brilliant, and thank you very much for your reply.
Post 05 May 2018, 22:08
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2292
Location: Usono (aka, USA)
Just FYI, I think the tool frequently used for this kind of thing is od (octal dump) although that has somewhat been supplanted in recent OSes with hexdump (and its alias "hd", which IIRC is same as "hexdump -C"). IIRC, for hex output you can use "od -v -Ax -tx1".

Oh, and just to keep barely on-topic, Brian Raiter rewrote hexdump in NASM assembly for Linux (202 bytes!).
Post 05 May 2018, 22:38
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.