You are on page 1of 18

8086 Microprocessor

Addressing Modes and Assembler Directives

Contents
Introduction Addressing modes Assembler directives Assembler directives types

Prepared by:Shruthi.K, Dept. of E&C, MIT.

Introduction
The MP communicates and operates in the binary system having 0 and 1 as bits. Each MP has a fixed set of instructions in the form of binary patterns called machine language. It is difficult for users to communicate in this binary language. Hence instructions are given abbreviated names called mnemonics which form the assembly language for a given MP. The mnemonic for a particular instruction consists of letters that suggest the operation to be performed by that instruction. An instruction is decided into groups of bits or fields, with one field called as operation code (opcode) indicating what the processor has to do and the other fields called operands, indicating the information needed by the instruction in carrying out its task.

Prepared by:Shruthi.K, Dept. of E&C, MIT.

Introduction
An operand may contain a datum, part of the address of a datum, an indirect pointer to a datum or other information pertaining to the data to be acted on by the instruction. Instructions may contain several operands but more the operands and longer the operands are, more memory space will be occupied and more time will be taken for execution. In order to minimize the total number of bits in an instruction, most instructions will have one operand in register. Memory and I/O spaces are relatively large and hence their address require several bits. But number of registers is small, hence it takes only few bits to specify a register. Therefore to conserve instruction bits, registers must be used as much as possible.

Prepared by:Shruthi.K, Dept. of E&C, MIT.

Addressing Modes
The way in which an operand is specified is called its addressing mode. 8086 has addressing modes for data and branch address separately. 8086 data addressing modes are: 1. Immediate 2. Direct 3. Register 4. Register indirect 5. Register relative 6. Based indexed 7. Relative based indexed 8086 branch addressing modes are: 1. Intrasegment direct 2. Intrasegment indirect 3. Intersegment indirect 4. Intersegment direct

Prepared by:Shruthi.K, Dept. of E&C, MIT.

Data Addressing Modes


Immediate data is either 8 bits or 16 bits and is part of the instruction. Ex: mov al,80h mov AX, 1345h Direct the 16 bit offset address of the data is part of the instruction. Ex: mov BX,[1560h] Register direct the data is stored in the register which is specified I the istruction. Ex: mov AX,BX Register indirect the 16 bit address of the data is stored in base register (BX) or any of the index registers (SI/DI) and this register is specified in the instruction. Ex: mov AX, [SI]

Prepared by:Shruthi.K, Dept. of E&C, MIT.

Data Addressing Modes


Register relative the address of the data is the sum of an 8 or 16 bit displacement and the contents of a base register or an index register and this is specified in the instruction. Ex: mov AX, [BX+20h] mov AX, [DI+2349h] Based indexed the address of the data is the sum of contents of an base register and an index register, both of which are specified in the instruction. Ex: mov AX,[BX+SI] Relative based indexed the address of the data is the sum of contents of an base register and an index register and an 8/16 bit displacement, all of these are specified in the instruction. Ex: mov AX,[BX+SI+69h]

Prepared by:Shruthi.K, Dept. of E&C, MIT.

Addressing Modes for Branch addresses


Refer page 38 &39 Microcomputer Systems: The 8086/8088 Family by Yu-Cheng Liu & Glenn A. Gibson.
Prepared by:Shruthi.K, Dept. of E&C, MIT.

Instruction Format
The general format of an assembler instruction is Label : Mnemonic operand2, operand1 Label it is an identifier that is assigned to the address of the first byte of instruction. Its presence is optional. Operand2 & operand 1 data on which operation to be performed. Operand 2 indicates destination and operand 1 indicates source.

Prepared by:Shruthi.K, Dept. of E&C, MIT.

Assembler Directives
There are some instructions in the assembly language which
are not a part of the processor instruction set.
Prepared by:Shruthi.K, Dept. of E&C, MIT.

