0% found this document useful (0 votes)
2 views

Lecture-2

The document discusses the instruction set and addressing modes of the 8086 microprocessor, detailing various types of instructions such as data transfer, arithmetic, and control transfer instructions. It explains different addressing modes including immediate, direct, and indirect addressing, as well as intersegment and intrasegment control transfer instructions. Additionally, it covers assembler directives used in 8086 assembly language programming.

Uploaded by

Feyissa Endebu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture-2

The document discusses the instruction set and addressing modes of the 8086 microprocessor, detailing various types of instructions such as data transfer, arithmetic, and control transfer instructions. It explains different addressing modes including immediate, direct, and indirect addressing, as well as intersegment and intrasegment control transfer instructions. Additionally, it covers assembler directives used in 8086 assembly language programming.

Uploaded by

Feyissa Endebu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

Ch-2: Instruction Set and Assembly

Language of 8086

Outlines:
• Addressing Mode
• Instructions Set

1 Microcomputer and Interfacing


Addressing Mode of 8086
 Indicate way of locating data or operand.
 Describe the type of operands and the way accessed
for executing an instruction.
 According to flow of instruction execution, the
instruction may be categorized as;
 Sequential control flow instruction
 Control transfer instructions

2 Microcomputer and Interfacing


Sequential Control Flow Instructions

 Are the instructions which after execution, transfer


control to the next instruction appearing immediately
after it.

 E.g: The arithmetic, logic, data transfer and processor


control instruction

3 Microcomputer and Interfacing


Control Transfer Instructions
 Transfer control to some predefined address or the
address somehow specified in the after their
execution.

 E.g INT, CALL, JMP and RET

4 Microcomputer and Interfacing


The addressing mode for sequential and control
flow instructions
Immediate addressing mode: immediate data is part of
instruction, appears in the form of successive byte.
 E.g MOV AX,0005H.
Direct Addressing Mode: a 16-bit memory address(offset)
directly specified in the instruction as part of it.
 E.g MOV AX,[5000H].
Register Addressing Mode: the data is stored in register and
it is referred using the particular register.
 E.g MOV BX, AX.
5 Microcomputer and Interfacing
Cont..
Register Indirect Addressing Mode: the memory location which contains
data or operands is determined in indirect way using the offset registers.

 E.g MOV AX, [BX].

Index Addressing Mode: offset of the operand is stored in one of the


index register

 E.g MOV AX, [SI].

Register Relative Addressing Mode: the data is available at an effective


address formed by adding an 8-bit or 16-bit displacement with the
content of any one of the register.

 E.g MOV AX,50H [BX].


6 Microcomputer and Interfacing
Cont..
Based indexed Addressing Mode: The effective address of data of
this addressing Mode is content of base register + content of an
index register.
 E.g MOV AX,[BX][SI].
Relative Based Indexed: The effective address of data formed by
adding 8-bit or 16-bit displacement to the sum content of base
register + content of an index register
 E.g MOV AX,50H[BX][SI].

7 Microcomputer and Interfacing


Cont..
 Basically, there are two addressing mode for the control
transfer instructions. These are;

• The location to which the


control is to be transferred
Intersegment lies in a different segment
other than the current one

• The destination location lies


in the same segment.
Intrasegment

8 Microcomputer and Interfacing


Cont..
 Addressing Modes for control Transfer Instructions:

Intersegment Intrasegment

Intersegment Intrasegment
Direct Direct

Intersegment Intrasegment
Indirect Indirect
9 Microcomputer and Interfacing
Cont..
Intersegment Direct:
 The address to which the transfer the control is to be
transferred is in a different segment.
 It provides a means for branching from one code
segment to another code segment.
 The CS and IP of the destination address are specified
directly in the instructions.
 Example: JMP 5000H, 2000H; Jump to effective address
2000H in segment 5000H
10 Microcomputer and Interfacing
Cont..
Intersegment Indirect:
 It is passed to the instruction indirectly.

 The starting address of the memory block may be


