flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > Compile FASM to obj file |
Author |
|
revolution 06 Jul 2013, 21:17
I'm not sure what you are asking so here is the fasm example for MS COFF format:
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 push _caption push _message push 0 call [MessageBox] ret section '.data' data readable writeable _caption db 'Win32 assembly',0 _message db 'Coffee time!',0 |
|||
06 Jul 2013, 21:17 |
|
Teddy 06 Jul 2013, 22:31
Hello Revolution.
Thanks for your reply. I'm sorry if my first message was confused. To summarize, I want to compile "FASM compiler" to get an ".obj" file, so I can then use it in a library written in C++. I thought using MS COFF format (I think this is the best for that, but I'm not completely sure). I'm encountering some issues when I try to compile FASM for Win32 with the MS COFF format, because it seems the import section is slightly different between the legacy PE format and the MS COFF format. Do you have any advice to get an .obj format or something else I can use in my C++ library ? Teddy. |
|||
06 Jul 2013, 22:31 |
|
bitRAKE 06 Jul 2013, 23:08
I started with FASM DLL, and then put:
Code: format MS COFF extrn '__imp__CreateFileA' as CreateFile:dword extrn '__imp__ReadFile' as ReadFile:dword extrn '__imp__WriteFile' as WriteFile:dword extrn '__imp__CloseHandle' as CloseHandle:dword extrn '__imp__SetFilePointer' as SetFilePointer:dword extrn '__imp__GetCommandLineA' as GetCommandLineA:dword extrn '__imp__GetEnvironmentVariableA' as GetEnvironmentVariable:dword extrn '__imp__GetStdHandle' as GetStdHandle:dword extrn '__imp__VirtualAlloc' as VirtualAlloc:dword extrn '__imp__VirtualFree' as VirtualFree:dword extrn '__imp__GetTickCount' as GetTickCount:dword extrn '__imp__GetSystemTime' as GetSystemTime:dword extrn '__imp__GlobalMemoryStatus' as GlobalMemoryStatus:dword Oh, you'd want to specify the export functions as public. Code: public fasm_GetVersion public fasm_Assemble public fasm_AssembleFile |
|||
06 Jul 2013, 23:08 |
|
Teddy 07 Jul 2013, 01:00
Hello bitRAKE.
Thanks for your message. What a brilliant idea to start working on the FASM DLL project ! I managed to perform the same actions you did to compile the project. After several tests, MS COFF format requires the mangled names of the exported functions. Here are the mangled names I used to get it perfectly working: Code: extrn '__imp__CreateFileA@28' as CreateFile:dword extrn '__imp__ReadFile@20' as ReadFile:dword extrn '__imp__WriteFile@20' as WriteFile:dword extrn '__imp__CloseHandle@4' as CloseHandle:dword extrn '__imp__SetFilePointer@16' as SetFilePointer:dword extrn '__imp__GetCommandLineA@0' as GetCommandLineA:dword extrn '__imp__GetEnvironmentVariableA@12' as GetEnvironmentVariable:dword extrn '__imp__GetStdHandle@4' as GetStdHandle:dword extrn '__imp__VirtualAlloc@16' as VirtualAlloc:dword extrn '__imp__VirtualFree@12' as VirtualFree:dword extrn '__imp__GetTickCount@0' as GetTickCount:dword extrn '__imp__GetSystemTime@4' as GetSystemTime:dword extrn '__imp__GlobalMemoryStatus@4' as GlobalMemoryStatus:dword I analyzed the file kernel32.dll using IDA to get these names. |
|||
07 Jul 2013, 01:00 |
|
Teddy 07 Jul 2013, 16:12
Just a little precision. If I correctly understood, the calling convention of FASM DLL is __stdcall right ?
I'm saying that because I had to edit the ret 20 instruction of the end of the Fasm_Assemble function into ret to make it __cdecl. |
|||
07 Jul 2013, 16:12 |
|
bitRAKE 07 Jul 2013, 17:56
Your understanding is correct.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
07 Jul 2013, 17:56 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.