100% found this document useful (2 votes)
686 views55 pages

Chapter-5: Assembly Language Programming Using 8086 (16 Marks)

The document provides information about assembly language programming using 8086 microprocessor. It discusses the basic concepts of assembly language programming such as introduction, program development steps, addressing modes, instruction set classification and examples of common instructions. The program development steps include defining the problem, creating an algorithm, flowchart, initialization checklist, choosing instructions and converting the algorithm to an assembly language program. It also describes the assembly language program development tools of editor, assembler, linker and debugger.

Uploaded by

PRABHAKAR MORE
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
100% found this document useful (2 votes)
686 views55 pages

Chapter-5: Assembly Language Programming Using 8086 (16 Marks)

The document provides information about assembly language programming using 8086 microprocessor. It discusses the basic concepts of assembly language programming such as introduction, program development steps, addressing modes, instruction set classification and examples of common instructions. The program development steps include defining the problem, creating an algorithm, flowchart, initialization checklist, choosing instructions and converting the algorithm to an assembly language program. It also describes the assembly language program development tools of editor, assembler, linker and debugger.

Uploaded by

PRABHAKAR MORE
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/ 55

Chapter-5

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

into machine language using assembler(MASM or


TASM).
● Assembly language programming requires good
knowledge of machine architecture, operating system
and programming principles.
● Assembly language is case insensitive, so program can

be loaded either in uppercase, lowercase or


combination of lowercase and uppercase.
● The program development tools , such as editor,
assembler, linker and debugger are required for the
programming.
Program Development Steps :-
● Algorithm
● Flowchart

● Defining the problem

● Initialization checklist

● Choosing instructions

● Converting algorithms to assembly language


program.
1. Defining the problem :-
• The first step in writing program is to think
very carefully about the problem that you
want the program to solve.
• At this point you need not to write down
program but you must know what you
would like to do.
2. Algorithm :-
• The sequence of operations or tasks
performed by your program can be
specified as a step in general English is
often called as Algorithm.
3. Flowchart :-
• The flowchart is a graphically
representation of the program operation or
task.
• The symbols that are used in flowchart are
circle, rectangle, diagonal, square and
parallelogram etc.
Input /
Process Decision
Output

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

1. Immediate addressing mode


2. Register addressing mode
3. Direct addressing mode
4. Register indirect addressing mode
5. Based addressing mode
6. Indexed addressing mode.
7. Based indexed addressing mode
8. Based, Indexed with displacement.
1. Immediate addressing mode:
 The addressing mode in which the data operand is a part of
the instruction itself is called immediate addressing mode.
 So source data may be 8 bit or 16 bit in length.

e.g.: MOV AL, 46H ; AL is loaded with 8 bit immediate data


46H, here 46H is the immediate data

MOV CX, 4847H ; CX is loaded with 16 bit immediate data


4847H, here 4847H is the immediate data.
Actually 8086 supports 24 addressing modes but only 8 are
utilized in 8086 programming. They are

1. Immediate addressing mode


2. Register addressing mode
3. Direct addressing mode
4. Register indirect addressing mode
5. Based addressing mode
6. Indexed addressing mode.
7. Based indexed addressing mode
8. Based, Indexed with displacement.
2. Register addressing mode : Register addressing
mode means, a register is the source of an operand for
an instruction.

e.g. : MOV AX, BX ; copies the contents of the 16-bit BX


register into the 16-bit AX register. 
3. Direct addressing mode:
 The addressing mode in which the effective address of the
memory location at which the data operand is stored is given
in the instruction. i.e the effective address is just a 16-bit
number is written directly in the instruction.
 
E.g. : MOV BX, [1354H]
MOV BL,[0400H]
 
 The square brackets around the 1354 H denotes the contents
of the memory location. When executed, this instruction will
copy the contents of the memory location into BX register
4. Register indirect addressing mode: Register indirect
addressing allows data to be addressed at any memory
location through an offset address held in any of the
following registers: BP, BX, DI and SI.

 Ex:MOV AX, [BX] Suppose the register BX contains


4675H ,the contents of the 4675 H are moved to AX.

 5. Based addressing mode: The offset address of the


operand is given by the sum of contents of the BX or BP
registers and an 8-bit or 16-bit displacement.

 Ex: MOV DX, [BX+04]


