0% found this document useful (0 votes)
167 views4 pages

Introduction To Assembly Language: Lab Experiment # 1

This document provides an introduction to assembly language programming using the 8086 microprocessor. It discusses writing simple assembly programs, assembling source code using Emu8086, and debugging programs. The key steps are: 1. Editing assembly source files (.asm) 2. Assembling to create object files (.obj) using an assembler 3. Linking object files to create executable files (.exe) 4. Executing programs and debugging using tools like Emu8086 to step through code and inspect registers. General purpose and segment registers of the 8086 CPU are described, along with common assembly language instructions like MOV, ADD, and INT 21H. An example assembly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views4 pages

Introduction To Assembly Language: Lab Experiment # 1

This document provides an introduction to assembly language programming using the 8086 microprocessor. It discusses writing simple assembly programs, assembling source code using Emu8086, and debugging programs. The key steps are: 1. Editing assembly source files (.asm) 2. Assembling to create object files (.obj) using an assembler 3. Linking object files to create executable files (.exe) 4. Executing programs and debugging using tools like Emu8086 to step through code and inspect registers. General purpose and segment registers of the 8086 CPU are described, along with common assembly language instructions like MOV, ADD, and INT 21H. An example assembly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LAB EXPERIMENT # 1

Introduction to Assembly language


Introduction:
The objective of this lab session is to introduce the student with 80X86 based
microprocessors architecture, few assembly language instructions and some IO operations
using INT 21H.

After this lab you will be able to:

 Write simple assembly language programs.


 Assemble, Link and Run assembly source code using Emu8086

Overview:
In general, programming of a microprocessor usually takes several iterations before the right sequence
of machine code instructions is written. The process, however, is facilitated using a special program
called an “Assembler”. The Assembler allows the user to write alphanumeric instructions, or
mnemonics, called Assembly Language instructions. The Assembler, in turn, generates the desired
machine instructions from the Assembly Language instructions. Assembly Language programming
consists of the following steps:

Action Result
1 Editing Source Files (*.asm)
2 Assembling Object files (*.obj)
3 Linking Executable Files(*.exe)
4 Executing Output

Assembling the Program:

The assembler is used to convert the assembly language instructions to machine code. It is used
immediately after writing the Assembly Language program. The assembler starts by checking the
syntax, or validity of the structure, of each instruction in the source file. If any error is found,
assembler displays a report on these errors along with a brief explanation of their nature. However if
the program does not contain any error, The assembler produces an object file that has the same name
as the original file but with the “.obj” extension

Linking the Program:

The linker is used to convert the object file to an executable file. The executable file is the final set of
machine instructions that can directly be executed by the microprocessor. It is different than the object
file in the sense that it is self-contained and re-locatable. An object file may represent one segment of
a long program; this segment cannot operate by itself, and must be integrated with other object files
representing rest of the program, in order to produce the final self-contained executable file.
In addition to the executable file, the linker can also generate a special file called the “map” file .This
file contains information about the Start, End, and the Length of the Stack, Code and the Data
segments. It also lists the Entry point of the program.

Executing the Program:

The executable file contains the machine language code. It can be loaded in the RAM and be executed
by the microprocessor simply by typing, from the DOS prompt, the name of the file followed by the
Enter Key (<┘). If the program produces an output on the screen, or a sequence of control signals to
control a piece of hardware, the effect should be noticed almost immediately. However, if the
program manipulates data in memory, nothing would seem to happen as a result of executing the
program.

Debugging the Program:

The debugger can also be used to find logical errors in the program. Even if a program does not
contain syntax errors it may not produce the desired results after execution. Logical errors may be
found by tracing the action of the program. Once found, the source file should be re-edited to fix the
problem, then re-assembled and re-linked. A special program called the “Debugger” is designed for
this purpose.

The debugger allows the user to trace the action of the program, by single stepping through the
program or executing the program up to a desired point, called “breakpoint”. It also allows the user
to inspect or change the contents of the microprocessor internal registers or the contents of any
memory location.
The details of a few assembly language mnemonics that we will be using in this lab is written as under

