When you write a HLL program and want to execute it you
know vaguely that there are some magic programs ( compiler,
linker, loader) at work to convert the the source code file xyz.c
into a binary executable xyz.exe .
[ Or even worse the only thing you know is what button to click
in your IDE to do it ! ]
This thorough spoiling is over when you're down to asm code !
With the help of a little demo program you will get a deeper insight
into the conversion from xyz.asm to xyz.exe.
a) Open a MS-DOS window
b) Get your favorite ASCII editor and create the file demo.asm :
[ Type it now, understand it later - and dont use WORD3001
with embedded figures and arabian fonts ;-) ]
mov AH,08h ; read 1 char
int 21h ; from keyboard to AL
mov DL,AL ; copy AL to DL
mov AH,02h ; write char in DL
int 21h ; to screen
mov AH,4Ch ; return to
int 21h ; DOS
c) Assemble the program with
C:> MASM demo
If the code is errorfree then MASM will create an object file demo.obj
[ If you are not in the MASM directory then you
must set your PATH
variable to the path of MASM.EXE ]
d) Link the program with
C:> LINK demo ( + prog1 + prog2 ....)
This adds info to demo.obj ( e.g. library
routines ...) and creates
the executable demo.exe .
LINK asks for the names of list-,map-,library- and exe-files.
[ Hitting the enter key will give the default output ]
Have a look at demo.lst, demo.map .
Neglect warnings for the moment [ no stack segment, no starting address ]
e) Run the program with
demo expects the input of a character from KB:
and sends it
to the screen.
Think about the data flow. Where resides the information ?
From MASM 6.0 on MicroSoft delivered a program ML that allowed
to do assembly and linkage in one step.
[ BTW ,in the version MASM6.1 we are running in H312 MASM.EXE is
only a small utility that translates command line options to those
accepted by ML.EXE, and then calls ML.EXE ]
C:> ML demo.asm : creates demo.exe
Useful switches : /Zi
: add debug info ( codeview)
/Fl : add a list file demo.lst
/Fm : add a map file demo.map
A complete call looks like :
C:> ML /Zi /Fl /Fm demo.asm
Have a look at demo.lst, demo.map.
The full list of options is available via :
C:> MASM /H
C:> LINK /HELP ; LINK /?
C:> ML /HELP ; ML /?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BORLAND version :
If you are working in a Borland environment ( C:>\BC5\TASM....)
you may prefer to use the Borland assembler TASM and linker TLINK.
MASM and TASM understand the same assembler instructions, but
there are some slight differences in the interpretation of macro
TASM/TLINK are part of the Borland IDE you
have used during your
first year. When we will come to the point to mix HLL- and ASM modules
we'll do that most probably with this IDE.
Assembly : C:> TASM /l /n /z demo
Switches : /l : create
/n : no symbol table
/z : display source lines with errors
For a complete set of options : C:> TASM /h
Linkage : C:> TLINK /3 /m /v demo
Switches : /3 : use 32-bit
/m : create map file demo.map
/v : add debug info for the debugger TD
There is no 1-step program similar to ML - but you
may write a
little DOS script to save typing.
List of all options : C:> TASM /?
; C:> TLINK /?
After being an expert now in handling all the necessary steps
of editing, assembling and linking with separate tools ( and I left
out the most important one, namely debugging ) I suggest that
from now on you use a simple IDE offered by MS in its infinite
kindness : PWB : Programmers WorkBench .
You will find it in the H312 boxes under WinNT.
If you want to install it at home ( strongly suggested ) you find it
on the CDROM accompanying Kip R. Irvines book : Assembly
Language for Intel-Based Computers [ TXC Irvi ].
Start : Doubleclick the PWB icon
use a DOS window and type C:> PWB
The edit-part of the functionality should be self evident -
File --> -New / -Open / - Save /
-Save as / -Close / -Exit
Edit --> -Cut / -Copy / -Paste / -Delete .......
Before you can convert the asm source code into an exe
( = Project Build) you must tell PWB which kind of executable
you want to build. This is done by setting several options
in the OPTIONS menue :
Options --> Project Templates -->
activate : RunTimeSupport : Assembler
Project Template : DOS EXE ok
Options --> Build Options -->
activate : Use Debug Options ok
Options --> Language Options --> MASM-Options -->
: MASM 5.1 Compatibility
delete : Warnings treated as errors
go to --> Set Debug Options -->
activate : Generate Listing File
Generate Symbol Table
Debug Information : (*) CodeView 2x ok
[ If you are lucky you need to set these options only once - they
should be set again by PWB on every new start ]
Now that all the options are set you are able to build the
Project --> Compile File : DEMO.ASM : create obj only
--> Build : DEMO.EXE : create exe file
--> Rebuild All : reaasemble/link
: later, for multi module
--> Open Project
To execute and debug the program :
Run --> Execute DEMO.EXE : switch to user screen for in/output
Debug DEMO.EXE : opens several windows
source window : contains binary and asm code (check
memory window : contains HEX/ASCII representation of the
register window : displays current contents of all registers
: appears eventually when input is required,
contains program's output : Hit F4 to see it
Hitting F8/F10 allows now to step through the program
instruction by instruction.
Watch/Breakpoints can be set :
see Data menue -->
--> Set Breakpoint