flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Intel syntax under MinGW

Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Hi!
I know that Mingw (gcc port for windows) uses AT&T syntax. But I've heard that it can use inline asm with intel syntax too. How to do that?
Another question:
How to link fasm generated obj to Mingw generated obj to get a working exe with each module (asm and c) using function from each other?

Thanks!
Post 24 Aug 2005, 17:28
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Compile your code to MS COFF format. In my attempt I used Dev-C++. I copied the compiled .obj file to the source directory and then searched in options. I found it in: Project -> Project options -> Parameters -> Consolidator. Add there a name of your .obj file.
Of course you have also to create .h file or define a prototype somewhere in the source

Hmm... I may write it somewhat obscure, so if you didn't understand anything feel free to ask.
Post 24 Aug 2005, 22:44
View user's profile Send private message Visit poster's website Reply with quote
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware
You can link with any COFF obj, just put it on the gcc command line. So:

fasm mycode.asm mycode.o
gcc -o myprog.exe myprog.c mycode.o

This will work fine. As far as using inline asm w/ gcc, I've never tried it since I hate the ATT syntax.
Post 24 Aug 2005, 23:19
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509
I don't know about mingw in particular, however the latest version of as (aka gas which is part of binutils) also has an .intel directive which tells the assembler to expect Intel syntax over AT&T syntax.

Never used it, as I've just always used fasm (and earlier nasm) to linked the assembled object file with the other C based source. (as ronware describes).
Post 25 Aug 2005, 05:24
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Thanks!
Here is my working test:

C code:
Code:
#include <windows.h>

int main() {
showmsg("Hello!","Test!");
return 0;
}
    


or better:
Code:
#include <windows.h>

void mainCRTStartup() {
showmsg("Hello!","Test!");
}
    

so default libs are ignored using '-nostdlib' and the code is smaller.

FASM code:
Code:
format COFF
include '%fasminc%\win32a.inc'
extrn '__imp__MessageBoxA@16' as MessageBox:dword
public _showmsg
proc _showmsg, msg:DWORD, ttl:DWORD
invoke MessageBox,0,dword[msg],dword[ttl],0
ret
endp
    


And here is an optimization:
Code:
format MS COFF
include '%fasminc%\win32a.inc'
extrn '__imp__MessageBoxA@16' as MessageBox:dword
public _showmsg
section '.text' code readable executable
proc _showmsg, msg:DWORD, ttl:DWORD
invoke MessageBox,0,dword[msg],dword[ttl],0
ret
endp
    

so I have the asm code in .text section and not in another section called .flat.
One question: Is it possible to merge these sections? (.text, .rdata and .idata)

Wow! Never thought that C interface with FASM was so easy and clean! Very Happy
But, just one question: I have to import functions in this format? extrn '__imp__MessageBoxA@16' as MessageBox:dword
Why can't I use just extrn 'MessageBoxA' as MessageBox:dword ?
or can I build import section in COFF format?
if none of these question have an 'yes' as answer, how can I know the number after the '@' (in this case 16)?

Thanks!
Post 06 Sep 2005, 14:30
View user's profile Send private message Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex
Hi Ozzy,

Names like _MessageBoxA@16' are called as decorated or mangled names. Primarly, this feature is related to the C++ language and the number 16 informs the linker that this function takes 16 / (4 bytes/dword) = 4 parameters. If you used ever Masm, you will see that function prototypes are looking like this one below :

Code:
MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD    

The import libraries used with MS COFF linkers like MS link and Pelle's Polink contains decorated names. If you wish to use this linkers with Fasm, you will need include files containing function declarations like extrn '__imp__MessageBoxA@16' as MessageBox:dword

kernel32.inc
Code:
extrndef '__imp__AddAtomA@4',AddAtom
extrndef '__imp__AllocConsole@0',AllocConsole
extrndef '__imp__AllocateUserPhysicalPages@12',AllocateUserPhysicalPages
extrndef '__imp__AreFileApisANSI@0',AreFileApisANSI
extrndef '__imp__AssignProcessToJobObject@8',AssignProcessToJobObject
extrndef '__imp__BackupRead@28',BackupRead
extrndef '__imp__BackupSeek@24',BackupSeek
.
.
etc
    


Code:
macro extrndef decorated_name,name
{
if used name
extrn decorated_name as name : dword
end if
}
    


MASM to FASM function prototype converter
http://board.flatassembler.net/topic.php?t=588

If you wish to use nondecorated names, you have to create your own import libraries for MS COFF linkers:
Quote:

Polib V3.00.1 can create import libraries directly from DLLs. With the /nound switch offered by Polib, it's possible to get import libraries with no underscored names making easy the linkage of Fasm and Sphinx C-- object files. This new version of Polib replaces my old tool dll2lib. ( Thanks Pelle )

http://vortex.masmcode.com/files/implib2.zip

Another method is to link Fasm object files with GoLink. This linker doesn't require any import library.

_________________
Code it... That's all...
Post 06 Sep 2005, 17:42
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex
Hi Ozzy,

An example of using Fasm with Pelles C :

http://www.masmforum.com/simple/index.php?topic=676.0

An example of using Fasm with GoLink :

http://www.geocities.com/wortex00/Fasm_GoLink.zip

_________________
Code it... That's all...
Post 06 Sep 2005, 18:02
View user's profile Send private message Visit poster's website Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf
Intel syntax in inline asm - for MingW/GCC
http://www.reversing.be/article.php?story=20051203194931893
Cheers.

_________________
Raedwulf
Post 02 May 2006, 07:55
View user's profile Send private message MSN Messenger 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 GitHub, YouTube, Twitter.

Website powered by rwasa.