Monday, July 20, 2015

How to Run and Assemble MASM Program

An masm program must be assembled and linked before it can be executed.
The assembler produces an object file (extension .OBJ). This file is taken by the linker and an executable program (extension .EXE) is produced, assuming there were no errors in the program.
We use the MASM assembler and the LINK linker. These are available on NAL under Programming: “MASM files v5.0”.

When you choose MASM and click on it, NAL will install both MASM and LINK in your home directory in a folder called MASM. You only need to do this ONCE.
The full name for this folder is H:\MASM
Create a program called TEST.ASM by copying the program text above and using Notepad (or Edit) save the file is in your home directory on the H:\ drive in the MASM folder. The file name will be: H:\MASM\TEST.ASM.
When saving the file with Notepad, you MUST save it with the “File Type” set to “All Files”.
You should now select the MS-DOS Prompt (Command PROMPT) from the Start button menu (sometimes under Programs option).

You now get an MS-DOS window where you have to enter commands by typing the name of the command you wish to use. Common commands are
TYPE filename to display the file filename on the screen;
DEL filename to delete the file called filename
COPY filename newname: to make a copy of filename called newname
To view your program, you may use the TYPE program:
H:\> type H:TEST.ASM



Running your program

First: Assemble it using MASM
H:\> masm test
Microsoft (R) Macro Assembler Version 5.10
Copyright (C) Microsoft Corp 1981, 1988. All rights reserved.
Object filename [H:TEST.OBJ]:                                                   Press Return
Source listing [NUL.LST]:                                                                 Press Return
Cross-reference [NUL.CRF]:                                                                    Press Return
48928 + 432619 Bytes symbol space free
0 Warning Errors
0 Severe Errors
Note: The file test.asm MUST be in the same folder as MASM for the above to work.

Secondly: Link it using Link
Having successfully assembled your program, as above, you now link it in a similar fashion:

H:\> link test
Microsoft (R) Overlay Linker Version 3.64
Copyright (C) Microsoft Corp 1983-1988. All rights reserved.
Run File [H:TEST.EXE]:                                                                    Press Return
List File [NUL.MAP]:                                                                               Press Return
Libraries [.LIB]:                                                     Press Return

Note: The file test.obj MUST be in the same folder as LINK for the above to work.

Finally, run it by entering the program name
To run your program, simply enter its name:
H:\> test
X
In the event of errors, you must edit your program and correct the errors. Then you repeat the above steps to assemble and link your program, before running it.
Similarly, if you modify your program, you must assemble and link it before running it again.