The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Sergiu FUNIERU on March 05, 2010, 05:05:48 AM

Title: Do I need a main macro inside the .code?
Post by: Sergiu FUNIERU on March 05, 2010, 05:05:48 AM
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?
Title: Re: Do I need a main macro inside the .code?
Post by: joemc on March 05, 2010, 05:38:24 AM
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.
Title: Re: Do I need a main macro inside the .code?
Post by: joemc on March 05, 2010, 05:41:18 AM
delete
Title: Re: Do I need a main macro inside the .code?
Post by: hutch-- on March 05, 2010, 09:27:54 AM
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.