flat assembler
Message board for the users of flat assembler.

Index > Main > Formatter directives

Author
Thread Post new topic Reply to topic
negativeIQ



Joined: 03 Oct 2004
Posts: 7
negativeIQ 03 Oct 2004, 19:06
Hi, I'm a newbie. Maybe this is a stupid question, but I cannot figure out the answer. I've already searched the forum with no success.

Reading the documentation of fasm I've encountered the formatter directives. Now suppose to write an asm file from scratch and to specify a format.Which format specific directives are mandatory, which are optional, what is the structure to respect? Can you give me some hint or point me to some documentation?

Thanks in advance.

Bye.
Post 03 Oct 2004, 19:06
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 03 Oct 2004, 20:35
hi,
It is difficult to say whick directives are optional and which are not. First of all, you have the "format" directive, this one determines set of other directives that you an use. So, with "format PE", output will be generated in windows-exe format, and you will have PE-specific directives available: section, rva, etc. But don't think about these directives in "mandatory or optional" category, rather browse available examples and see how they are used. This is the best way to learn them.
Post 03 Oct 2004, 20:35
View user's profile Send private message Visit poster's website Reply with quote
negativeIQ



Joined: 03 Oct 2004
Posts: 7
negativeIQ 03 Oct 2004, 21:16
Hi, tanks for answering.
I had a look into the examples and I'm even more puzzled than before. I mean the use of these directives (format specific ones) seems to be arbitrary. For example if I write this:

format PE
x db 0

It would compile despite the fact I haven't included the data definition into a data section...

Further help will be appreciated. Thanks.

Bye.

P.S. another question: does the fasm documentation really cover anything one should know about fasm or is it far from complete?
Post 03 Oct 2004, 21:16
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 04 Oct 2004, 10:35
Quote:

format PE
x db 0

It would compile despite the fact I haven't included the data definition into a data section...

there is no difference between data and code in compiled program, both are "data", only things that matters is if processor tries to execute "data" (instructions in machine language).

And later when you learn self-modifying code you'll find out that something like "x db 0", doesn't have to be nescessary data definition, for example in old DOS viruses you often see things like (something db 90h), which is hardcoded "nop" instruction (does nothing) which has opcode 90h in machine language, and can be replaced by another one-byte opcode.

PS2: it covers most one should know about FASM. But about FASM, not about assembly. And also there are some "extreme" cases that are not covered into detail because it will make documentation hardly readable.

Also try to look at my tutorial somewhere in section main (i don't have link now, sorry, sitting behind friend's computer...).
Post 04 Oct 2004, 10:35
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
negativeIQ



Joined: 03 Oct 2004
Posts: 7
negativeIQ 04 Oct 2004, 10:43
Ok, but I'd like to know if (in the case of PE for example) I'm "forced" to use:

section '.code' code readable executable
section '.data' data readable writeable

or other directives. Is there a pattern to follow?

Thanks, bye.
Post 04 Oct 2004, 10:43
View user's profile Send private message Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer 04 Oct 2004, 11:49
negativeIQ wrote:
Ok, but I'd like to know if (in the case of PE for example) I'm "forced" to use:

section '.code' code readable executable
section '.data' data readable writeable

or other directives. Is there a pattern to follow?

Thanks, bye.


Look at the beer example from fasm package.

_________________
Best regards,
Antoch Victor
Post 04 Oct 2004, 11:49
View user's profile Send private message Yahoo Messenger Reply with quote
negativeIQ



Joined: 03 Oct 2004
Posts: 7
negativeIQ 04 Oct 2004, 12:02
Thanks for the hint.

; no section defined - fasm will automatically create .flat section for both
; code and data, and set entry point at the beginning of this section

But is this also true for other file formats (different than PE)? I mean: can I write code only specifying the format without using any other directive?

Thanks, bye.
Post 04 Oct 2004, 12:02
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 04 Oct 2004, 13:25
negativeIQ wrote:
P.S. another question: does the fasm documentation really cover anything one should know about fasm or is it far from complete?


Fasm documentation covers near everything Fasm related. The full x86 instruction set is far beyond the scope of Fasm documentation. The same is true for the platform specific topics such as DOS interrupts, Windows API's or Linux syscalls.

Regarding formatter, take into account this:
Fasm will stick to your orders. It will not take any decision for you. For example, you can put code in your data section or viceversa and fasm does not complain at all. You can call sections as you wish and have any number of sections and Fasm will not issue neither a warning about it.
This is an advantage, but comes at the expense of having to know how the format should be, how the thing works.

If you don't specify any Format directive, the default is a plain binary file. Mnemonics will be translated into opcodes, data will go as it is and in the place you define it.

Each format comes with certain directives depending on its nature. Everything's optional and there is a default if you don't specify a directive.

Hope it helps Wink
Post 04 Oct 2004, 13:25
View user's profile Send private message Yahoo Messenger Reply with quote
negativeIQ



Joined: 03 Oct 2004
Posts: 7
negativeIQ 04 Oct 2004, 15:46
Thanks for answering. I'm running some experiment to better understand this topic.

In particular I'm trying to write a simple asm function that I call from a C program. After exploring cdecl.inc I discovered cproc (that is not documented into fasm manual).

I compile the asm file specifying COFF format with no additional directives.

I compile and link (using LCC compiler): lc project.c function.obj

And LC warns me like this:
File function.obj contains unknown section .flat.
.text section assumed

So I guess these specific directives have some importance...

Bye.

P.S. maybe this is a subject for anothe topic, however: what does actually cproc and endp do? The macro language they're written in is hard to read for me.
Post 04 Oct 2004, 15:46
View user's profile Send private message 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.