Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
111 views11 pages

CHAPTER 3: Instruction Set and Programming of 8086: Compiled by Vishal Gaikwad, SIESGST

The document discusses instruction set and programming of the 8086 microprocessor. It covers 8086 addressing modes, instruction encoding formats and the instruction set. It also discusses assembler directives like ORG, ASSUME, DB, DD, DQ, DT, DW, ENDS, EQU, EVEN, GROUP, INCLUDE, ENDP, PUBLIC, LENGTH and OFFSET. Additionally, it provides examples of 8086 assembly language programs for finding the maximum and minimum numbers from an array of 10 numbers and arranging given numbers in ascending order.

Uploaded by

Anikhet Mulky
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
0% found this document useful (0 votes)
111 views11 pages

CHAPTER 3: Instruction Set and Programming of 8086: Compiled by Vishal Gaikwad, SIESGST

The document discusses instruction set and programming of the 8086 microprocessor. It covers 8086 addressing modes, instruction encoding formats and the instruction set. It also discusses assembler directives like ORG, ASSUME, DB, DD, DQ, DT, DW, ENDS, EQU, EVEN, GROUP, INCLUDE, ENDP, PUBLIC, LENGTH and OFFSET. Additionally, it provides examples of 8086 assembly language programs for finding the maximum and minimum numbers from an array of 10 numbers and arranging given numbers in ascending order.

Uploaded by

Anikhet Mulky
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/ 11

CHAPTER 3: Instruction set and programming of 8086

 8086 Addressing modes.


 8086 Instruction encoding formats and instruction set.
 Assembler directives.
 8086 programming and debugging of assembly language program. Programs
related to: arithmetic, logical, delay, string manipulation, stack and subroutines,
input, output, timer/counters.
 Elementary DOS Programming: Introduction to int-21h services.

Compiled by Vishal Gaikwad, SIESGST.


Addressing Modes of 8086

1. Register Addressing mode


2. Immediate Addressing mode
3. Direct Addressing mode
4. Register Indirect Addressing mode
5. Indexed Addressing mode
6. Base Relative Addressing mode
7. Base Indexed Addressing mode

1. Register Addressing Mode

Data transfer using registers is called register addressing mode. Here operand value is present
in register. For example:
MOV AL,BL;
MOV AX,BX;

2. Immediate Addressing mode

When data is stored in code segment instead of data segment immediate addressing mode is
used. Here operand value is present in the instruction. For example:

MOV AX, 12345;

3. Direct Addressing mode

When direct memory address is supplied as part of the instruction is called direct addressing
mode. Operand offset value with respect to data segment is given in instruction.
For example:
MOV AX, [1234];
ADD AX, [1234];

4. Register Indirect Addressing mode

Here operand offset is given in a cpu register. Register used are BX, SI(source index),
DI(destination index), or BP(base pointer). BP holds offset w.r.t Stack segment, but SI,DI and
BX refer to data segment.

Compiled by Vishal Gaikwad, SIESGST.


For example:
MOV [BX],AX;
ADD AX, [SI];
5. Indexed Addressing mode

In this addressing mode, the operands offset address is found by adding the contents of SI or
DI register and 8-bit/16-bit displacements.
For example:
MOV BX, [SI+16],
ADD AL, [DI+16]

6. Base Relative Addressing mode

Operand offset given by a sum of a value held either in BP, or BX and a constant offset
sepecified as an operand.
For example:
MOV AX,[BP+1];
JMP [BX+1];

7. Base Indexed

Here operand offset is given by sum of either BX or BP with either SI or DI.


For example:
MOV AX, [BX+SI]
JMP [BP+DI]

Assembler Directives for 8086

ORG (ORIGIN)

ORG Changes the starting offset address of the data in the data segment. As an assembler
assembles a section of a data declarations or instruction statements, it uses a location counter
to keep track of how many bytes it is from the start of a segment at any time. The location
counter is automatically set to 0000 when assembler starts reading a segment.
The ORG directive allows you to set the location counter to a desired value at any point in the
program.

Compiled by Vishal Gaikwad, SIESGST.


Example: The statement ORG 2000H tells the assembler to set the location counter to 2000H.

ASSUME

