Presidency Univeristy,: School of Engineering Department of Computer Science & Engineering
Presidency Univeristy,: School of Engineering Department of Computer Science & Engineering
School of Engineering
IV Semester 2019-20
Microprocessor & Microcontrollers
Addressing Modes
&
Instruction Set
8086 Microprocessor Introduction
Program
A set of instructions written to solve a
problem.
Instruction
Directions which a microprocessor
follows to execute a task or part of a
task.
Computer language
4
Addressing Modes
8086 Microprocessor Addressing Modes
3. Direct Addressing
4. Register Indirect Addressing
5. Based Addressing Group II : Addressing modes for memory
6. Indexed Addressing data
7. Based Index Addressing
8. String Addressing
9. Direct I/O port Addressing Group III : Addressing modes for I/O
10. Indirect I/O port Addressing ports
8
Group I : Addressing modes for
8086 Microprocessor Addressing Modes register and immediate data
9
Group I : Addressing modes for
8086 Microprocessor Addressing Modes register and immediate data
10
8086 Microprocessor Addressing Modes: Memory Access
Adder
11
8086 Microprocessor Addressing Modes: Memory Access
12
8086 Microprocessor Addressing Modes: Memory Access
Supported combinations:
BX SI
+ disp
BP DI
13
Group II : Addressing modes
8086 Microprocessor Addressing Modes for memory data
14
Group II : Addressing modes
8086 Microprocessor Addressing Modes for memory data
15
Group II : Addressing modes
8086 Microprocessor Addressing Modes for memory data
7. Based Index Addressing When BP holds the base value of EA, BP and SS is
used.
8. String Addressing
Example:
9. Direct I/O port Addressing
MOV AX, [BX + 08H]
10. Indirect I/O port Addressing Operations:
0008H 08H (Sign extended)
11. Relative Addressing EA = (BX) + 0008H
12. Implied Addressing BA = (DS) x 1610
MA = BA + EA
(AX) (MA) or,
(AL) (MA)
(AH) (MA + 1)
16
Group II : Addressing modes
8086 Microprocessor Addressing Modes for memory data
17
Group II : Addressing modes
8086 Microprocessor Addressing Modes for memory data
18
Group II : Addressing modes
8086 Microprocessor Addressing Modes for memory data
19
Group III : Addressing modes
8086 Microprocessor Addressing Modes for I/O Ports
1. Register Addressing These addressing modes are used to access data from
standard I/O mapped devices or ports.
2. Immediate Addressing
In direct port addressing mode, an 8-bit port address
3. Direct Addressing is directly specified in the instruction.
20
Group IV : Relative Addressing
8086 Microprocessor Addressing Modes Mode
21
Group V : Implied Addressing
8086 Microprocessor Addressing Modes Mode
6. Indexed Addressing
8. String Addressing
22
INSTRUCTION SET
8086 Microprocessor Instruction Set
2. Arithmetic Instructions
3. Logical Instructions
24
8086 Microprocessor Instruction Set
25
8086 Microprocessor Addressing Modes 1. Data Transfer Instructions
26
8086 Microprocessor Addressing Modes 1. Data Transfer Instructions
28
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADD reg2/ mem, reg1/mem
ADD reg2, reg1 (reg2) (reg1) + (reg2)
ADD reg2, mem (reg2) (reg2) + (mem)
ADD mem, reg1 (mem) (mem)+(reg1)
ADD reg/mem, data
ADD reg, data (reg) (reg)+ data
ADD mem, data (mem) (mem)+data
ADD A, data
ADD AL, data8 (AL) (AL) + data8
ADD AX, data16 (AX) (AX) +data16
29
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADC reg2/ mem, reg1/mem
ADC reg2, reg1 (reg2) (reg1) + (reg2)+CF
ADC reg2, mem (reg2) (reg2) + (mem)+CF
ADC mem, reg1 (mem) (mem)+(reg1)+CF
ADC reg/mem, data
ADC reg, data (reg) (reg)+ data+CF
ADC mem, data (mem) (mem)+data+CF
ADC A, data
ADC AL, data8 (AL) (AL) + data8+CF
ADC AX, data16 (AX) (AX) +data16+CF
30
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SUB reg2/ mem, reg1/mem
SUB reg2, reg1 (reg2) (reg1) - (reg2)
SUB reg2, mem (reg2) (reg2) - (mem)
SUB mem, reg1 (mem) (mem) - (reg1)
SUB reg/mem, data
SUB reg, data (reg) (reg) - data
SUB mem, data (mem) (mem) - data
SUB A, data
SUB AL, data8 (AL) (AL) - data8
SUB AX, data16 (AX) (AX) - data16
31
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SBB reg2/ mem, reg1/mem
SBB reg2, reg1 (reg2) (reg1) - (reg2) - CF
SBB reg2, mem (reg2) (reg2) - (mem)- CF
SBB mem, reg1 (mem) (mem) - (reg1) –CF
SBB reg/mem, data
SBB reg, data (reg) (reg) – data - CF
SBB mem, data (mem) (mem) - data - CF
SBB A, data
SBB AL, data8 (AL) (AL) - data8 - CF
SBB AX, data16 (AX) (AX) - data16 - CF
32
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
INC reg/ mem
33
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
34
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
DIV reg/ mem
DIV reg For 16-bit :- 8-bit :
(AL) (AX) :- (reg8) Quotient
(AH) (AX) MOD(reg8) Remainder
For 32-bit :- 16-bit :
(AX) (DX)(AX) :- (reg16) Quotient
(DX) (DX)(AX) MOD(reg16) Remainder
DIV mem For 16-bit :- 8-bit :
(AL) (AX) :- (mem8) Quotient
(AH) (AX) MOD(mem8) Remainder
For 32-bit :- 16-bit :
(AX) (DX)(AX) :- (mem16) Quotient
(DX) (DX)(AX) MOD(mem16) Remainder
35
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
IDIV reg/ mem
IDIV reg For 16-bit :- 8-bit :
(AL) (AX) :- (reg8) Quotient
(AH) (AX) MOD(reg8) Remainder
For 32-bit :- 16-bit :
(AX) (DX)(AX) :- (reg16) Quotient
(DX) (DX)(AX) MOD(reg16) Remainder
IDIV mem For 16-bit :- 8-bit :
(AL) (AX) :- (mem8) Quotient
(AH) (AX) MOD(mem8) Remainder
For 32-bit :- 16-bit :
(AX) (DX)(AX) :- (mem16) Quotient
(DX) (DX)(AX) MOD(mem16) Remainder
36
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP reg2/mem, reg1/ mem
Modify flags (reg2) – (reg1)
If (reg2) > (reg1) then CF=0, ZF=0, SF=0
CMP reg2, reg1
If (reg2) < (reg1) then CF=1, ZF=0, SF=1
If (reg2) = (reg1) then CF=0, ZF=1, SF=0
Modify flags (reg2) – (mem)
CMP reg2, mem If (reg2) > (mem) then CF=0, ZF=0, SF=0
If (reg2) < (mem) then CF=1, ZF=0, SF=1
If (reg2) = (mem) then CF=0, ZF=1, SF=0
Modify flags (mem) – (reg1)
CMP mem, reg1 If (mem) > (reg1) then CF=0, ZF=0, SF=0
If (mem) < (reg1) then CF=1, ZF=0, SF=1
If (mem) = (reg1) then CF=0, ZF=1, SF=0
37
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP reg/mem, data
Modify flags (reg) – (data)
CMP mem, data If (mem) > data then CF=0, ZF=0, SF=0
38
8086 Microprocessor Addressing Modes 2. Arithmetic Instructions
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP A, data
Modify flags (AL) – data8
39
8086 Microprocessor Addressing Modes 3. Logical Instructions
2. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
AND A, data
AND AL, data8 (AL) (AL) – data8
2. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
OR A, data
OR AL, data8 (AL) (AL) – data8
41
8086 Microprocessor Addressing Modes 3. Logical Instructions
2. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
XOR A, data
XOR AL, data8 (AL) (AL) – data8
42
8086 Microprocessor Addressing Modes 3. Logical Instructions
2. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
TEST A, data
TEST AL, data8 Modify flags (AL) – data8
43
8086 Microprocessor Addressing Modes 3. Logical Instructions
2. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
SHR reg/mem
SHR reg, 2
SHR reg
SHR reg, CL
SHR mem, 2
SHR mem
SHR mem, CL
44
8086 Microprocessor Addressing Modes 3. Logical Instructions
2. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
SHL reg/mem or SAL reg/mem
SHL reg, 2 or SAL reg, 2
SHL reg or SAL reg
SHL reg, CL or SAL reg, CL
SHL mem, 2 or SAL mem, 2
SHR mem or SAL mem
SHL mem, CL or SAL mem, CL
45
8086 Microprocessor Addressing Modes 3. Logical Instructions
2. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
RCR reg/mem
RCR reg, 4
RCR reg
RCR reg, CL
RCR mem, 4
RCR mem
RCR mem, CL
46
8086 Microprocessor Addressing Modes 3. Logical Instructions
2. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, ROL …
ROL reg/mem
ROL reg, 1
ROL reg
ROL reg, CL
ROL mem, 1
ROL mem
ROL mem, CL
47
4. String Manipulation
8086 Microprocessor Addressing Modes Instructions
48
4. String Manipulation
8086 Microprocessor Addressing Modes Instructions
49
4. String Manipulation
8086 Microprocessor Addressing Modes Instructions
50
4. String Manipulation
8086 Microprocessor Addressing Modes Instructions
51
4. String Manipulation
8086 Microprocessor Addressing Modes Instructions
52
4. String Manipulation
8086 Microprocessor Addressing Modes Instructions
(AL) (MA)
LODSB
If DF = 0, then (SI) (SI) + 1
If DF = 1, then (SI) (SI) – 1
MA = (DS) x 1610 + (SI)
(AX) (MA ; MA + 1)
LODSW
If DF = 0, then (SI) (SI) + 2
If DF = 1, then (SI) (SI) – 2
53
4. String Manipulation
8086 Microprocessor Addressing Modes Instructions
(MAE) (AL)
STOSB
If DF = 0, then (DI) (DI) + 1
54
8086 Microprocessor Addressing Modes 5. Process Control Instructions
55
6. Control Transfer
8086 Microprocessor Addressing Modes Instructions
Mnemonics Explanation
56
6. Control Transfer
8086 Microprocessor Addressing Modes Instructions
• Checks flags
57
6. Control Transfer
8086 Microprocessor Addressing Modes Instructions
58
6. Control Transfer
8086 Microprocessor Addressing Modes Instructions
Mnemonics Explanation
JC disp8 Jump if CF = 1
JP disp8 Jump if PF = 1
JO disp8 Jump if OF = 1
JS disp8 Jump if SF = 1
59
Assembler Directives
8086 Microprocessor Assembler Directives
61
8086 Microprocessor Assembler Directives
DB Define Byte
DW Define a byte type (8-bit) variable
SEGMENT Reserves specific amount of memory locations
ENDS to each variable
ASSUME
Range : 00H – FFH for unsigned value;
ORG
00H – 7FH for positive value and 80H – FFH
END
EVEN for negative value
EQU General form : variable DB value/ values
PROC Example:
FAR
LIST DB 7FH, 42H, 35H
NEAR
ENDP Three consecutive memory locations are reserved for the
SHORT variable LIST and each data specified in the instruction
are stored as initial value in the reserved memory
MACRO location
ENDM
62
8086 Microprocessor Assembler Directives
DB Define Word
DW Define a word type (16-bit) variable
SEGMENT Reserves two consecutive memory locations to
ENDS each variable
ASSUME
Range : 0000H – FFFFH for unsigned value;
ORG
0000H – 7FFFH for positive value and 8000H
END
EVEN – FFFFH for negative value
EQU General form : variable DW value/ values
PROC Example:
FAR
NEAR ALIST DW 6512H, 0F251H, 0CDE2H
ENDP Six consecutive memory locations are reserved for the
SHORT variable ALIST and each 16-bit data specified in the
instruction is stored in two consecutive memory
MACRO location.
ENDM
63
8086 Microprocessor Assembler Directives
DB SEGMENT : Used to indicate the beginning of a
code/ data/ stack segment
DW
SEGMENT ENDS : Used to indicate the end of a code/ data/
ENDS stack segment
ASSUME General form:
ORG
Segnam SEGMENT
END
EVEN …
EQU …
… Program code
PROC … or
FAR … Data Defining Statements
…
NEAR
ENDP Segnam ENDS
SHORT
MACRO
ENDM User defined name of the
segment
64
8086 Microprocessor Assembler Directives
DB Informs the assembler the name of the program/
data segment that should be used for a specific
DW segment.
SEGMENT
ENDS General form:
ASSUME ASSUME segreg : segnam, .. , segreg : segnam
ORG
END User defined name of the
EVEN Segment Register
segment
EQU
Example:
PROC
FAR ASSUME CS: ACODE, Tells the compiler that the
NEAR DS:ADATA instructions of the program
ENDP are stored in the segment
ACODE and data are stored
SHORT in the segment ADATA
MACRO
ENDM
65
8086 Microprocessor Assembler Directives
DB ORG (Origin) is used to assign the starting address
(Effective address) for a program/ data segment
DW
END is used to terminate a program; statements after
SEGMENT END will be ignored
ENDS
EVEN : Informs the assembler to store program/ data
ASSUME segment starting from an even address
ORG
EQU (Equate) is used to attach a value to a variable
END
EVEN Examples:
EQU ORG 1000H Informs the assembler that the statements
following ORG 1000H should be stored in
PROC memory starting with effective address 1000 H
FAR
LOOP EQU 10FEH Value of variable LOOP is 10FEH
NEAR
ENDP _SDATA SEGMENT In this data segment, effective address of
ORG 1200H memory location assigned to A will be 1200 H
SHORT A DB 4CH and that of B will be 1202H and 1203H.
EVEN
MACRO B DW 1052H
ENDM _SDATA ENDS
66
8086 Microprocessor Assembler Directives
DB PROC Indicates the beginning of a procedure
SHORT
MACRO User defined name of the
ENDM procedure
67
8086 Microprocessor Assembler Directives
DB Examples:
DW ADD64 PROC
NEAR
SEGMENT The subroutine/ procedure named
…
ENDS ADD64 is declared as NEAR and so the
…
assembler will code the CALL and RET
ASSUME …
instructions involved in this procedure
ORG as near call and return
RET
END ADD64 ENDP
EVEN CONVERT PROC
EQU FAR The subroutine/ procedure named
… CONVERT is declared as FAR and so
PROC
… the assembler will code the CALL and
FAR … RET instructions involved in this
NEAR procedure as far call and return
ENDP RET
CONVERT ENDP
SHORT
MACRO
ENDM
68
8086 Microprocessor Assembler Directives
DB Reserves one memory location for 8-bit signed
displacement in jump instructions
DW
SEGMENT Example:
ENDS
ASSUME
ORG The directive will reserve one
JMP SHORT
memory location for 8-bit
END AHEAD
displacement named AHEAD
EVEN
EQU
PROC
FAR
NEAR
ENDP
SHORT
MACRO
ENDM
69
8086 Microprocessor Assembler Directives
DB MACRO Indicate the beginning of a macro
DW ENDM End of a macro
SEGMENT General form:
ENDS
ASSUME macroname MACRO[Arg1, Arg2 ...]
Program
ORG … statements in the
END … macro
EVEN …
EQU
macroname ENDM
PROC
FAR
NEAR
ENDP
User defined name of the
SHORT macro
MACRO
ENDM
70
Thank You