referred using any of the addressing modes, except
immediate mode.

 Example: JMP [2000H]; Jump to an address in the other


segment at effective address 2000H in DS.

11 Microcomputer and Interfacing


Cont..
Intrasegment Direct Mode:
 Destination location lies in the same segment appears
directly in the instructions as an immediate displacement
value.
 The displacement is computed relative to the content of
the instruction pointer.
 The effective address of the destination is given by the sum
of 8 or 16-bit displacement and current content of IP.
 Displacement is 8-bit (-128 <d<+128) it is as short
jump
 Displacement is of 16-bit (-32768<d<+32768) it is as
long jump
12 Microcomputer and Interfacing
Cont..
 Example: JMP SHORT LABEL

Intrasegment Indirect Mode:


 The displacement to which the control is to be transferred
is in the same segment in which the control transfer
instruction lies, but it is passed to the instruction directly.

 The branch address is found as the content of a register or


a memory location.

 Example: JMP [BX]; Jump to effective address stored in BX


13 Microcomputer and Interfacing
Instruction set of 8086
Classified into seven, they are:
 Data Transfer Instructions
 Arithmetic and Logical Instructions
 Program Control Transfer Instructions
 Machine Control Instructions
 Shift / rotate Instructions
 Flag Manipulation Instructions
 String Instructions
14 Microcomputer and Interfacing
Cont..
Data Transfer Instructions:-
 Transfer data from memory to internal register, from
internal register to memory, from one register to another
register, from input port to internal register, from internal
register to and output port.
MOV Instructions
 It is a general purpose instruction to transfer a byte or
word from register to register, memory to register, register
to memory.
15 Microcomputer and Interfacing
Cont..
 General form: MOV Destination, Source
 Here the source and destination needs to be the same size
that is both 8-bit or 16-bit

 MOV instruction does not affect any flags.

 Example:

 MOV BX, 00F2H; load the immediate number 00F2H in BX register

 MOV BX,[2000H]; Copy the 8 –bit content of the memory location, at a displacement
of 2000H from data segment base to CL register

16 Microcomputer and Interfacing


Cont..
PUSH instruction:
 Decrements the stack pointer by two and copies the word
from source to the location where the stack pointer now
points.
 The source must of word size data(i.e. general purpose
register, segment register or a memory location).
 It must pushes the most significant byte to sp-1, then least
significant to the sp-2.
 It does not affect any flags.
17 Microcomputer and Interfacing
Cont..

• Example: PUSH CX; Decrement SP by 2, copy the content of CX to the stack.

PUSH DS; Decrement SP by 2 and copy DS to stack.


18 Microcomputer and Interfacing
Cont..
POP instruction:
 It copies a word from the stack location pointed by the stack
pointer to the destination.
 The destination can be a general purpose register, segment
register or a memory location.
 The content copied the stack pointer is automatically
incremented by two.
 Execution pattern is similar to that of the PUSH instruction.
 Example: POP CX; Copy a word from the top of the stack to CX and increment
SP by two.
19 Microcomputer and Interfacing
Cont..
IN & OUT instructions:
 The IN instruction will copy data from port to the
accumulator.
 The OUT instruction is used to copy data from
accumulator to an output port.
 Both can be done using direct and indirect addressing
modes.
 Example : IN AL, 0F8H; Copy a byte from the port 0F8H to AL.
MOV DX, 30F8H; Copy port address in DX
IN AL, DX; move 8-bit data from 30F8H port
OUT 047H, AL; Copy contents of AL to 8-bit port 047H
20 Microcomputer and Interfacing
Cont..
XCGH instructions:
 It exchanges contents of the destination and source.
 Destination and source can be register and register
or register and memory location but, it cannot
interchange the value of two memory locations.
 General format: XCHG Destination, Source
 Example:
 XCHG BX, CX; exchange word in CX with the word in BX.
 XCHG AL,CL; exchange byte in CL with byte in AL.