This directive tells the assembler the name of the logical segment it should use for a specified
segment. For example ASSUME CS:CODE, tells the assembler that the instructions for a
program are in a logical segment named CODE. The 8086 works directly with only 4 physical
segments: a Code segment, a data segment, a stack segment, and an extra segment.

DB – Define Byte

This directive is used to declare a byte type variable or to store a byte in memory location. For
example
NAME DB ‘THOMAS’;
VALUES DB ‘0’,’1’,’2’,’3’;

DD – Define Doubleword

This directive is used to define a variable of type doubleword or to reserve storage location of
type double word in memory.
For example:
POINTER DD 12341234H

DQ – Define Quadword

This directive is used to define a variable of type quadword or to reserve storage location of
type quadword in memory.
For example:
POINTER DQ 1234123412341234H
DT – Define Ten Bytes

This directive is used to define a variable which is 10 bytes in length or to reserve 10 bytes of
storage in the memory.
For example:
POINTER DT 11223344556677889900

Compiled by Vishal Gaikwad, SIESGST.


DW – Define Word

This directive is used to define a variable of type word or to reserve storage location of type
word in memory.
For example
ARRAY DW 100DUP(0) ; defines an array of size 100 all initialized to 0.
MULTIPLIER DW 1234h; defines a variable multiplier of value 1234h

ENDS

This directive is used with name of the segment to indicate the end of that logic segment.
For example:
CODE SEGMENT ; this statement starts the segment
CODE ENDS ; this statement ends the segment

EQU

This directive is used to give a name to some value or to a symbol. Each time the assembler
finds the name in the program, it will replace the name with the value or symbol you given to
that name.
For example:
FACTOR EQU 03H ; this equates factor to 03h can be used as
ADD AL, FACTOR ; When it codes this instruction the assembler will code it
as ADD AL, 03H ;
The advantage of using EQU in this manner is, if FACTOR is used many no of times in a
program and you want to change the value, all you had to do is change the EQU statement at
beginning, it will changes the rest of all.

EVEN

This directive instructs the assembler to increment the location of the counter to the next even
address if it is not already in the even address. If the word is at even address 8086 can read a
memory in 1 bus cycle.
If the word starts at an odd address, the 8086 will take 2 bus cycles to get the data. A series of
words can be read much more quickly if they are at even address. When EVEN is used the

Compiled by Vishal Gaikwad, SIESGST.


location counter will simply incremented to next address and NOP instruction is inserted in
that incremented location.
For example:
DATA1 SEGMENT ; Location counter will point to 0009 after assembler reads next statement
SALES DB 9 DUP(?) ;declare an array of 9 bytes
EVEN ; increment location counter to 000AH
RECORD DW 100 DUP(0) ;Array of 100 words will start from an even address for quicker
read
DATA1 ENDS

GROUP

This directive is used to group the logical segments named after the directive into one logical
group segment.

INCLUDE

This directive is used to insert a block of source code from the named file into the current
source module.

ENDP (END PROCEDURE)

The directive is used along with the name of the procedure to indicate the end of a procedure
to the assembler. The directive, together with the procedure directive, PROC, is used to
“bracket” a procedure.

Example:
SQUARE_ROOT PROC; Start of procedure.
SQUARE_ROOT ENDP; End of procedure.

PUBLIC

Large program are usually written as several separate modules. Each module is individually
assembled, tested, and debugged. When all the modules are working correctly, their object code
files are linked together to form the complete program. In order for the modules to link together
correctly, any variable name or label referred to in other modules must be declared PUBLIC in

Compiled by Vishal Gaikwad, SIESGST.


the module in which it is defined. The PUBLIC directive is used to tell the assembler that a
specified name or label will be accessed from other modules.

LENGTH

LENGTH is an operator, which tells the assembler to determine the number of elements in
some named data item, such as a string or an array.
Example: MOV CX, LENGTH STRING1
This will determine the number of elements in STRING1 and load it into CX. If the string was
declared as a string of bytes, LENGTH will produce the number of bytes in the string. If the
string was declared as a word string, LENGTH will produce the number of words in the string.

OFFSET

OFFSET is an operator, which tells the assembler to determine the offset or displacement of a
named data item (variable), a procedure from the start of the segment, which contains it.
Example:
MOV BX, OFFSET PRICES;
It will determine the offset of the variable PRICES from the start of the segment in which
PRICES is defined and will load this value into BX.

