Monday, January 18, 2010

Assembling and Linking Assembly Language Codes with TASM and MASM

On the days of Assembly Programming I enjoyed it very much. It was not about which assembler I used, whether it was turbo assembler or microsoft assembler. It was about the clever scripts I always wrote to perform compilation of my codes and linking at ease.

TASM
So if you were using Turbo Assember what would be the command to assemble the code. It is:

D:\tasm\bin> tasm filename.asm

And how to link?

D:\tasm\bin> tlink filename

Notice the tlink command uses only filename. No extension should be provided. Otherwise it will halt on error.

You’ll find my batch script more interesting.

@echo Saint Atique Windows Batch Script
@if exist %1.obj del %1.obj
@if exist %1.exe del %1.exe
@tasm %1
@if not exist %1.obj goto End
@echo Compiled filename: %1.asm (Assembly Sourcecode)
@tlink %1
@echo.
@echo Linked filename: %1.obj (Object file)
@echo.
@if not exist %1.exe goto End
@echo %1.exe (Executable file running under %os% DOS)
@echo =========================================================
@echo.
@%1
@echo.

:End
@echo Process Ended

As I saved it as tcpl.cmd the command to assemble and link a program file was:

D:\tasm\bin> tcpl filename.asm

MASM
I wrote the following script to assemble and link with masm as you know assemble command is masm and linking command is link.

@title Saint Atique masm platform
@echo Saint Atique Script
@echo MASM assemble syntax: mpl SourceFileName (output file is out.exe)
@echo Creating object file.
@echo.
@rem case sensitive /ml switch
@if exist out.exe del out.exe
@if exist out.obj del out.obj
@masm /ml %1 out
@if not exist out.obj goto obj_fail
@echo Linking output obj file
@link /batch out;
@echo.
@if not exist out.exe goto build_fail
@echo Running executable file: out.exe
@echo ==============================================
@out
@echo.
@echo Process succeeded.
@goto end
:obj_fail
@echo.
@echo Error generating obj binary codes
@goto end
:build_fail
@Echo Error building executable file..

:end
@echo Process Ended.
@title Saint Atique Terminal

And for compiling masm win32 programs I wrote this script, saved a lot of hard works and avoiding boorish repetition.


@title Saint Atique masm win32 platform
@echo Saint Atique Script
@echo MASM assemble syntax: wpl SourceFileName
@echo Creating object file.
@echo.
@if exist %1.exe del %1.exe
@if exist %1.obj del %1.obj
@ml /c /coff /Cp %1.asm
@if not exist %1.obj goto obj_fail
@if exist %1.rc @echo Linking %1.rc & @rc %1.rc
@echo Linking object file and res file
@link /SUBSYSTEM:WINDOWS /LIBPATH:e:\masm32\lib %1.obj %1.RES
@echo.
@if not exist %1.exe goto build_fail
@echo Running executable file: %1.exe
@echo ==============================================
@%1.exe
@echo.
@echo Process succeeded.
@goto end
:obj_fail
@echo.
@echo Error generating obj binary codes
@goto end
:build_fail
@echo.
@Echo Errors in source. Correction required..

:end
@echo Process Ended.
@title Saint Atique Terminal

Happy assembling.

No comments:

Post a Comment