Looks weird but it works perfectly...
include \masm32\include\masm32rt.inc
MyTest PROTO: DWORD, :DWORD
.data
stdata SYSTEMTIME <2011,3,7,3,20,59,59,12345> ; wYear, wMonth, ... wMilliseconds
dataArg2 dd ?
dataArg1 dd ?
dataRetAdd dd ?
dataSaveEbp dd ?
dummy LABEL dword
.code
AppName db "Masm32 is great!", 13, 10, 0
Hello db "A message: ", 0
start:
mov ebx, esp
print str$(ebx), 9, "Stack", 13, 10 ; check for stack and ebp on entry
print str$(ebp), 9, "ebp", 13, 10, 10
invoke MyTest, addr Hello, offset AppName ; that looks really straightforward...
mov ebx, esp
print str$(ebx), 9, "Stack", 13, 10 ; check for stack and ebp on entry
print str$(ebp), 9, "ebp", 13, 10, 10
inkey "OK"
exit
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
MyTest proc arg1x:DWORD, arg2x:DWORD
LOCAL SaveEbp, RetAdd, arg1, arg2, stime:SYSTEMTIME
push ebp
mov ebp, offset dummy
pop SaveEbp
pop RetAdd
pop arg1
pop arg2
print arg1
print arg2
movzx eax, stime.wYear ; yep, this is a "preloaded LOCAL"!
print str$(eax), 9, "Year", 13, 10
movzx eax, stime.wMonth
print str$(eax), 9, "Month", 13, 10
movzx eax, stime.wMilliseconds
print str$(eax), 9, "millisecs", 13, 10, 10
mov edx, RetAdd
mov ebp, SaveEbp
jmp edx
MyTest endp
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
end start
So, is there an advantage than can be had with your code ?
Andy
Quote from: Magnum on March 06, 2011, 02:01:27 AM
So, is there an advantage than can be had with your code ?
You can declare a global structure "local". Code might be a bit more compact...
might be more compacter, but it also destroy the concept of local variables (e.g. thread save variables)
That is true, although imho not each and every routine has to be thread-safe.
Actually, it is just a little exercise that helped me understand what is behind LOCAL - a macro that assigns equates to memory relatetive to ebp.
:8)
INCLUDE \masm32\include\masm32rt.inc
.DATA
dd 256 dup(?)
EspInit dd STD_OUTPUT_HANDLE,TxtString,sizeof TxtString,BytesWritten,0
BytesWritten dd ?
TxtString db 'Hello Jochen!',13,10
.CODE
_main PROC
mov esp,offset EspInit
CALL GetStdHandle
push eax
CALL WriteFile
CALL ExitProcess
_main ENDP
END _main
version 2 :P
INCLUDE \masm32\include\masm32rt.inc
.DATA
dd 256 dup(?)
EspInit dd GetStdHandle,Brnch,STD_OUTPUT_HANDLE,WriteFile,ExitProcess
hStdOut dd ?,offset TxtString,sizeof TxtString,offset BytesWritten,0
BytesWritten dd ?
TxtString db 'Hello Jochen!',13,10
.CODE
_main PROC
mov esp,offset EspInit
ret
Brnch:: mov hStdOut,eax
ret
_main ENDP
END _main
Madman :cheekygreen:
Quote from: dedndave on March 07, 2011, 10:03:17 PM
version 2 :P
:U
Under Win9x you even may self-delete EXE after all :bg
Only one thing is - allocate more space for the stack :P
it shouldn't use too much stack space :P
i could probably reduce it
Quote from: dedndave on March 07, 2011, 11:52:02 PM
it shouldn't use too much stack space :P
i could probably reduce it
It is just suit to thing stated there: http://www.masm32.com/board/index.php?topic=12460.msg128614#msg128614. APIs you using very fastly come to the kernel, with less stack usage, this is reason :P
I think its cute but I would be inclined to test it under DEP before you distributed any code that works like this.
i have no intention of publishing any code like that
it was just for fun :bg
These are preloaded, with tilted stack.
#1
no auto exit
#2
Exit code: -1073741819
#3
Exit code: -1073741819
Perhaps a preloaded smiley face will make them work.