flat assembler
Message board for the users of flat assembler.

Index > Windows > Question on FASM format for an STDCALL object module.

Author
Thread Post new topic Reply to topic
hutch--



Joined: 19 Jun 2003
Posts: 10
hutch-- 23 Dec 2006, 01:53
Hi guys,

I have a question on a topic I cannot find in the FASM PDF file. It is about creating COFF object modules with FASM.

The following format,
Code:
format MS COFF

section '.text' code readable executable

public _ProcName

_ProcName:

    ; assembler code goes here
    


Works OK using C calling convention but I could not work out how to write the module as STDCALL. Its easy enough in code to add the return stack count with RET as is required by STDCALL but i could not find the reference of how to do it.

I don't really want high level PROC notation, I would prefer to start with a label and write the code manually.

Regards,

hutch at movsd dot com
Post 23 Dec 2006, 01:53
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Dec 2006, 02:20
So if you want to manually do the code why "ret numArgs*4" isn't enough?

Including "macro\proc32.inc" or one of the win32*.inc includes you can use the proc macro which automatically adjust the stack accordingly to the selected calling convention when you use "ret" since "ret" is defined as a macro in the context of the procedure and performs the appropiate epilogue sequence. Check http://flatassembler.net/docs.php?article=win32 for more info.

If nothing of this helps you then sorry Razz you have not provided enough code to see what exactly you want (I speak for myself of course).
Post 23 Dec 2006, 02:20
View user's profile Send private message Reply with quote
hutch--



Joined: 19 Jun 2003
Posts: 10
hutch-- 23 Dec 2006, 03:32
The assembler code is the simple part, what I could not find in the reference is how to set the module to STDCALL convention. If I write a conventional C calling convention with the notation I posted in the first post, it works fine.

Now as before this leading code produces a successful C calling convention module.

Code:
format MS COFF

section '.text' code readable executable

public _your_proc_name

_your_proc_name:

  ; assembler code goes here.
    


What I could not find in the reference material was a combination of the "public" directive to make the procedure visible AND the label name that would produce a valid STDCALL object module.

It is NOT code analysis or assistance that I need, its a specific FASM format that will generate a valid object module that is visible to a linker using STDCALL.
Post 23 Dec 2006, 03:32
View user's profile Send private message Reply with quote
hutch--



Joined: 19 Jun 2003
Posts: 10
hutch-- 23 Dec 2006, 03:41
hutch-- wrote:
The assembler code is the simple part, what I could not find in the reference is how to set the module to STDCALL convention. If I write a conventional C calling convention with the notation I posted in the first post, it works fine.

Now as before this leading code produces a successful C calling convention module.

Code:
format MS COFF

section '.text' code readable executable

public _your_proc_name@16

_your_proc_name@16:

  ; assembler code goes here.
    


What I could not find in the reference material was a combination of the "public" directive to make the procedure visible AND the label name that would produce a valid STDCALL object module.

It is NOT code analysis or assistance that I need, its a specific FASM format that will generate a valid object module that is visible to a linker using STDCALL.
Post 23 Dec 2006, 03:41
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Dec 2006, 05:38
Hutch, just in case you want a semi-automatized way then this may help you
Code:
macro public symbol, size
{
  if 1
  match size, size ; To ensure that size will be the actual value
  \{
    if ~ size eqtype 1
      display "Integer spected",13,10
      err
    end if

    public symbol as \`symbol \# '@' \# \`size
  else
  \}
    public symbol
  end if
}

format MS COFF

section '.text' code readable executable 

ProcSize equ 4
public _ProcName, ProcSize

public addNums, 8
_ProcName: 

    ; assembler code goes here

addNums:
  mov eax, [esp+4]
  add eax, [esp+8]
  ret 8     


PS: BTW, thanks for posting your question, it helped me to found a fasm bug Smile
Post 23 Dec 2006, 05:38
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Dec 2006, 09:55
hutch: in FASM, you can export symbol under different name than it has in source. Great feature.

Code:
public ProcName as '_ProcName@16'    
.

This doesn't impose any HLL rules on you. So there is nothing like "stdcall module" or "ccall module" - just a MSCOFF file, with code as you like at, and exports as you like them
Post 23 Dec 2006, 09:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
hutch--



Joined: 19 Jun 2003
Posts: 10
hutch-- 23 Dec 2006, 10:44
vid,

Thanks, its a cleaner solution than the one I found.

Regards,

hutch at movsd dot com
Post 23 Dec 2006, 10:44
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Dec 2006, 16:20
My macro does exactly the same that vid does in "public symbol as \`symbol \# '@' \# \`size". With "public addNums, 8" produces "public addNums as 'addNums@8'" and if you don't specify size argument it produces "public addNums".
Post 23 Dec 2006, 16:20
View user's profile Send private message Reply with quote
hutch--



Joined: 19 Jun 2003
Posts: 10
hutch-- 23 Dec 2006, 23:38
LocoDelAssembly,

Thanks for the offer, your macro looks fine but in the context of the test library that I have up and going, I need to keep it at its most basic notation as I am not all that familiar with specific FASM notation.

Regards,

hutch at movsd dot com
Post 23 Dec 2006, 23:38
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.