开发者

External procedure in FASM

I have been trying to export procedure from external file to the main assembly program, but it didn't work.

Here is test code from external file:

; Export procedure Summa
format PE GUI 4.0

include 'win32a.inc'

section '.code' code readable executable

proc Summa
Public Summa
ret 2
endp

And in the main file I try to attach Summa:

format PE GUI 4.0

include 'win32a.inc开发者_JAVA百科'

section '.data' data readable writeable

extrn Summa as Summa : proc  

While compiling main file I get Illegal Instruction error in the line with extrn keyword.

Tried to search the web, but I wasn't lucky to find how I should attach external procedure in FASM...

Thanks!


I see that you have two GUI executables, so what means "export procedure from external file to the main assembly program"?
Do you want to make two object files (.obj) and then link them together?
Then use format MS COFF in both files, add proper extrn and public directives, and use some linker (for example link.exe) to build .exe file.

Also, read fasm.pdf, section 2.4.3 "Common Object File Format".


With PE, I believe you can import from a DLL like so:

library kernel,'KERNEL32.DLL'

import kernel,\
    ExitProcess,'ExitProcess'

If you use MS COFF, the linking style will be different depending on your bitness 32 or 64:

32-bit:

format MS COFF

section '.data' data readable writeable

extrn '__imp__Summa@0' as Summa:dword     

64-bit:

format MS64 COFF

section '.data' data readable writeable

extrn '__imp_Summa' as Summa:qword

A great example showing linking in 32-bit: https://flatassembler.net/examples/msvc.zip

You can also use extrn with ELF64, Linux example: https://2ton.com.au/rants_and_musings/gcc_integration.html

PE DLL function import example: https://flatassembler.net/examples/quetannon.zip

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