flat assembler
Message board for the users of flat assembler.

Index > Main > code and data sections

Author
Thread Post new topic Reply to topic
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf
Hi there,
I'd like to know if there is a clean way of producing a single bin file from two or more source files.

Let's assume we have the following two files:

_____file1.asm_____
org 0
code1:
mov eax, ebx
mov ecx, eax

org 0
data1:
d1 dw ?

_____file2.asm_____
code2:
cmp eax, ecx
je @f
@@:
xor eax, eax
data2:
d2 dw ?

What I need is the binary file generated by
_____file.asm_____
org 0
code1:
mov eax, ebx
mov ecx, eax
code2:
cmp eax, ecx
je @f
@@:
xor eax, eax

org 0
data1:
d1 dw ?
data2:
d2 dw ?
---------------------

For now, what I do is make use of some conditional compilation and include my asm source files in a single main source file.
I include my files twice: the first time the code is taken, while the second time the data is taken.
Post 27 Feb 2009, 23:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17346
Location: In your JS exploiting you and your system
revolution
1) You can use a linker. Put all the various bits of your code into sections, and then use the linker to merge the sections together in the order you specify.

2) Use macros. Enclose each of the sections within a macro definition, and then at the end instantiate the macros in the order that you need.
Post 28 Feb 2009, 01:38
View user's profile Send private message Visit poster's website Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf
revolution wrote:
1) You can use a linker. Put all the various bits of your code into sections, and then use the linker to merge the sections together in the order you specify.


Which free linker would you recommend?
Post 28 Feb 2009, 10:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17346
Location: In your JS exploiting you and your system
revolution
gandalf wrote:
revolution wrote:
1) You can use a linker. Put all the various bits of your code into sections, and then use the linker to merge the sections together in the order you specify.


Which free linker would you recommend?
I don't use linkers. So I can't recommend any. I leave the question open for others to make suggestions.
Post 28 Feb 2009, 10:45
View user's profile Send private message Visit poster's website Reply with quote
gandalf



Joined: 27 Feb 2009
Posts: 31
gandalf
Quote:
I don't use linkers. So I can't recommend any. I leave the question open for others to make suggestions.


The problem is that I need binary files (for an OS-like project) and AFAIK fasm doesn't support sections in binary format (how could it?)
I would need to make fasm produce a, say, MS COFF file, link it and then convert it into a binary file, or something like that.
Developing my own ad-hoc linker would probably be simpler than figuring out how to make all this work out.

Wouldn't the use of macros make the error reporting less readable?
I think I'll get rid of conditional comp... assembling and create separate code and data asm files:
list_c.asm
list_d.asm
tree_c.asm
tree_d.asm
BTW, having code and data on different files is even more convenient because you can keep them in two different edit windows and switch between them instantly.
Post 28 Feb 2009, 11:07
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
For windows I would suggest MS linker (link.exe + DLLs, available in any compiler package). Then you need to separately compile both files to MS COFF .obj files, and use linker to merge them.

Quote:
Wouldn't the use of macros make the error reporting less readable?

Yeah, somewhat. But nothing extremely hard.
Post 28 Feb 2009, 13:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Wait, doesn't NASM / YASM support multi-section binary??

And as for making COFF into flat binary, can't GNU BinUtils OBJCOPY do that??
Post 09 Mar 2009, 01:36
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 YouTube, Twitter.

Website powered by rwasa.