Seminar Topics & Project Ideas On Computer Science Electronics Electrical Mechanical Engineering Civil MBA Medicine Nursing Science Physics Mathematics Chemistry ppt pdf doc presentation downloads and Abstract

Full Version: 8086 Assembler Tutorial for Beginners
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[attachment=72934]



This tutorial is intended for those who are not familiar with
assembler at all, or have a very distant idea about it. Of course if you
have knowledge of some other programming language (Basic, C/C++,
Pascal...) that may help you a lot.
But even if you are familiar with assembler, it is still a good idea to
look through this document in order to study emu8086 syntax.
It is assumed that you have some knowledge about number
representation (HEX/BIN), if not it is highly recommended to study
Numbering Systems Tutorial before you proceed.
What is an assembly language?
Assembly language is a low level programming language. You need
to get some knowledge about computer structure in order to understand
anything. The simple computer model as I see it:



GENERAL PURPOSE REGISTERS
8086 CPU has 8 general purpose registers, each register has its own
name:
· AX - the accumulator register (divided into AH / AL).
· BX - the base address register (divided into BH / BL).
· CX - the count register (divided into CH / CL).
· DX - the data register (divided into DH / DL).
· SI - source index register.
· DI - destination index register.
· BP - base pointer.
· 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 separate
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.
3
8086 Assembler Tutorial Prof. Emerson Giovani Carati, Dr. Eng.
SEGMENT REGISTERS
· CS - points at the segment containing the current program.
· DS - generally points at segment where variables are defined.
· ES - extra segment register, it's up to a coder to define its usage.
· 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.
Segment registers work together with general purpose register to
access any memory value. For example if we would like to access memory
at the physical address 12345h (hexadecimal), we should set the DS =
1230h and SI = 0045h. This is good, since this way we can access much
more memory than with a single register that is limited to 16 bit values.
CPU makes a calculation of physical address by multiplying the
segment register by 10h and adding general purpose register to it (1230h
* 10h + 45h = 12345h):
The address formed with 2 registers is called an effective address.
By default BX, SI and DI registers work with DS segment register;
BP and SP work with SS segment register.
Other general purpose registers cannot form an effective address!
Also, although BX can form an effective address, BH and BL cannot!
SPECIAL PURPOSE REGISTERS
· IP - the instruction pointer.
· Flags Register - determines the current state of the processor.
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.



(Part 4)
Interrupts
Interrupts can be seen as a number of functions. These functions
make the programming much easier, instead of writing a code to print a
character you can simply call the interrupt and it will do everything for
you. There are also interrupt functions that work with disk drive and other
hardware. We call such functions software interrupts.
Interrupts are also triggered by different hardware, these are called
hardware interrupts. Currently we are interested in software
interrupts only.
To make a software interrupt there is an INT instruction, it has
very simple syntax:
INT value
where value can be a number between 0 to 255 (or 0 to 0FFh), generally
we will use hexadecimal numbers.
You may think that there are only 256 functions, but that is not
correct. Each interrupt may have sub-functions.
To specify a sub-function AH register should be set before calling
interrupt. Each interrupt may have up to 256 sub-functions (so we get
256 * 256 = 65536 functions). In general AH register is used, but
sometimes other registers maybe in use. Generally other registers are
used to pass parameters and data to sub-function. The following example
uses INT 10h sub-function 0Eh to type a "Hello!" message. This functions
displays a character on the screen, advancing the cursor and scrolling the
screen as necessary.