News:

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

location of main procedure

Started by llkooj, December 03, 2008, 02:00:09 AM

Previous topic - Next topic

llkooj

Is this allowed?

procedure1 PROC
.
.
.
procedure1 ENDP

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


That is, having procedures before 'main'? Thanks.

Jimg

Yes.  And a side benefit is you don't have to have a worthless proto to call the earlier procedures.

raymond

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
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

llkooj

Thanks. I had the procedure named 'Test'. I changed the name and it worked.


jj2007

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

MichaelW

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.
eschew obfuscation