Chapter-5: Assembly Language Programming Using 8086 (16 Marks)
Chapter-5: Assembly Language Programming Using 8086 (16 Marks)
Assembly Language
Programming using 8086
(16 Marks)
Introduction
● An Assembly Language programming is low level
language programming.
● An assembly language program has to be converted
● Initialization checklist
● Choosing instructions
Subroutine Connector
4. Initialization Checklist :-
• In program there are many variables, constants, segment
registers, flags, stack which must be initialize properly.
• The best way to approach the initialization task is to make the
checklist of the entire variables, constants, registers, flags in the
program.
5. Choosing instructions :-
• Next step is to choose proper instruction that performs your
problem’s operations or tasks.
• This is an important step, so you must know entire instruction
set of the microprocessor, the operation performed and flag
affected after the execution by the instructions.
6. Converting algorithms to assembly language program :-
• Once you have selected the instructions for the operations to be
performed, then arrange these instructions in sequence as per
algorithm.
• Next step is to convert algorithm in to assembly language
program.
Assembly Language Program
Development Tools:-
1.Editor
2.Assembler
3.Linker
4.Debugger
1. Editor :-
• An editor is a program which helps you to
construct your assembly language program in
right format so that the assembler will translate
it correctly to machine language.
• So, you can type your program using editor.
• The Dos based editor such as EDIT, WordStar
and Norton Editor etc. can be used to type
your program.
• Program type in any editor has file extension as
.asm
2. Assembler :- .asm - .obj
• An assembler is a program that translate
assembly language program to machine
language that can be understand by
microprocessor and generate the file called as
object file with extension .obj.
• Examples of assembler are TASM(Borland’s
Turbo Assembler) and MASM(Microsoft Macro
Assembler) etc.
3. Linker :- .obj - .exe
• A linker is a program which combines more than one
separately assembled module into one executable
program and generate .exe module.
• Examples are TLINK(Borland’s Turbo Linker) and
LINK(Microsoft’s Linker) etc.
4. Debugger :-
• Debugger is a program that allows the execution of
program in single step mode under the control of the
user.
• The process of locating and correcting errors using a
debugger is known as debugging.
• Examples are Dos Debug command, Borland’s Turbo
Debugger(TD) etc.
Addressing Modes:-
The different ways in which a source operand is
denoted in an instruction are known as the
addressing modes.
Actually 8086 supports 24 addressing modes but only 8 are
utilized in 8086 programming. They are
Ex : MOV AX,[BX+DI+08]
ADD CX,[BX+SI+16]
Instruction Set of 8086
An instruction is a binary pattern designed
inside a microprocessor to perform a specific task
or function.
The entire group of instructions that a
microprocessor supports is called Instruction
Set.
8086 has more than 20,000 instructions.
Classification of Instruction Set
Data Transfer Instructions
Arithmetic Instructions
Bit Manipulation Instructions
Flag Manipulation Instructions
String Instructions
Data Transfer Instructions
These instructions are used to transfer data from
source to destination.
The operand can be a constant, memory location,
register or I/O port address.
E.g.: PUSH BX
POP Des:
●
It pops the operand from top of stack to Des.
●
Des can be a general purpose register, segment register
(except CS) or memory location.
E.g.: POP AX
Data Transfer Instructions
XCHG Des, Src:
This instruction exchanges Src with Des.
It cannot exchange two memory locations directly.
E.g.: XCHG DX, AX
27
Arithmetic Instructions
ADD Des, Src:
The src may be an immediate number, register or a
memory location.
The Des may be an immediate number, register or a
memory location.
The src and Des must be of same type and cannot both
be memory locations.
E.g.:
SBB AL, 74H
SBB DX, AX
Arithmetic Instructions
INC Src:
●
It increments the byte or word by one.
●
The operand can be a register or memory location.
E.g.: INC AX ; AX = AX + 1
DEC Src:
● It decrements the byte or word by one.
● The operand can be a register or memory location.
E.g.: DEC AX ; AX = AX - 1
Arithmetic Instructions
DAA (Decimal Adjust after Addition)
It only works on AL register.
This instruction must be used after the ADD/ADC
instruction.
The ADD/ADC instruction adds the two BCD number
in hexadecimal format and DAA instruction convert
this hexadecimal result into BCD result.
Arithmetic Instructions
The working of DAA instruction is given below:
1. If lower nibble in AL accumulator > 9 or AF=1 then
AL=AL+06
2. If higher nibble in AL accumulator > 9 or CF=1
AL=AL+60
3. If both above conditions are satisfied, then
AL=AL+66
Arithmetic Instructions
e.g. If AL=99H, BL=99H
ADD AL, BL ; 1001 1001 AL=99H
+ 1001 1001 BL=99H
--------------------------
0011 0010 AL=32H , CF=1, AF=1
i.e . third condition is true (AF=CF=1), then add 66H into the AL
register.
0011 0010 AL=32H
+ 0110 0110 66H
-----------------------
1001 1000 AL=198 in BCD form.
Arithmetic Instructions
DAS (Decimal Adjust after Subtraction)
It only works on AL register.
This instruction must be used after the SUB/SBB instruction.
The SUB/SBB instruction subtracts the two BCD number in
hexadecimal format and DAS instruction convert this hexadecimal
result into BCD result.
The working of DAS instruction is given below:
1. If lower nibble in AL accumulator > 9 or AF=1 then
AL=AL-06
2. If higher nibble in AL accumulator > 9 or CF=1
AL=AL-60
3. If both above conditions are satisfied, then
AL=AL-66
Arithmetic Instructions
NEG Src:
It creates 2’s complement of a given number.
That means, it changes the sign of a number.
NOT Src:
It complements each bit of Src to produce 1’s
complement of the specified operand.
The operand can be a register or memory location.
Example :
OR BH, CL ; OR byte in CL with byte in BH, result in BH
Bit Manipulation(Logical) Instructions
SHL Des, Count:
●
It shift each bit in the specified destination count times toward
left.
●
It puts zero(s) in LSBs. LSB 0
●
MSB is shifted into carry flag. CF MSB
●
If the number of bits desired to be shifted is 1, then the immediate
number 1 can be written in Count.
●
However, if the number of bits to be shifted is more than 1, then
the count is put in CL register.
Bit Manipulation(Logical) Instructions
Example :
BX=11100101 11010011
CF=0
SHL BX, 1 ; Shift the contents of BX register by one towards left.
CF=1 BX= 11001011 10100110
Example :
CF=0 BL=0011 1011
ROR BL, 1 ; Rotate the contents of BL right by one bit position.
CF=1 BL= 1001 1101
Flag Manipulation Instructions
This type of instructions are used to change the status of
flags in the flag register such as CF, DF and IF.
STC: It sets the carry flag to 1. i.e. CF=1
CLC: It clears the carry flag to 0. i.e. CF=0
CMC: It complements the carry flag. i.e. CF= ~ CF
STD: It sets the direction flag to 1. i.e. DF=1
CLD: It clears the direction flag to 0. i.e. DF=0
CLI :-It clears the interrupt flag to 0. i.e. IF=0
STI :- It sets the interrupt flag to 1. i.e. IF=1
String Instructions
MOVS / MOVSB / MOVSW:
●
It causes moving of byte or word from one string to
another.
●
In this instruction, the source string is in Data Segment
and destination string is in Extra Segment.
●
SI and DI store the offset values for source and
destination string.
●
Source string is represented as DS:SI
●
Destination String is represented as ES:DI
Operation :
ES:[DI] -------DS:[SI]
String Instructions
●
On the execution of this instruction both SI and DI are
automatically incremented by one to point next element
of source and destination.
For byte movement,
If DF=0, SI=SI+1, DI=DI+1
If DF=1, SI=SI-1, DI=DI-1
For word movement,
If DF=0, SI=SI+2, DI=DI+2
If DF=1, SI=SI-2, DI=DI-2
String Instructions
LODS / LODSB / LODSW: This instruction transfers word
or byte from source string pointed by SI in AL for byte or
AX for word.
On execution of this instruction only SI is incremented by
one to point next element of source string.
For byte movement, AL-------DS:[SI]
If DF=0, SI=SI+1
If DF=1, SI=SI-1
For word movement, AX-------DS:[SI]
If DF=0, SI=SI+2
If DF=1, SI=SI-2
String Instructions
STOS / STOSB / STOSW: This instruction transfers word or
byte from AL for byte and AX for word to destination string
pointed by DI in ES.
On execution of this instruction only DI is incremented by
one to point next element of destination string.
For byte movement, ES:[DI]-------AL
If DF=0, DI=DI+1
If DF=1, DI=DI-1
For word movement, ES:[DI]-------AX
If DF=0, DI=DI+2
If DF=1, DI=DI-2
String Instructions
CMPS (Compare string) : This instruction compares a
byte or word in the source string with a byte or word in the
destination string.
On execution of this instruction both SI and DI are
incremented by one to point next element of source and
destination string.
For byte comparison,
If DF=0, SI=SI +1, DI=DI+1
If DF=1, SI=SI -1, DI=DI-1
For word comparison,
If DF=0, SI=SI +2 ,DI=DI+2
If DF=1, SI=SI -2, DI=DI-2
String Instructions
CMPSB (Compare string Byte) : This instruction
compares a byte in the source string with a byte in the
destination string.