Author Topic: Goasm -> Masm  (Read 5304 times)

Magnum

  • Member
  • *****
  • Posts: 2399
Goasm -> Masm
« on: November 30, 2012, 03:49:44 AM »
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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Goasm -> Masm
« Reply #1 on: November 30, 2012, 04:31:30 AM »
MASM will accept Start...
Code: [Select]
Start:
        mov     eax,0
        INVOKE  ExitProcess,eax

        END     Start

or a PROC...
Code: [Select]
_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

  • Global Moderator
  • Member
  • *****
  • Posts: 1196
Re: Goasm -> Masm
« Reply #2 on: November 30, 2012, 10:56:28 PM »
Why not just return from the thread procedure?
Well Microsoft, here’s another nice mess you’ve gotten us into.

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Goasm -> Masm
« Reply #3 on: December 01, 2012, 06:35:48 AM »
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

  • Global Moderator
  • Member
  • *****
  • Posts: 1196
Re: Goasm -> Masm
« Reply #4 on: December 01, 2012, 07:10:57 AM »
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.