MP-Lab Sheet #1
MP-Lab Sheet #1
Sheet #1
Introduction:
To Write your first assembly language program you must use an editor
to enter the program into a file. The process of using the editor (editing)
is a basic form of word processing. This skill has no relevance to
programming. We use Microsoft’s EDIT, MASM and LINK programs
for Editing, assembling and linking 8086 assembly language programs.
MASM program files should have names with the extension (.asm).
We will call our first program (prog1.asm), it displays the message
“Hello World!” on the screen. (You may use any name you wish. It is a
good idea to choose a meaningful file name). Having entered and saved
the program using an editor, you must then use the MASM and LINK
commands to translate it to machine code so that it may be executed as
follows.
Editor
Ex: Edit
Prog1.asm
This version is
Assembler
actually loaded
and executed MASM Prog1.asm
Prog1.obj
Linker
LINK Prog1.obj
Prog1.exe
By using this program, you can write the assembly program listed on the
next page (you use this program to write source code for C/C++ since it
is only a text editor).
The Code:
.model small
.stack 100h
.data
message db ‘Hello World‘, 13, 10, ‘$‘
.code
start:
mov ax, @data
mov ds, ax ;copy address of message to dx
end start
Note that the text after the semicolon is only a comment so the code will
be like this in editor program:
To save the code you can use the mouse pointer to access the menu bar
or you can simply use the keyboard shortcuts to access the menu bar by
pressing the ALT key plus the first highlighted letter in the main menu
bar or in the sub menus. For example, to access the file menu press
(ALT + F) as show below:
To select a menu item use arrow keys (Up Key or Down Key) to move
to any item in the menu or use a shortcut to select an item for example to
save the file use (S key) to select the save command from FILE menu.
After completing the code save the file as prog1.asm by selecting save
command then a dialog box will be displayed asking for the file name
and the location to be saved in.
To save the file enter the file name (prog1.asm) in the file name field as
shown up in the figure the press on the OK button by using mouse left
click or by pressing ENTER key (OK is highlighted command button).
After saving the file now you can quit from the editor by using the
mouse pointer by selecting EXIT command or you can quit from the
editor by pressing (ALT + F) to select FILE menu followed by letter (X)
Assembling:
We are now ready to assemble the saved code. To assemble the code,
you must use an assembler such as MASM (which stands for Macro
Assembler) (This Assembler is produced by Microsoft) in this lab we are
using version 5.0 Macro assembler.
the program will ask you to enter the object file name and other two file
names (will be explained later) to keep the file name suggested by the
program between the brackets just press ENTER key 3 times.
The Assembler shows that the program has no errors or warning in the
code. Now your code is ready for the next step …Linking.
Linking:
C:\>link prog1.obj
C:\>prog1
C:\>prog1.exe