flat assembler
Message board for the users of flat assembler.

Index > Windows > Using Fasm with Visual C++

Author
Thread Post new topic Reply to topic
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 21 Feb 2004, 11:16
Hi friends,

Here is an example on how to use Fasm with VC++ , a simple hello world application using the StdOut function coded in Fasm

Hello world code:
Code:
extern int __stdcall StdOut(char *msg);

void main(int argc,char *argv[])
{
StdOut("Hello world");
}
    


Code:
format MS COFF

include 'win32.inc'
include 'StdOut.imp'

public StdOut as "_StdOut@4"

section '.text' code readable executable

proc StdOut,lpszText
  
    hOutPut  dd ?
        bWritten dd ?
        sl       dd ?
     enter
       invoke GetStdHandle,STD_OUTPUT_HANDLE
       mov [hOutPut],eax
        invoke lstrlen,[lpszText]
      mov [sl],eax
        lea eax,[bWritten]
        invoke WriteFile,[hOutPut],[lpszText],[sl],eax,NULL
        mov eax,[bWritten]
     return
    


The original StdOut function can be found in Hutch's masm32.lib
This function needs to be exported with the decorated form, _StdOut@4
You will find the revised stdcall macro supporting indirect function fall for MS Link

Here is my simplified C start-up code for console applications:
Code:
.386
.model flat,stdcall
option casemap:none

include \masm32\include\kernel32.inc

__getmainargs PROTO C :DWORD,:DWORD,:DWORD,:DWORD
main PROTO C :DWORD,:DWORD

.data?
argc dd ?
argv dd ?
env dd ?
.code
start:
        invoke  __getmainargs,ADDR argc,ADDR argv,ADDR env,0
        invoke main,argc,argv
        invoke ExitProcess,0
END start
    


Finally,building the executable Sample.exe:
Code:
set fasminc=c:\fasmw\include
scan StdOut.asm -ic
\fasm\fasm StdOut.asm StdOut.obj

\progra~1\micros~2\vc98\bin\cl /c /Zl /Ogtyb2 /Gs /G6 /Gz /Zp1 /FAs /FaSample.asm /FoSample.OBJ Sample.c
\masm32\bin\link /NODEFAULTLIB /ENTRY:start /SUBSYSTEM:CONSOLE /LIBPATH:c:\masm32\lib /out:Sample.exe startc.obj Sample.obj StdOut.obj kernel32.lib user32.lib msvcrt.lib
    


Here is also my GUI version of C start-up code:
Code:
.386
.model flat,stdcall
option casemap:none

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

.data?
hInstance HINSTANCE ?

.code
start:
        invoke GetModuleHandle, NULL
        mov    hInstance,eax
        invoke GetCommandLine
        invoke WinMain, hInstance,NULL,eax,SW_SHOWDEFAULT
        invoke ExitProcess,eax
END start
    


Description:
Download
Filename: Fasm+VC.zip
Filesize: 10.01 KB
Downloaded: 584 Time(s)


_________________
Code it... That's all...
Post 21 Feb 2004, 11:16
View user's profile Send private message Visit poster's website 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.