Introduction To Assembly Language: Lab Experiment # 1
Introduction To Assembly Language: Lab Experiment # 1
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
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
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.
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.
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
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.
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: -
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.