flat assembler
Message board for the users of flat assembler.

Index > Windows > fasmg dll call

Author
Thread Post new topic Reply to topic
Andy



Joined: 17 Oct 2011
Posts: 55
Andy 04 Jun 2023, 10:29
I followed Tomasz's youtube video and I managed to setup fasmg on windows but I am a little bit confused how I use fasmg.dll with a high level language. How do I set includes for specific CPU? What exactly source_string should be to compile a simple instruction like xor eax,eax?

Edit: I posted in the wrong section of forum, please someone move it to appropriate forum
Post 04 Jun 2023, 10:29
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3976
Location: vpcmipstrm
bitRAKE 04 Jun 2023, 11:16
We can see from the source code that the DLL exports two functions, and the assembly function uses six parameters. It's a 32-bit DLL using the standard 32-bit ABI - parameters pass on the stack.
Code:
        invoke  fasmg_Assemble,\
                source_string,\         ; source string
                NULL,\                  ; source path
                aout,\                  ; output region
                NULL,\                  ; output path
                [hStdOut],\             ; stdout
                [hStdErr]               ; stderr
        test    eax,eax
        jnz     error    
To compile an instruction like xor eax,eax, the \fasmg\packages\x86\include\cpu\x64.inc file would need to be included. Usually the INCLUDE environment variable is set to something sensible, and then your string "xor eax,eax" could be prefixed with the desired includes prior to being passed to the fasmg_Assemble function.
Code:
; fasmg-powered mini assembler using,
; flat assembler  version g.k0v2

include 'cpu\p6.inc'
use32
xor eax, eax    
There are examples in the source package and on this board. I'm assuming you know how to use a DLL function from your HLL language, but I'm happy to help with something more specific?
Post 04 Jun 2023, 11:16
View user's profile Send private message Visit poster's website Reply with quote
Andy



Joined: 17 Oct 2011
Posts: 55
Andy 04 Jun 2023, 11:41
I know how to use the DLL from HLL and I think also that I understand the exported functions of fasmg.dll. The problem is when I have to include files like format/pe.inc, which include cpu/8086.inc. How does fasmg.dll know where the includes directory is? Is there any way to set the path for include directory like an env variable so I don't have to use full path of includes?

I tried what you said and I used this as source_string in my dll call:
Code:
include "<full path to fasmg>include\cpu\x64.inc
use32
xor eax, eax    


and I get what I expected: 31 C0
Post 04 Jun 2023, 11:41
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 04 Jun 2023, 13:16
First, please read the main thread documenting the DLL interface.

As for the path, the base path is simply the current directory of the parent process (you can change it with SetCurrentDirectory). It also searches the directories specified in INCLUDE environment variable, the same like console interface does. You can set up this variable for your process with SetEnvironmentVariable function. You can even change the contents of this variable between the calls to fasmg_Assemble.
Post 04 Jun 2023, 13:16
View user's profile Send private message Visit poster's website Reply with quote
Andy



Joined: 17 Oct 2011
Posts: 55
Andy 04 Jun 2023, 13:38
Thank you. It works like a charm.
Post 04 Jun 2023, 13:38
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.