flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > GNU 'g77' Fortran interface with FASM subroutine (ia32) |
Author |
|
revolution 24 Jun 2017, 15:43
There are three methods I can think of that your Fortran compiler might support.
|
|||
24 Jun 2017, 15:43 |
|
NimbUs 24 Jun 2017, 16:12
Hi revolution ! Thank you for the kind attention !
The devil - as we know - is in the details, and it is the interfacing details I am querying for. As for your genral suggestions, 1. I don't think g77 has a mechansm whereby compiled programs would run (MS windows) DLLs 3. g77 does not support inline assembly, unlike some newer GNU Fortran compilers. 2. This, I guess, is what I'm asking, a "how-to" : details of all the needed glue. I am not even sure of the format of object files used by Fortran, though I assume they would be Coff rather than old Intel/MS "OMF". Can FASM output object modules instead of statically compiled whole programs ? How do we instruct it it do so ? How does it exmport/import public names ? I'd really really need to see a sample, or template albeit incomplete. -- NimbUs[/i] Last edited by NimbUs on 24 Jun 2017, 16:15; edited 1 time in total |
|||
24 Jun 2017, 16:12 |
|
revolution 24 Jun 2017, 16:14
fasm comes with example files in the download. Look in the "EXAMPLES" folder for MSCOFF.ASM file. You should find this:
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 |
|||
24 Jun 2017, 16:14 |
|
Xorpd! 25 Jun 2017, 01:46
g77 can run DLLs. Just make a *.LIB file when you make the *.DLL and link against the *.LIB file and make sure the *.DLL is in your path when you run the executable. Now, if the *.DLL procedure is STDCALL that may be a problem.
You can find out the format of a *.OBJ file or *.o file with objdump.exe, which comes with the GNU utilities, thus you probably already have it in your path as a consequence of having installed g77. FASM can compile to *.OBJ files. The secret sauce is 'format MS coff' or 'format MS64 coff' or 64-bit code. It can export name via the public keyword. A brief example: Code: D:\gfortran\clf\rdtsc>type rdtsc_32.asm format MS coff section '.text' code readable executable public _rdtsc_32_ _rdtsc_32_: rdtsc ret D:\gfortran\clf\rdtsc>fasm rdtsc_32.asm flat assembler version 1.71.49 (1048576 kilobytes memory) 1 passes, 114 bytes. D:\gfortran\clf\rdtsc>objdump -f rdtsc_32.obj rdtsc_32.obj: file format pe-i386 architecture: i386, flags 0x00000039: HAS_RELOC, HAS_DEBUG, HAS_SYMS, HAS_LOCALS start address 0x00000000 D:\gfortran\clf\rdtsc>type hello32.f PROGRAM HELLO32 IMPLICIT NONE INTEGER*8 RDTSC_32 EXTERNAL RDTSC_32 INTEGER*8 T0, TF T0 = RDTSC_32() WRITE(*,*) 'Hello, world' TF = RDTSC_32() WRITE(*,*) 'Time = ',TF-T0 END D:\gfortran\clf\rdtsc>gfortran hello32.f rdtsc_32.obj -ohello32 D:\gfortran\clf\rdtsc>hello32 Hello, world Time = 570736 I'm not sure whether this will work with g77, though. Use objdump.exe on a g77-generated *.o file to discover file format, name mangling, and calling convention. g77 is kind of archaic and you will get much better help if you can move up to gfortran. You will want to anyhow when you find that 32-bit code doesn't have a hardware instruction for 64X64->128 multiply. Just sayin'. |
|||
25 Jun 2017, 01:46 |
|
NimbUs 27 Jun 2017, 11:23
Back to report I have solved the actual Fortran-ASM interfacing problem,
using not FASM but NASM this time, another fine assembler (which I had not previously tried) that will natively assemble to a number of object file formats, including Coff and its win32 variant, which is exactly what was expected by the g77 compiler suite on my (Windows XP 32 bits) platform... The interested could find details in a recent thread in the usenet news group comp.lang.asm.x86 (also archived as "google groups"). @Revolution, @Xorpd! : thanks for your above replies, which show that there are probably ways to skin this cat using the FASM, too... |
|||
27 Jun 2017, 11:23 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.