By large, I mean multi-file. I still have not been able to find any simple code showing proper use of PUBLIC, EXTERN, EXTERNDEF. My big problem right now is that I have 2 files: main.asm files.asm files.asm uses CreateFile which is in Kernel32(inc/lib) and uses constants in is loaded in main.asm. files.asm cannot see I cant load in files.asm or I get a redefinition error. None of the source code I have looked at has given me any definite idea about how to resolve scope across files for variables, and apparently inc/libs. Most tutorials are for some aspect of code, but none really for style/method of code design.
Posted on 2001-05-03 18:18:00 by asm_happy
I asked this question quite some time ago... the link is here: How to split asm files up I started prefereing the include statement, here's my main.asm

.model flat,stdcall
option casemap:none

include \masm32\include\
include \masm32\include\
includelib \masm32\lib\user32.lib
include \masm32\include\
includelib \masm32\lib\kernel32.lib
include \masm32\include\
includelib \masm32\lib\comctl32.lib
include \masm32\include\
includelib \masm32\lib\comdlg32.lib
include \masm32\include\
includelib \masm32\lib\gdi32.lib
include \masm32\include\
includelib \masm32\lib\advapi32.lib
include \masm32\lib\
includelib \masm32\lib\masm32.lib
;include \masm32\include\
;includelib \masm32\lib\shell32.lib

     include protos.asm
     include macros.asm

     include constants.asm
     include data.asm
     include udata.asm
     invoke GetModuleHandle,0
     mov hInstance,eax
     invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
     invoke ExitProcess,eax

     include MyProcs.asm
     include WndProc.asm
     include WinMain.asm
end start
Posted on 2001-05-03 18:28:00 by JimmyClif
Best thing about this is: It gives you reusable files...
Posted on 2001-05-03 18:32:00 by JimmyClif
Thanks for that bit of code. Alot easer to read than the mess I got now. I notice you include MyProcs.asm. If in your own code in MyProcs.asm, you use WinAPI or Win constants, they will be in scope right? I'll have to look at my code, cause I think this is what I'm doing but is out of scope for files.asm
Posted on 2001-05-03 20:10:00 by asm_happy
I use this:

;~~~~----==== ThisFile - v1.0b - by Wolfao ====----~~~~
.model flat,stdcall
option casemap:none

include OtherFile.asm

  blah DWORD 0
  bloo DWORD ?
  invoke Proc1
  invoke Proc2

Proc1 proc
Proc1 endp
End Start

;~~~~----==== OtherFile - v1.0b - by Wolfao ====----~~~~
  blee DWORD 0

Proc2 proc
Proc2 endp
Hope this help. :)
Posted on 2001-05-04 22:10:00 by wolfao
Generally, you should add the following lines at the beginning of your include files :


; declarations here


It will prevent the compiler to include the same file several times.

Here is an example where File1.asm uses a function and a variable defined in File2.asm :


__FILE1_INC__ = 1

; MainFunction declaration
MainFunction    proto arg1:DWORD, arg2:DWORD


; File1.asm



; main function definition
MainFunction proc arg1:DWORD, arg2:DWORD
  invoke  Function2, arg1, arg2
  ; you can use the variable defined in File2.asm
  mov     eax, var
MainFunction endp



__FILE_2_INC__ = 1

; var declaration
externdef       var:dword

; function2 declaration
Function2  proto arg1:DWORD, arg2:DWORD

; File2.asm

  ; var definition
  var dword 0


; Function2 declaration

Function2 proc arg1:DWORD, arg2:DWORD
; function code here
Function2 endp

To build your executable : ml /c file1.asm ml /c file2.asm link file1.obj file2.obj /out:executable.exe There is more info in the MASM manual. Good luck! This message was edited by Hiroshimator, on 5/5/2001 9:14:01 AM
Posted on 2001-05-05 09:09:00 by karim
Thnks for the new replies. Now I have Jimmy Cliff's example for biring includes/const/golbal var/ ect together. The two examples show the relations hip between 2 files will help. The MSAM help is very useful to me because it has definitions, but no examples. Hirosimator linked some MASM help file, but I cant read them because I have no program that can read Word 2.0 format. I will see if I can figure out now, thanks.
Posted on 2001-05-05 21:50:00 by asm_happy