News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Goasm -> Masm

Started by Magnum, November 30, 2012, 03:49:44 AM

Previous topic - Next topic

Magnum

This is what I have so far on converting this Goasm code to masm syntax.

I don't need a complete conversion as I want to learn a lot of things.

I am looking at whether this will need a  (1) _main   PROC, or (2) a start: , end start
I will also convert many of the calls to invoke.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

MASM will accept Start...
Start:
        mov     eax,0
        INVOKE  ExitProcess,eax

        END     Start


or a PROC...
_main   PROC

        mov     eax,0
        INVOKE  ExitProcess,eax

_main   ENDP

        END     _main


i prefer the later, as it allows for the use of LOCAL vars
it also looks neater and, i think, is more readable   :P
when you use LOCAL, the assembler generates a prologue
it also generates an epilogue anywhere RET is used in that PROC
seeing as the _main PROC rarely has a RET, no epilogue is generated
as you know, when the assembler generates one of the prologues, it uses stack space
normally, the stack space is released in the epilogue
seeing as there is no RET and no epilogue, there is no balancing of the stack
however, ExitProcess releases any stack space used by the process thread

this may not apply for PROC's used in threads
i.e., the operating system may not free the stack for ExitThread the same way as for ExitProcess
this can cause a memory leak
when i write a thread PROC, i am careful not to use any parameters or USED on the PROC line
i am also careful not to use LOCAL in thread PROCs
when you start a thread, there may be one caller parameter available in [ESP+4], however
when i terminate a thread, i make sure the stack is balanced

MichaelW

Why not just return from the thread procedure?
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

well - according to the documentation, it is prefered to use ExitThread

i also see the docs state that it releases the stack space
i don't think that was in there in older versions - it may be new with vista/win 7 or something

MichaelW

Returning from the thread procedure triggers an implicit call to ExitThread, so everything happens as it should and it's easier to code.
Well Microsoft, here's another nice mess you've gotten us into.