flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > When ESP changes

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 08 Jan 2016, 16:12
Code:
; example of simplified Windows programming using complex macro features
include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here
.code
    start:
        push    string1
        invoke  MessageBox,HWND_DESKTOP,dword [esp+8],invoke GetCommandLine,MB_OK
        invoke  ExitProcess,0
    string1:
        db 'Hello!'
.end start    
Here if you use
Code:
invoke  MessageBox,HWND_DESKTOP,dword [esp],invoke GetCommandLine,MB_OK    
it won't work as expected (I got the name of the .exe file). Is it possible to make it automatically change [esp] to [esp+8] when two values are pushed?
Post 08 Jan 2016, 16:12
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 08 Jan 2016, 16:50
You could try to apply a modification to macros this way:
Code:
include 'win32ax.inc'

macro pushd value {
        pushd value
        offset@stack = offset@stack + 4
}

macro invoke statement& {
        define esp (esp+offset@stack)
        offset@stack = 0
        invoke statement
        restore esp
}

.code
    start:
        push    string1
        invoke  MessageBox,HWND_DESKTOP,dword [esp],invoke GetCommandLine,MB_OK
        invoke  ExitProcess,0
    string1:
        db 'Hello!',0
.end start    
But this only adds a layer of processing to the outermost "invoke" - if you wanted to make it work correctly inside a nested statements too, you'd have to modify the allow_nesting macro in win32ax.inc and store/restore the stack offsets at every level of nesting.
Post 08 Jan 2016, 16:50
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.