News:

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

assembling multiple .asm files

Started by ninjarider, September 22, 2006, 01:03:36 AM

Previous topic - Next topic

ninjarider

i got my os that im working on. some of the codes is getting elaberate and code that i have finished confuses me when im trying to work on a new feature. how can i go about splitting my .asm file into multiples and have it assemble like it was still in the same file.

daydreamer

Quote from: ninjarider on September 22, 2006, 01:03:36 AM
i got my os that im working on. some of the codes is getting elaberate and code that i have finished confuses me when im trying to work on a new feature. how can i go about splitting my .asm file into multiples and have it assemble like it was still in the same file.
you create your own .inc files and cut out your proc's from main and paste into the new .inc files and use include to include all your .inc files

Tedd

Or even just place conceptually separate parts (keyboard, video, timer, disk, filesystem, etc) into separate .asm files, and then have one 'main' .asm file which contains no actual code, but "includes" all of the .asm files -- and this is the file you assemble.
No snowflake in an avalanche feels responsible.


ninjarider

for both methods do all the lables stay the same for calls, jumps, and variables.

its just a curiosity thing.

zooba

If you use the either of the including methods you have to keep labels unique throughout all the files.

If you assemble each file separately and link them all together, you can use the same label in different files. This method is theoretically more efficient, since you only need to assemble the files which have changed, though in practice (at least for small projects) it doesn't make much difference.

Cheers,

Zooba :U

Tedd

Yep, keeping labels unique throughout can become a problem eventually. Two tricks to avoid this: use local labels wherever possible (how to use these depends on which assembler you're using), and if you prefix the names of each 'module' with the module name (plus underscore?), then all names within that are different from names in all other modules (which means you just need to keep the names unique within modules).
Assembling files separately and then linking them works well as long as all your 'exported' names are still unique (module_ prefix :wink) and, more importantly, that you're actually linking as opposed to assembling directly to binary (which I assume is what you're doing :P; without a module format there's no need to link anyway.)
No snowflake in an avalanche feels responsible.

ninjarider

ok. i've been playing around with the two previous listed methods and have it working.

how would i go assembling them individually and linking them together.
would it look something like this
ml /c diskio.asm
ml /c os.asm
ml /c keyboard.asm

link16 /tiny diskio.obj, os.obj, keyboard.obj

Wistrik

I believe link will require an output file name for the resulting executable.

That format should work; I recall a similar example given in the MASM Programmer's Guide.

PBrennick

ninjarider,
You could also use a response file.  When building a library, for example, where there can literally be a hundred different assembly files, this is the only way to go.


@echo off
set name=myprog

dir /b *.asm > build.rsp               : create a response file for ML.EXE
\masm32\bin\ml.exe /c /coff @build.rsp
if errorlevel 1 goto errasm

dir /b *.obj > build2.rsp              : create a response file for LINK.EXE

\GeneSys\bin\link /SUBSYSTEM:WINDOWS /out:"%name%.exe" @build2.rsp
if errorlevel 1 goto errlink

:errasm
echo.
echo Assembly error
goto done

:errlink
echo.
echo Link error
goto done

:done
set name=
echo on
pause



The batch file has a few other things in it such as provision for a resource file but that is easily done and does not affect what I am trying to show you so I omitted it.
Paul
The GeneSys Project is available from:
The Repository or My crappy website