News:

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

How to properly set up multiple source files

Started by MalcolmOSX, March 11, 2005, 06:44:02 AM

Previous topic - Next topic

MalcolmOSX

Hey guys

Now I'm a guy that likes clean, good looking code. And I can't figure out for the life of me how to break up my code into multiple source files. I'm using WinASM Studio to develop everything.


The real question I need answered is...what exactly needs to go in the seperate files? Any examples would be much appreciated.


Thanks, Malcolm

sluggy

I tend to have one main asm file that includes all the others, i do it like this:


   include includeFile.inc


and then in the file called includeFile.inc, i have the actual includes:


   include abc.asm
   include def.asm
   etc


I do it this way because it is clean, and i don't care about compile time (*anything* is faster to compile than a large web app in VS.Net  ::) ). An alternative is to split your asm into discrete logical files, and compile them into lib files, which you can then just link them into your main asm file. I tend not to do that, as i put my libraries into dlls so they can be called from any language.


donkey

A third option when using MASM (or GoAsm) is to use multiple discreet files and have them compiled into separate OBJ files then brought together in the link phase. This has the advantage of allowing you to only compile those parts of the program you want to. I am not sure how WinASM Studio does this but in RadASM you can easily set it up. The separately compiled "modules" have the following setup...

.586
.mmx
.model flat,stdcall
option casemap:none

;#########################################################################
; Include files

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

;#########################################################################
; Libraries

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

PUBLIC datalabel ; exported to other modules
EXTERN extlabel:DWORD ; imported from another module

.data?
datalabel dd ?

.code

; note no entry point

end


This is not specific to your development environment, it is part of MASM so it should be possible in any IDE, WinASM studio is an excellent package and I would be surpised if it was not included as an option. The link command would be as follows..

C:\MASM32\BIN\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /LIBPATH:"C:\MASM32\LIB" Main.obj Module1.obj...
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

James Ladd

I try to have files that relate to one item only
eg: draw.asm, calculate.asm, store.asm
Within those I "try" to make sure each API does only one thing.
If it does more than one then I rename the API or break it into
more than one API (if I can).

There probably is no "proper" way to setup multiple source files.

One rule of thumb I try to stick with is that code belongs in an .ASM file
and definitions, macros and equates etc in .INC files.

rgs, striker

Mark Jones

I've been toying with EasyCode and WinAsm. Both are quite different in their approach of "module" files. To use multiple procs across source file I ended up doing something like this:

MyProg.asm:

.386
.model  flat, stdcall
include MyProg.inc
include MyProg Module 2.asm
.data
<blah blah blah>
.code
start:
<blah blah blah>
end start


MyProg.inc

.386
.model  flat, stdcall
include masm32.lib, etc
.static
<blah blah blah>
.data?
.data


MyProg Module 2.asm

.386
.model  flat, stdcall
OPTION proc:public
.data
.code
module2:

calculate proc public
<blah blah blah>
endproc

end module2



The whole idea was that certain procs could be "offloaded" to other .asm files. I had trouble getting it to work properly, so I just stuck with keeping everything in one .asm file and .inc file.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08