0% found this document useful (0 votes)
58 views7 pages

MP-Lab Sheet #1

This document provides instructions for writing, assembling, and running a first assembly language program for MS-DOS. It describes using an editor like EDIT to enter code for a "Hello World" program into a file called prog1.asm. It then explains assembling the code using MASM to create an object file prog1.obj, and linking the object file using LINK to create an executable prog1.exe that prints "Hello World" when run. The full process involves editing and saving the code, assembling with MASM, linking with LINK, and then running the executable file.

Uploaded by

Renas Dareesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views7 pages

MP-Lab Sheet #1

This document provides instructions for writing, assembling, and running a first assembly language program for MS-DOS. It describes using an editor like EDIT to enter code for a "Hello World" program into a file called prog1.asm. It then explains assembling the code using MASM to create an object file prog1.obj, and linking the object file using LINK to create an executable prog1.exe that prints "Hello World" when run. The full process involves editing and saving the code, assembling with MASM, linking with LINK, and then running the executable file.

Uploaded by

Renas Dareesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab.

Sheet #1

Writing Your First Assembly Language Program


For MS-DOS OS

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

Instructors: Omar, Qaidar and Samyian


1
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #1

The program can be executed by writing the program name (Prog1 or


Prog1.exe) at the command prompt.

How to Follow the Steps?


Editing:
You can use EDIT program to write your first assembly language by
writing edit command at the command prompt as shown below:
C:\>edit

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).

Instructors: Omar, Qaidar and Samyian


2
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #1

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

mov dx, offset message


mov ah, 9h ; string output
int 21h ; display string

mov ax, 4c00h ; return to ms-dos


int 21h

end start

Note that the text after the semicolon is only a comment so the code will
be like this in editor program:

Instructors: Omar, Qaidar and Samyian


3
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #1

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.

Instructors: Omar, Qaidar and Samyian


4
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #1

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).

The Program Shows the


file path and name here
after saving the file

Instructors: Omar, Qaidar and Samyian


5
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #1

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.

Now enter MASM command followed by the file name (prog1.asm) at


the command prompt to get the object file (prog1.obj) as shown below:
C:\>masm prog1.asm

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.

Instructors: Omar, Qaidar and Samyian


6
UOZ – CS. Dept. Microprocessors Lab. 2020 – Lab. Sheet #1

Linking:

To produce an executable MS-DOS program, you need to link your


program by using a linker program called LINK. To use this program
just type LINK followed by prog.obj at the command prompt to get the
executable file (prog1.exe)

C:\>link prog1.obj

As mentioned earlier. To keep the file names as suggested by the


program just press ENTER 3 times and that’s it. You can execute the
program by typing the file name without an extension or followed by
(.exe) extension as shown in the figure:

C:\>prog1

C:\>prog1.exe

Instructors: Omar, Qaidar and Samyian


7

You might also like