NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: nimday on May 04, 2014, 09:23:27 PM

Title: Invoke Win32
Post by: nimday on May 04, 2014, 09:23:27 PM
Hello , how to create invoke like masm , i read nasmx but to complex to me
Can somebody give a small example to improve this code
Thanks

Code: [Select]
%macro Invoke1 2
 push %2
 call %1
%endmacro

%macro Invoke4 5
 push %5
 push %4
 push %3
 push %2
 call %1
%endmacro

extern _ExitProcess@4
extern _MessageBoxA@16

global _main

section .data
msg db "Hello",0
caption db "title",0

section .text

_main:

    Invoke4 _MessageBoxA@16,0,msg,caption,0
    Invoke1 _ExitProcess@4,0
Title: Re: Invoke Win32
Post by: encryptor256 on May 05, 2014, 12:20:31 PM
Hi,
this might work!

Win32, invoke stdcall routine:
Code: [Select]
%macro invoke 1-*

%assign max %0 - 1

%if max > 0

%rotate max

%rep max

%warning %1

push %1

%rotate -1
%endrep

%endif

call %1
%endmacro

I suggest using NASMX,
because in win32 there is an 'N' various calling conventions,
which NASMX has worked out.
Title: Re: Invoke Win32
Post by: Rob Neff on May 05, 2014, 03:35:42 PM
Hello , how to create invoke like masm , i read nasmx but to complex to me

What part is too complex?  As the current NASMX lead designer I'm very interested in where you get stuck.  NASMX should be very familiar to Masm users.

Can somebody give a small example to improve this code

As encryptor256 points out NASMX has already worked through all the issues you're likely to encounter when writing code.  At your level I don't recommend attempting to read through the macro definitions themselves as they are rather complex but rather simply use them until you become more comfortable.

Check out nasmx/demos/win32/ and start with DEMO1.  Each directory has a small example which shows you how to achieve what you're attempting.
Title: Re: Invoke Win32
Post by: nimday on May 05, 2014, 07:43:24 PM
@encryptor256 , Thanks it's working for me :)
@Rob Neff , You are right , maybe i read too much from nasmx.inc  :-[

Thanks all