COMMAND FILE NAME


1 MOV AX, BX Copies the contents of accumulator register BX to AX
2 ADD AX, BX Adds the contents of AX and BX and saves result in AX
3 INT 21H Generates interrupt No: 21 H, Which returns the control to DOS if value
of register AH=4C H (more about this in future labs)
Inside the CPU:

General Purpose Registers


8086 CPU has 8 general purpose registers, each register has its own name:

a) AX - the accumulator register (divided into AH / AL).


b) BX - the base address register (divided into BH / BL).
c) CX - the count register (divided into CH / CL).
d) DX - the data register (divided into DH / DL).
e) SI - source index register.
f) DI - destination index register.
g) BP - base pointer.
h) SP - stack pointer.

Despite the name of a register, it's the programmer who determines the usage for each general-
purpose register. the main purpose of a register is to keep a number (variable). the size of the above
registers is 16 bit, it's something like: 0011000000111001b (in binary form), or 12345 in decimal
(human) form.
4 general purpose registers (AX, BX, CX, DX) are made of two separates 8 bit registers, for example
if AX= 0011000000111001b, then AH=00110000b and AL=00111001b. therefore, when you modify
any of the 8 bit registers 16 bit register is also updated, and vice-versa. the same is for other 3
registers, "H" is for high and "L" is for low part.

because registers are located inside the CPU, they are much faster than memory. Accessing a memory
location requires the use of a system bus, so it takes much longer. Accessing data in a register usually
takes no time. therefore, you should try to keep variables in the registers. register sets are very small
and most registers have special purposes which limit their use as variables, but they are still an
excellent place to store temporary data of calculations.
Segment Registers
a) CS - points at the segment containing the current program.
b) DS - generally points at segment where variables are defined.
c) ES - extra segment register, it's up to a coder to define its usage.
d) SS - points at the segment containing the stack.

although it is possible to store any data in the segment registers, this is never a good idea. the segment
registers have a very special purpose - pointing at accessible blocks of memory.

Special Purpose Registers


a) IP - the instruction pointer.
b) flags register - determines the current state of the microprocessor.

IP register always works together with CS segment register and it points to currently executing
instruction. flags register is modified automatically by CPU after mathematical operations, this allows
to determine the type of the result, and to determine conditions to transfer control to other parts of the
program. generally, you cannot access these registers directly, the way you can access AX and other
general registers, but it is possible to change values of system registers using some tricks that you will
learn a little bit later.

LAB WORK

Program # 1: -

.MODEL SMALL ; defines memory to be used


.STACK 100H ; defines stack of 256 bytes
.CODE ; code segment starts
MOV AX, 2000
MOV BX, 2000H
MOV CX, 1010001B
MOV DX, -4567
MOV AH,’A’; Copies ASCII value of”A” in AH
MOV AL,’a’ ; Copies ASCII value of”a” in AH
MOV AH, 4CH
INT 21H ; INT 21h returns the control to DOS if AH=4CH
END

Assembling Program in Emu8086

Emu8086 is an integrated development environment; it consists of an editor, an assembler, linker


and a debugger.
To use Emu8086 for assembling your program, do following steps and attach the result in the
form of screen shot in lab file.

a) Open the emu8086 present on your desktop. Following window will be appeared.
b) Select “new” from the above window. A new small window will appear select “COM
template” and press Ok.
c) A code window will appear just write your specific code in the space mentioned for the
code.
d) After writing your code, go to the file menu and save your code with an appropriate name
(the .asm extension is by default, you don’t have to write it explicitly).
e) After saving your code, compile your code by pressing compile menu and view it there
are any errors otherwise just press ok.
f) Now emulate your program form the menu and see the values of registers step by step and
also get familiar with relevant things shown by the emulator.
g) Emulator screen is present for I/O.

You might also like