6. Indexed Addressing mode: The operands offset address
is found by adding the contents of SI or DI register and 8-bit
or 16-bit displacements.
 Ex: MOV BL,[SI+06] ; Copies data from memory location
whose offset is calculated by adding the content of SI with 8bit
displacement to BL.

7. Based -index addressing mode: The offset address of


the operand is computed by summing the base register to the
contents of an Index register.

 Ex: MOV AX,[BX+DI] ; Copies the word from memory


location whose offset is calculated by adding the content of BX
with the contents of DI.
 
8. Based indexed with displacement mode: The
operands offset is computed by adding the base register
contents, an Index registers contents and 8 or 16-bit
displacement.

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

MOV {Destination, Source}


Opcode Operands
Data Transfer Instructions
 MOV Des, Src:
 Src operand can be register, memory location or
immediate operand.
 Des can be register or memory operand.
 Both Src and Des cannot be memory location at the
same time.
 E.g.:
 MOV AL, BL
Data Transfer Instructions
PUSH Operand:
It pushes the operand into top of stack.

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.: ADD AL, 74H ; AL= AL + 74H


 ADD DX, AX ; DX = DX + AX
Arithmetic Instructions
 ADC Des, Src: This instruction adds the carry flag into
the result.
 Destination= Source +Destination +CF
 It adds the two operands with CF.

 E.g.: ADC AL, 74H


 ADC DX, AX
Arithmetic Instructions
 SUB Des, Src:
 It subtracts source operand from destination operand.
 For subtraction, CF acts as borrow flag.
 E.g.:
 SUB AL, 74H
 SUB DX, AX
Arithmetic Instructions
 SBB Des, Src:
 It subtracts the two operands and also the borrow from
the result.

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

e.g. NEG AX ; Replace the number in AX with it’s 2’s


complement.
Arithmetic Instructions
 MUL Src: This is unsigned multiplication instruction.

 E.g. MUL BL ; Multiply AL by BL, result is stored in AX


 MUL CX ; Multiply AX by CX, result is in DX:AX register

 IMUL Src: It is a signed multiplication instruction.


Arithmetic Instructions
 DIV Src: It is an unsigned division instruction.
 It divides word by byte or double word by word.
 During the division of word by byte, the word
(dividend) must be in AX register and the byte (divisor)
may be in any 8 bit register or memory location.
 After the division, 8 bit quotient will be available in AL
and 8bit remainder will be in AH register.
e.g. DIV BL ; Divide word in AX by byte in BL,
Quotient in AL and remainder in AH.

IDIV Src: It is a signed division instruction.
Bit Manipulation(Logical) Instructions

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

e.g. NOT AL; complements each bit of AL register.


Bit Manipulation(Logical) Instructions
 AND Des, Src:
 It performs AND operation of Des and Src.

 Src can be immediate number, register or memory location.

 Des can be register or memory location.

 Both operands cannot be memory locations at the same time.

 Destination =destination AND source


 Example:

 AND BH, CL ; AND byte in CL with byte in BH, result in BH


Bit Manipulation(Logical) Instructions
OR Des, Src:

It performs OR operation of Des and Src.

Src can be immediate number, register or memory location.

Des can be register or memory location.

Both operands cannot be memory locations at the same time.

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

***Shift register BL Left 4 times. ***


Bit Manipulation(Logical) Instructions
SHR Des, Count:

It shift bits of byte or word right, by count.

It puts zero(s) in MSBs.

LSB is shifted into carry flag.

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 :
CF=0 BX= 11100101 11010011
SHR BX, 1 ; Shift the contents of BX register by one toward
right.
CF=1 BX= 01110010 11101001

*** Shift register BL Right 3 times. ***


Bit Manipulation(Logical) Instructions
ROL Des, Count:

It rotates bits of byte or word left, by count .

MSB is transferred to LSB and also to CF.

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.

Example :
CF=0 BL= 1011 1010
ROL BL, 1 ; Rotate all bits in BL left by one bit position.
CF=1 BL= 0111 0101
*** Rotate register BL Left 4 times. ***
Bit Manipulation(Logical) Instructions
ROR Des, Count:

It rotates bits of byte or word right, by count.

LSB is transferred to MSB and also to CF.

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.

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.

CMPSW (Compare string word) : This instruction


compares a word in the source string with a word in the
destination string.

You might also like