flat assembler
Message board for the users of flat assembler.

Index > Main > fasm newbie questions

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 05:51
I don't really have a problem with fasm, there are some things that annoys me and sometimes tempts me to switch to another assembler, really just minor simple problems, but they do bother me, and please show a little respect for these silly questions.

Question 1: When I am using a COM interface, I were not able to declare one inside a local procedure, I had to declare in the global section. Could I get a full example of how to declare interfaces, how to use them in procedures and outside procedures. (In NASM I designed macros to handle interfaces and it's so easy to do that when you get to design your own macros for that stuff) But I would really appreciate some input on this in fasm.

Question 2: Another minor issue for me is when I am coding in MS COFF mode and I want to compile COFF objects. I want to be able to use the extended features of fasm (.if, .then) and all the layers that it offers, but it seems to be including all the API functions too when I include the win32ax include file, is this too much to include for a simple coff project? Should I include that file for simple coff projects?

Question 3: Can I reference structures with pointer to structures in the procedure argument? How?

Question 4 (A very bothersome issue for me): In NASM, I can simply switch to the data segment by issuing a macro [SECTION] to switch to the data section and I can declare data anywhere in source code and it will be put into the active section. How can I declare data in the data section without adding it directly to the data section manually? This problem is one of the problems that caused me to abandon fasm, I couldn't find an easy way to live with this.

Question 5: The fixup section, should I include it in every new project? What exactly should I put in it? This bothers me quite a bit, an explanation would be appreciated.

Question 6: In NASM I provide the -e command line option to see the output from macros, how can I do that in fasm to see what my macros produce?

Question 7: How can I make a section shared, using fasm? The fasm manual does not specify or support all the flags that I need to use.

Question 8: How does fasm treat data declared as .bss and .data, are there any merging going on?

Question 9: I have some fasm source files made by someone else and they use 'on nul' on top of the source file, what does this do?

Question 10: How can I customize the prologue and epilogue of my proc without interfering with the rest of the proc endp structure?

Question 11: Because fasm is self compiling, how can I replace the linker option for giving my DLL delayload?

Question 12: Does fasm have mechanisms for using SEH or do I have to create a macro myself?

Question 13: How can I detect the target architecture, in other assemblers you can restrict it by issuing a .386 directive, and so on, but in fasm I don't know how to detect the final architecture without going through all the instructions manually.

Question 14: How can i temporarily disable fasm's optimization?

Question 15: How can I align the stack when I use proc and endp?

Question 16: (Not very relevant): How can I customize the dos stub from fasm?

Question 17: How can I specify the executable base address or use the fixed base address option?

Question 18: The include files in fasm has removed the conditional testing for different versions of windows, are there any flags I can set so the include files works for a specific windows version?

Question 19: Fasm ships with wsock32 which is deprecated and is a stub for ws32, are there plans to include the most up to date winsock include file?

Question 4 and question 6 is by far the most important to me. I must be able to declare global data from within my macro's and from anywhere without having to manually add it to the global data section.


Last edited by PeExecutable on 27 Jun 2015, 06:44; edited 3 times in total
Post 27 Jun 2015, 05:51
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 27 Jun 2015, 06:35
Master, you are actually here to bash FASM, not as an honest user of FASM posting honest questions. That kind of attitude will take you nowhere. I learned this from my Guru in Tibet

You told us that you been struggling to understand FASM for quite some time but your post number is barely 7 posts in total? That shows your true color and intention. Clearly you are extremely mad about the other thread bashing NASM. I knew it!!

I am reporting you to Frank Kotler now. Maybe you could use some good advise from him for your bad attitude.

Are we still friends or what?
Post 27 Jun 2015, 06:35
View user's profile Send private message Visit poster's website Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 06:39
These are real questions that I wonder about. If you don't want to answer, leave it to someone else.
Post 27 Jun 2015, 06:39
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 27 Jun 2015, 06:47
PeExecutable wrote:
These are real questions that I wonder about. If you don't want to answer, leave it to someone else.
Your extreme hatred towards FASM is not good for FASM-NASM long-nurtured friendships. Our 2 communities been like brothers for years and now this??? You can even find NASM users in this thread (e.g dogman) and he's taking it more openly. Why can't you? -_-
Post 27 Jun 2015, 06:47
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 27 Jun 2015, 06:55
I am through with this dude / girl. That hatred.....

I am back to bed now.
Post 27 Jun 2015, 06:55
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 27 Jun 2015, 07:18
PeExecutable wrote:
Question 2: Another minor issue for me is when I am coding in MS COFF mode and I want to compile COFF objects. I want to be able to use the extended features of fasm (.if, .then) and all the layers that it offers, but it seems to be including all the API functions too when I include the win32ax include file, is this too much to include for a simple coff project? Should I include that file for simple coff projects?
Just include the file 'if.inc' when you want to use it.
PeExecutable wrote:
Question 3: Can I reference structures with pointer to structures in the procedure argument? How?
Yes. Just use the structure label name.
Code:
struc xyz ... {<stuff>}
the_struc xyz ...
stdcall function, the_struc, ...    
PeExecutable wrote:
Question 4 (A very bothersome issue for me): In NASM, I can simply switch to the data segment by issuing a macro [SECTION] to switch to the data section and I can declare data anywhere in source code and it will be put into the active section. How can I declare data in the data section without adding it directly to the data section manually? This problem is one of the problems that caused me to abandon fasm, I couldn't find an easy way to live with this.
You can switch sections with the 'section' directive. You could also make a macro to switch to a data section, place some data, then switch back to code.
PeExecutable wrote:
Question 5: The fixup section, should I include it in every new project? What exactly should I put in it? This bothers me quite a bit, an explanation would be appreciated.
DLLs require fixups. EXEs don't require, but can also be included if wanted (for ASLR or whatever). Just leave the section empty in the source and fasm fills it in with the actual fixups.
PeExecutable wrote:
Question 6: In NASM I provide the -e command line option to see the output from macros, how can I do that in fasm to see what my macros produce?
There is an external tool in the 'tools' folder that shows the pre-processed source.
PeExecutable wrote:
Question 7: How can I make a section shared, using fasm? The fasm manual does not specify or support all the flags that I need to use.
The fasm.pdf says this:
fasm manual wrote:
section directive defines a new section, it should be followed by quoted string defining the name of section, then one or more section flags can follow. Available flags are: code, data, readable, writeable, executable, shareable, discardable, notpageable.
PeExecutable wrote:
Question 8: How does fasm treat data declared as .bss and .data, are there any merging going on?
It is the linkers job to merge sections. If you use a direct exe output then nothing is merged. If you need merging then use a linkable output.
PeExecutable wrote:
Question 9: I have some fasm source files made by someone else and they use 'on nul' on top of the source file, what does this do?
This means the PE stub is empty.
PeExecutable wrote:
Question 10: How can I customize the prologue and epilogue of my proc without interfering with the rest of the proc endp structure?
Look for prologue@proc and epilogue@proc.
PeExecutable wrote:
Question 12: Does fasm have mechanisms for using SEH or do I have to create a macro myself?
Use a macro. There is no native support for SEH.
PeExecutable wrote:
Question 13: How can I detect the target architecture, in other assemblers you can restrict it by issuing a .386 directive, and so on, but in fasm I don't know how to detect the final architecture without going through all the instructions manually.
You can't. But there are macros available that can emulate this (but somewhat out-of-date now). http://board.flatassembler.net/topic.php?t=6921
PeExecutable wrote:
Question 14: How can i temporarily disable fasm's optimization?
Do you mean size optimisation for immediates? If so then use an override like byte or dword.
PeExecutable wrote:
Question 15: How can I align the stack when I use proc and endp?
See question 10.
PeExecutable wrote:
Question 16: (Not very relevant): How can I customize the dos stub from fasm?
See question 9.
PeExecutable wrote:
Question 17: How can I specify the executable base address or use the fixed base address option?
See the documentaion for the 'format' directive.
PeExecutable wrote:
Question 18: The include files in fasm has removed the conditional testing for different versions of windows, are there any flags I can set so the include files works for a specific windows version?
I've not seen any. Someone may have made some includes.
PeExecutable wrote:
Question 19: Fasm ships with wsock32 which is deprecated and is a stub for ws32, are there plans to include the most up to date winsock include file?
I am sure that the suthor is happy to receive any updates and new definitions files.
Post 27 Jun 2015, 07:18
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 27 Jun 2015, 07:32
With regard to section merging there are macros that can merge different parts of the source together. This would allow the generation of EXEs directly with everything merged accordingly.

See: http://board.flatassembler.net/topic.php?t=12012
Post 27 Jun 2015, 07:32
View user's profile Send private message Visit poster's website Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 08:12
Wow, that was fast. Thanks for the speedy replies. About question 4 (changing sections): I assume if I put an align directive/macroinstruction right after the section directive, the alignment will be applied to that section which is active. I hope.

Code:
mov eax, 10
section .data
align 16
  _tea db 'A cup of tea',0
section .code
mov ecx, 20
    


Btw. You have no idea how eager I am to go back to fasm, after using nasm with my own custom macros, with a big lack of ability for using .if .then and so forth. If I just can manage to MASTER fasm this time, and fully. So that I don't have to go back again to another assembler, because fasm is outstanding, it's just that I need to get the things working, so I don't get stuck again.

The thing about changing sections in fasm, I had no idea that it was just like nasm.

I'm the kind of guy who likes to have huge projects manageable with master include files, then minor include files, perhaps with make files and the ability to build huge libraries with one command. That's how I like to do things.


Last edited by PeExecutable on 27 Jun 2015, 08:23; edited 1 time in total
Post 27 Jun 2015, 08:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 27 Jun 2015, 08:21
Yes, the alignment is active only where you place it. So it would place anywhere from zero to fifteen NOP instructions. But each new section will get a 'natural' alignment so putting align at the beginning of a section does nothing.

BTW your example of usage of 'section' is not correct for fasm, unless you are using a macro named 'section'.
Post 27 Jun 2015, 08:21
View user's profile Send private message Visit poster's website Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 08:24
Ok, quotes missing, I see that now
Post 27 Jun 2015, 08:24
View user's profile Send private message Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 09:01
You mentioned to include 'if.inc' in my ms coff project source files to replace win32ax.inc

But if I also want to be able to nest my procedure calls, are there other include files other than if.inc I should put into my ms coff source files?
Post 27 Jun 2015, 09:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 27 Jun 2015, 09:16
You can still include 'win32ax.inc' in MS COFF sources. No harm will come. It implicitly includes 'if.inc' as part of it. It is really up to you what you want to include. Anything you don't use would make outputs from things like 'PREPSRC.INC' too verbose, but otherwise nothing will break.
Post 27 Jun 2015, 09:16
View user's profile Send private message Visit poster's website Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 09:22
I tried to change to the data section and back to code again as shown in this sample. It did work but with one minor issue, the debug window shows that fasm has put 2 int3 instructions right where I change to the data section. What have I done wrong? Question
Code:
; example of making Win32 COFF object file

format MS COFF

extrn '__imp__MessageBoxA@16' as MessageBox:dword

section '.text' code readable executable

 public _demo

 _demo:
        push    0
section '.data' data readable writeable
        _tea db 'A cup of tea',0
section '.text' code readable executable
        push    _caption
        push    _message
        push    0
        call    [MessageBox]
        ret

section '.data' data readable writeable

 _caption db 'Win32 assembly',0
 _message db 'Coffee time!',0    


The two int3 instructions align it by 4, it seems to. But thats not what I expected it to do. It shouldn't align the code section by 4. I expected it to put the _tea string below the _message string in the data section and continue code flow normally.

One another question: EQU's in my previous assemblers have always been absolutely constant, unchangeable. In fasm you can change them and (pop them) but if there is a way to define non-changeable constants let me know. I highly appreciate and respect the traditional purpose of EQU where it can't change, and if it can change the compiler ought to at least tell about it in a warning (which it does not do). EQU's are one of my beloved children in asm, i'd like some input on this.


Last edited by PeExecutable on 14 Jul 2015, 16:38; edited 2 times in total
Post 27 Jun 2015, 09:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 27 Jun 2015, 12:28
The manual specifies this in 2.4.3 Common Object File Format
Quote:
By default section is aligned to double word (four bytes), in case of Microsoft COFF variant other alignment can be specified by providing the align operator followed by alignment value (any power of two up to 8192) among the section flags.
Post 27 Jun 2015, 12:28
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 27 Jun 2015, 12:55
The only way that I am aware of generating an error (not a warning) when a variable is redefined would be with the assembler equals (=) assignment.
Code:
assert x or 1 ;check if x is defined only once
x=1    
Quote:
flat assembler version 1.71.39 (3145344 kilobytes memory)
2 passes, 0 bytes.
-------------------------------------------------------------------------------------------
Code:
assert x or 1 ;check if x is defined only once
x=1
x=2 ;redefine x    
Quote:
flat assembler version 1.71.39 (3145344 kilobytes memory)
test.asm [1]:
assert x or 1
error: symbol 'x' out of scope.
Post 27 Jun 2015, 12:55
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 27 Jun 2015, 13:28
revolution wrote:
The only way that I am aware of generating an error (not a warning) when a variable is redefined would be with the assembler equals (=) assignment.
You could use "LABEL ... AT ..." construct for this purpose, in fact the only difference between numeric symbols defined with LABEL and = is that the former cannot be redefined.

In fasm g there is a ":=" construct that allows a short form definition of numeric (or linear polynomial) constant, but it does in fact have the same effect as "LABEL ... AT ...", it is just shorter and simpler. With fasm g it is also possible to have a forward-referenced symbolic constant, though I did not invent any syntax analogous to ":=" that would apply to symbolic values.
Post 27 Jun 2015, 13:28
View user's profile Send private message Visit poster's website Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 16:24
To rephrase the question, what methods do you guys use to place data in the data section when you need to do it from anywhere. What method should I use to get the _tea string placed exactly below the _message string? (without the int3 instructions preferably) Very Happy
Post 27 Jun 2015, 16:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 27 Jun 2015, 16:29
Did you read the link to the list building macros?

Did you read the quote from the manual about using align with the section directive?

You appear to be asking the same questions again so I am unsure where you are currently at.
Post 27 Jun 2015, 16:29
View user's profile Send private message Visit poster's website Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 16:37
I am lazy at times, will check it out Very Happy
Post 27 Jun 2015, 16:37
View user's profile Send private message Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 27 Jun 2015, 18:08
I read through the list builder, I understand the concept. You basically take over the charge of defining the sections from inside your own macros, and thereby you can also control the order of defined data. It's smart and I like it.

But apart from that, if we go back to a fasm-point of view, the goal of a macro engine of an assembler (in my opinion), is to make it powerful and flexible, but once you need a macro to strongly override the default behavior of an assembler, time has come for standardization.

A macro system is designed to help you use the assembler, but when a macro system moves into the domain of overriding the entire assembler, time has come to standardize things.

It's misuse of the macro system.

A good principle is: 1. If something is frequently needed, standardize it and put it in code instead of having people do it in macros.

Thanks, that doesn't mean I hate it

(When power become necessary, it becomes weakness)

I mean, just think about it, we're actually talking about removing white lines in .fas files only to implement a feature to define data elements in the data section. We've moved into a crazy thing here only to get one feature (that most people expect already to be implemented in any language). Standardize it, just do it. Every indication points toward doing that. Standardize it if it becomes a big problem. There is a fine line between logic and madness. This thing we're talking about, is madness.

The macro system is designed to help the assembly programmer, but when macros goes into the act of replacing what the assembler can't already do, it's bad philosophy.

Other than that, thanks for the list builder.

But listen carefully to what I have to say about this, take it seriously. "If you let the macro system take over everything with the assembler, people will stop appreciating macros and they will lose respect of it".

People will get respect for the macro system, when they can use it in small things.

A powerful macro assembler, and a loveable macro assembler is one the user can use without the actual need to use macros, in that way, macros become a luxury.


Last edited by PeExecutable on 27 Jun 2015, 18:27; edited 4 times in total
Post 27 Jun 2015, 18:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.