flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > Intel syntax under MinGW |
Author |
|
Reverend 24 Aug 2005, 22:44
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. |
|||
24 Aug 2005, 22:44 |
|
ronware 24 Aug 2005, 23:19
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. |
|||
24 Aug 2005, 23:19 |
|
Chewy509 25 Aug 2005, 05:24
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). |
|||
25 Aug 2005, 05:24 |
|
OzzY 06 Sep 2005, 14:30
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! 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! |
|||
06 Sep 2005, 14:30 |
|
Vortex 06 Sep 2005, 17:42
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:
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... |
|||
06 Sep 2005, 17:42 |
|
Vortex 06 Sep 2005, 18:02
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... |
|||
06 Sep 2005, 18:02 |
|
Raedwulf 02 May 2006, 07:55
Intel syntax in inline asm - for MingW/GCC
http://www.reversing.be/article.php?story=20051203194931893 Cheers. _________________ Raedwulf |
|||
02 May 2006, 07:55 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.