News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Do I need a main macro inside the .code?

Started by Sergiu FUNIERU, March 05, 2010, 05:05:48 AM

Previous topic - Next topic

Sergiu FUNIERU

On some tutorials, I saw they use this:
.code
start:
          ; some code
  exit
end start


instead of :
.code
start:
main proc
                  ; some code
          exit
main endp
end start


Do I really need a main proc inside the .code?

Or here:
start:
    call main
    exit
end start

what's the advantage of calling main, instead putting the main procedure first?

joemc

Quote from: Sergiu Funieru on March 05, 2010, 05:05:48 AM
On some tutorials, I saw they use this:
Do I really need a main proc inside the .code?
No
Quote from: Sergiu Funieru on March 05, 2010, 05:05:48 AM
what's the advantage of calling main, instead putting the main procedure first?
The only reason i have found it beneficial to call a main procedure, or a procedure by any name, after you code execution begins is it builds a stack frame and lets you use the LOCAL macro.  For applications that have 1 main window I personally have been doing something similair to :

.code
start:
call CreateWindow
call MessageLoop
call ExitProcess

All the temporary variables i use to create the window are not stuck on the stack this way.


hutch--

Sergiu,

Starting the .CODE section before a procedure is defined has its advantages, it is what you call module level scope and if you want to use that you write it that way. If everything you want to do can be done within procedures, then you can do it that way, depends on what you need. The logic is something like this.


.code    ; start the .CODE section
dname db "data here if you want:,0

start:    ; begin execution here
  ; the rest of your code.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php