The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: llkooj on December 03, 2008, 02:00:09 AM

Title: location of main procedure
Post by: llkooj on December 03, 2008, 02:00:09 AM
Is this allowed?

procedure1 PROC
.
.
.
procedure1 ENDP

main PROC
.
.
.
INVOKE ExitProcess, 0
main ENDP
END main


That is, having procedures before 'main'? Thanks.
Title: Re: location of main procedure
Post by: Jimg on December 03, 2008, 02:06:08 AM
Yes.  And a side benefit is you don't have to have a worthless proto to call the earlier procedures.
Title: Re: location of main procedure
Post by: raymond on December 03, 2008, 02:17:21 AM
And it doesn't even need to be a proc if there's no specific reason for it.

.code
... whatever code you want here

main:
...whatever other code you want here
INVOKE ExitProcess, 0

end main
Title: Re: location of main procedure
Post by: llkooj on December 03, 2008, 02:34:43 AM
Thanks. I had the procedure named 'Test'. I changed the name and it worked.

Title: Re: location of main procedure
Post by: jj2007 on December 03, 2008, 02:35:27 AM
Quote from: Jimg on December 03, 2008, 02:06:08 AM
Yes.  And a side benefit is you don't have to have a worthless proto to call the earlier procedures.

And it doesn't even have to be code if there's no specific reason for it  :wink

.code
AppName db "Masm32:", 0
...

However, with the no proto technique the order matters for everything: Any procedure can only be called if it is above the calling code.

include \masm32\include\masm32rt.inc

MyTest3 PROTO: DWORD, :DWORD

.code
AppName db "Masm32:", 0

MyTest2 proc argA, argB
invoke MessageBox, 0, argA, argB, MB_YESNO
ret
MyTest2 endp

MyTest1 proc argA, argB
invoke MyTest2, argA, argB ; defined above, no PROTO needed
invoke MyTest3, argA, argB ; PROTO needed
ret
MyTest1 endp

MyTest3 proc argA, argB
invoke MessageBox, 0, argA, argB, MB_YESNO or MB_DEFBUTTON2
ret
MyTest3 endp

start: invoke MyTest1, chr$("Hello World"), addr AppName
exit

end start
Title: Re: location of main procedure
Post by: MichaelW on December 03, 2008, 05:36:34 AM
QuoteHowever, with the no proto technique the order matters for everything: Any procedure can only be called if it is above the calling code.

More precisely, you can CALL a procedure that is defined below the CALL statement, but without a preceding PROTO you cannot INVOKE a procedure that is defined below the INVOKE statement.