Compiled by Vishal Gaikwad, SIESGST.


University Questions and 8086 programming

1. Write a program for 8086 to find the maximum number form array of 10 numbers.
[10M,Dec-2017]

; Assume 10 numbers are stored in 2000H onwards locations

MOV SI, 2000


MOV DI, 4000
MOV CX, 0009
MOV AX, [SI] ; Move the first number into AX register
BACK: INC SI
CMP AX, [SI]
JNC DOWN
MOV AX, [SI]
DOWN: LOOP BACK
MOV [DI], AX
INT 3

2. Write a program for 8086 to find the smallest number form array of 10 numbers.
[10M,May-2015]

; Assume 10 numbers are stored in 2000H onwards locations

MOV SI, 2000


MOV DI, 4000
MOV CX, 0009
MOV AX, [SI] ; Move the first number into AX register
BACK: INC SI
CMP AX, [SI]
JC DOWN
MOV AX, [SI]
DOWN: LOOP BACK
MOV [DI], AX
INT 3

Compiled by Vishal Gaikwad, SIESGST.


3. Write a program for 8086 microprocessor for arranging given numbers in ascending
order and store the result in memory location 0800H onwards. [10M,Dec-2016]

; Assume 10 numbers are stored in 0800H onwards locations

MOV SI, 0800


MOV DX, 0005
UP: MOV CX, 0004
BACK: MOV AX, [SI] ; Move the first number into AX register
INC SI
CMP AX, [SI]
JC DOWN
MOV BX, [SI]
MOV [SI], AX
DEC SI
MOV [SI], BX
INC SI
DOWN: DEC CX
JNZ BACK
DEC DX
JNZ UP
MOV [DI], AX
INT 3

4. Write a program for 8086 to multiply two 32 bit numbers (12345678 X 87654321)
[10M,May-2015]
5. Explain with suitable examples the following instructions of 8086, [10M,Dec-2016]
1. CBW 2.TEST 3. LAHF 4. XLAT 5.LEA
6. Describe the various addressing modes supported by 8086 with examples.[10M,Dec-
2016, 10M-Dec-2015,5M-May-2015, 10M-May-2018]
7. Write assembly language program to add two 32 bit numbers and also draw flowchart.
[10M May-2016]

Compiled by Vishal Gaikwad, SIESGST.


Assume 1st 32 bit number stored at 1000H onward locations, and 2nd 32 bit number
stored at 2000H onwards locations.

MOV AX, 5000H ; Initialize DATA SEGMENT to 5000H


MOV DS, AX
MOV AX, [1000H] ; take lower 16-bit of NUM1 in AX
MOV BX, [2000H] ; take lower 16-bit of NUM2 in BX
ADD AX, BX ; AX = AX + BX
MOV [3000H], AX ; Store lower 16-bit result at NUM3
MOV AX, [1002H] ; take higher 16-bit of NUM1 in AX
MOV BX, [2002H] ; take higher 16-bit of NUM2 in BX
ADC AX, BX ; AX = AX + BX + CF (add with carry)
MOV [3002H], AX ; Store higher 16-bit result at NUM3
HLT ; Halt 8086

Based on the following algorithm draw flowchart.

Step I : Initialize the data segment.


Step II : Load the LSB of first number into AX register.
Step III : Load the MSB of first number into BX register.
Step IV : Load the LSB of the second number into CX register.
Step V : Load the MSB of the second number into DX register.
Step VI : Add the LSBs of two number.
Step VII : Add the MSBs of two numbers along with carry.
Step VIII : Display the result.
Step IX : Stop.

Compiled by Vishal Gaikwad, SIESGST.


8. Write an assembly language program to find factorial of number N and also draw
flowchart. [10M,Dec-2016]
Assume number N stores at 2000H location
MOV SI, 2000
MOV DI, 2002
MOV CX, [SI]
MOV AX, CX ; Move contents of CX to contents of AX register
DEC CX ; Decrement CX
UP: MUL CX
DEC CX ; Decrement CX
JNZ UP ; Jump if not zero
MOV [DI], AX ; Load the values of AX into location given by DI
INT 3

For the remaining programs please refer online resources/lab programs/any book

Compiled by Vishal Gaikwad, SIESGST.

You might also like