21 Microcomputer and Interfacing
Arithmetic and Logic Instructions
ADD instructions:
 It is used to add the current contents of destination with that of
source and store the result in destination.
 AF, OF, CF, PF, SF and ZF flags are affected.
 General format: ADD Destination, Source
 Example:
 ADD AL, OFH; Add the immediate content, 0FH to the content of AL and the result
in AL.
 ADD AX, BX; AX<=AX+BX
 ADD AX, [5000H];
 ADD [5000H], 0100H;
22 Microcomputer and Interfacing
23 Microcomputer and Interfacing
Cont..
SUB instruction:
 It is used to subtract the current contents of destination with
that of source and store the result in destination.
 AF, OF, CF, PF, SF and ZF flags are affected.
 General format: SUB Destination, Source
 Example:
 SUB AL, OFH; Subtract the immediate content, 0FH to the content of AL and the
result in AL.
 SUB AX, BX; AX<=AX-BX
 SUB AX, [5000H];
 SUB [5000H], 0100H;

24 Microcomputer and Interfacing


25 Microcomputer and Interfacing
26 Microcomputer and Interfacing
.

27 Microcomputer and Interfacing


28 Microcomputer and Interfacing
29 Microcomputer and Interfacing
30 Microcomputer and Interfacing
31 Microcomputer and Interfacing
32 Microcomputer and Interfacing
Cont..
CMP: Compare
 The instruction compare the source operand(i.e. register
immediate data or memory location) with the destination
operand(i.e. register or memory location).
 It does not store the result anywhere, but affects the flags.
 If source operand = destination operand zero flag is set
Source operand > destination operand carry flag is set
Else carry flag is reset
 Example : CMP AX, 0100H;

33 Microcomputer and Interfacing


Cont..
INC & DEC instructions
 Are used to increment and decrement the contents
of the specified destination by one.
 AF, OF, CF, PF, SF and ZF flags are affected.
 Example:
 INC AL; AL<=AL+1
 INC AX; AX<=AX+1
 DEC AL; AL<=AL-1
 DEC AX; AX<=AX-1

34 Microcomputer and Interfacing


35 Microcomputer and Interfacing
36 Microcomputer and Interfacing
37 Microcomputer and Interfacing
38 Microcomputer and Interfacing
39 Microcomputer and Interfacing
40 Microcomputer and Interfacing
41 Microcomputer and Interfacing
42 Microcomputer and Interfacing
43 Microcomputer and Interfacing
44 Microcomputer and Interfacing
45 Microcomputer and Interfacing
46 Microcomputer and Interfacing
47 Microcomputer and Interfacing
48 Microcomputer and Interfacing
49 Microcomputer and Interfacing
50 Microcomputer and Interfacing
51 Microcomputer and Interfacing
52 Microcomputer and Interfacing
53 Microcomputer and Interfacing
54 Microcomputer and Interfacing
ASSEMBLER DIRECTIVES

 These are instruction to the assembler, linker and loader.


 Commonly used assembler directive in 8086 assembly language
programming are:
 ASSUME: Used to tell the name of the logical segment the
assembler to use for a specified segment.
e.g. ASSUME CS:CODE program are in logical segment named
CODE.
 DB: used to reserve byte of memory location in available location
e.g. RANKS DB 01H, 02H, 03H, 04H
55 Microcomputer and Interfacing
Cont..

 DW-Define Word: The assembler reserve the number of


memory words (16-bit)
e.g. WORDS DW 1234H, 4567H, 78ABH

 END-End of program: Marks the end of assembly


language.

 ENDP: End procedure: Indicate the end of a procedure


e.g. SQUARE_ROOT PROC: Start of procedure

SQUARE_ROOT ENDP: End of procedure

56 Microcomputer and Interfacing


The end

Thank You!

57 Microcomputer and Interfacing

You might also like