These instructions are instructions to the assembler. These are referred to as pseudo operations or as assembler directives.

They are used to control during program assembling and do


not generate any executable machine code.

10

Assembler Directives Types


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Data definition and storage allocation directives DB,DW. Program organization directives SEGMENT, ASSUME. Alignment directives ORG Program end directives END Value returning directives LENGTH,SIZE Procedure definition directives PROC,ENDP Macro definition directives MACRO,ENDM Data control directives PUBLIC,EXTRN Branch displacement directives LABEL, SHORT Header file inclusion directive - INCLUDE

Prepared by:Shruthi.K, Dept. of E&C, MIT.

11

Assembler Directives
1. ASSUME used to instruct the assembler the name of the logical segment it should use for a specified segment. Ex: ASSUME CS: code, DS: data 2. DB(Define byte) used to declare a byte type variable or to set aside one or more memory locations of type byte in memory. Ex: temp DB 67h prices DB 45h,89h,23h temp DB 100 DUP(?) store DB 50 DUP(00h) 3. DW(Define word) instructs the assembler to define a variable of type word or to reserve memory locations of type word in memory. Ex: mul DW 437AH

Prepared by:Shruthi.K, Dept. of E&C, MIT.

12

Assembler Directives
4. DD (define double word) 5. DQ(define quad word) 6. DT(define ten bytes) 7.END it is put after the last instruction of a program to instruct the assembler that it is the physical end of the program. Ex: start: mov ax, bx add ax, bx END start 8. PROC instruction to assembler that next set of instructions form a procedure. 9. ENDP used along with the name of the procedure to indicate the end of a procedure to the assembler. Ex: display PROC near/far mov ax,bx ENDP display

Prepared by:Shruthi.K, Dept. of E&C, MIT.

13

Assembler Directives
10. SEGMENT used to indicate the start of a logical segment. 11. ENDS used with the name of a segment to indicate the end of that logical segment. Ex: data SEGMENT Temp DB 45h data ENDS 12. EQU(Equate) used to give name to some value. Each time the assembler finds the given name in the program, it replaces the name by the value assigned to it. Ex: data EQU 45h mov al,data (al = 45h)

Prepared by:Shruthi.K, Dept. of E&C, MIT.

14

Assembler Directives
13. INCLUDE used to instruct the assembler to insert a block of source code from the named file into the current source module. Ex: INCLUDE macro.lib 14. LENGTH instructs the assembler to determine the number of elements in some named data item such as an array or a string. Ex: data SEGMENT name DB 100 DUP(?) data ENDS code SEGMENT mov ax, LENGTH name (ax=100) code ENDS

Prepared by:Shruthi.K, Dept. of E&C, MIT.

15

Assembler Directives
15. OFFSET informs the assembler to determine the offset of a named data item from the start of the segment which contains it. Ex: data SEGMENT prices DB 12h,23h,34h data ENDS code SEGMENT mov BX, OFFSET prices code ENDS 16. ORG(Originate) the directive informs the assembler that the next code or data following the directive should be allocatted in the address mentioned with the directive. Ex: ORG 100h temp db 34h,67h,

Prepared by:Shruthi.K, Dept. of E&C, MIT.

16

Assembler Directives
17. PTR (pointer) used to explicitly specify the type of data being referred by a variable. Ex: data SEGMENT Array db 12h,23h,34h,45h data ENDS code SEGMENT mov BX, OFFSET Array Mov DL, BYTE PTR[BX] code ENDS 18.MODEL this directive provides shortcuts in defining segments. It initializes memory model before defining any segment. The memory model can be small, large, medium.

Prepared by:Shruthi.K, Dept. of E&C, MIT.

17

Assembler Directives
19. MACRO informs the assembler the beginning of the macro. 20. ENDM informs the assembler the end of the macro. Ex: macro name MACRO arguments ----------------ENDM

Prepared by:Shruthi.K, Dept. of E&C, MIT.

18