Ec8691 Unit I - PPT
Ec8691 Unit I - PPT
Ec8691 Unit I - PPT
MICROCONTROLLERS
U.Vinothkumar
Asst Prof
Dept of ECE
Dr.N.G.P.Institute of Technology
Coimbatore.
UNIT I - THE 8086 MICROPROCESSOR (9 Hrs)
Introduction to 8086 – Microprocessor architecture –
Addressing modes - Instruction set and
assembler directives – Assembly language
programming – Modular Programming - Linking and
Relocation - Stacks - Procedures – Macros – Interrupts
and interrupt service routines – Byte and
String Manipulation.
2
Architecture
8086 Microprocessor
Architecture
Segment
Registers
6
8086 Microprocessor
Architecture Bus Interface Unit (BIU)
7
8086 Microprocessor
Architecture Bus Interface Unit (BIU)
8
8086 Microprocessor
Architecture Bus Interface Unit (BIU)
9
8086 Microprocessor
Architecture Bus Interface Unit (BIU)
10
8086 Microprocessor
Architecture Bus Interface Unit (BIU)
11
8086 Microprocessor
Architecture Bus Interface Unit (BIU)
Instruction queue
A group of First-In-First-
Out (FIFO) in which up to
6 bytes of instruction
code are pre fetched
from the memory ahead
of time.
12
8086 Microprocessor
Architecture Execution Unit (EU)
EU decodes and
executes instructions.
A decoder in the EU
control system
translates instructions.
and
Some of the 16 bit registers can be
Index registers (Source used as two 8 bit registers as :
Index, Destination Index)
each of 16-bits AX can be used as AH and AL
BX can be used as BH and BL
CX can be used as CH and CL 13
DX can be used as DH and DL
8086 Microprocessor
Architecture Execution Unit (EU)
14
8086 Microprocessor
Architecture Execution Unit (EU)
15
8086 Microprocessor
Architecture Execution Unit (EU)
Example:
16
8086 Microprocessor
Architecture Execution Unit (EU)
17
8086 Microprocessor
Architecture Execution Unit (EU)
18
8086 Microprocessor
Architecture Execution Unit (EU)
19
8086 Microprocessor
Architecture Execution Unit (EU)
20
8086 Microprocessor
Architecture Execution Unit (EU)
Auxiliary Carry Flag
Carry Flag
Flag Register This is set, if there is a carry from the
This flag is set, when there is
lowest nibble, i.e, bit three during
addition, or borrow for the lowest a carry out of MSB in case of
nibble, i.e, bit three, during addition or a borrow in case
subtraction. of subtraction.
This flag is set, when the This flag is set, if the result of This flag is set to 1, if the lower
result of any computation the computation or comparison byte of the result contains even
is negative performed by an instruction is number of 1’s ; for odd number
zero of 1’s set to zero.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
Tarp Flag
Over flow Flag If this flag is set, the processor
This flag is set, if an overflow occurs, i.e, if the result of a signed enters the single step execution
operation is large enough to accommodate in a destination
mode by generating internal
register. The result is of more than 7-bits in size in case of 8-bit
signed operation and more than 15-bits in size in case of 16-bit interrupts after the execution of
sign operations, then the overflow will be set. each instruction
Direction Flag Interrupt Flag
This is used by string manipulation instructions. If this flag bit
is ‘0’, the string is processed beginning from the lowest Causes the 8086 to recognize
address to the highest address, i.e., auto incrementing mode. external mask interrupts; clearing IF
Otherwise, the string is processed from the highest address disables these interrupts.
towards the lowest address, i.e., auto incrementing mode. 21
8086 Microprocessor
Architecture
8086 registers
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
categorized
into 4 groups OF DF IF TF SF ZF AF PF CF
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
1. Register Addressing
Group I : Addressing modes for
2. Immediate Addressing register and immediate data
3. Direct Addressing
5. Based Addressing
Group II : Addressing modes for
6. Indexed Addressing memory data
7. Based Index Addressing
8. String Addressing
8. String Addressing
29
8086 Microprocessor Group I : Addressing modes for
Addressing Modes register and immediate data
1. Register Addressing
In immediate addressing mode, an 8-bit or 16-bit
2. Immediate Addressing data is specified as part of the instruction
3. Direct Addressing
Example:
4. Register Indirect Addressing
MOV DL, 08H
5. Based Addressing
The 8-bit data (08H) given in the instruction is
6. Indexed Addressing moved to DL
8. String Addressing
MOV AX, 0A9FH
9. Direct I/O port Addressing
The 16-bit data (0A9FH) given in the instruction is
10. Indirect I/O port Addressing
moved to AX register
11. Relative Addressing
(AX) 0A9FH
12. Implied Addressing
30
8086 Microprocessor
Addressing Modes : Memory Access
1. Register Addressing
2. Immediate Addressing
3. Direct Addressing
Here, the effective address of the memory
location at which the data operand is stored is
4. Register Indirect Addressing given in the instruction.
12. Implied Addressing This addressing mode is called direct because the
displacement of the operand from the segment
base is specified directly in the instruction.
34
8086 Microprocessor Group II : Addressing modes
Addressing Modes for memory data
(CL) (MA)
(CH) (MA +1)
35
8086 Microprocessor Group II : Addressing modes
Addressing Modes for memory data
(AL) (MA)
36
(AH) (MA + 1)
8086 Microprocessor Group II : Addressing modes
Addressing Modes for memory data
(CL) (MA)
(CH) (MA + 1)
37
8086 Microprocessor Group II : Addressing modes
Addressing Modes for memory data
38
8086 Microprocessor Group II : Addressing modes
Addressing Modes for memory data
1. Register Addressing
2. Immediate Addressing
1. Register Addressing
2. Immediate Addressing
3. Direct Addressing
5. Based Addressing
6. Indexed Addressing
Instructions using this mode have no operands.
The instruction itself will specify the data to be
7. Based Index Addressing
operated by the instruction.
8. String Addressing
Example: CLC
9. Direct I/O port Addressing
This clears the carry flag to zero.
10. Indirect I/O port Addressing
42
INSTRUCTION SET
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
3. Logical Instructions
44
8086 Microprocessor
Instruction Set
45
8086 Microprocessor
Instruction Set
46
8086 Microprocessor
Instruction Set
48
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADD A, data
49
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADD A, data
50
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SUB A, data
51
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SBB A, data
52
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
53
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
54
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
55
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
56
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
57
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
58
8086 Microprocessor
Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP A, data
59
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
60
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
61
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
62
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
63
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
64
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
65
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
66
8086 Microprocessor
Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
67
8086 Microprocessor
Instruction Set
68
8086 Microprocessor
Instruction Set
REP
69
8086 Microprocessor
Instruction Set
MOVS
(MAE) (MA)
70
8086 Microprocessor
Instruction Set
CMPS
71
8086 Microprocessor
Instruction Set
LODS
73
8086 Microprocessor
Instruction Set
STOS
74
8086 Microprocessor
Instruction Set
CLC Clear CF 0
NOP No operation
Mnemonics Explanation
CALL reg/ mem/ disp16 Call subroutine
76
8086 Microprocessor
Instruction Set
Checks flags
77
8086 Microprocessor
Instruction Set
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
79
8086 Microprocessor
Assembler Directives
Used to :
› specify the start and end of a program
› attach value to variables
› allocate storage locations to input/output data
› define start and end of segments, procedures, macros etc..
80
8086 Microprocessor
Assemble Directives
DB Define Byte
PROC
FAR Example:
NEAR LIST DB 7FH, 42H, 35H
ENDP
Three consecutive memory locations are reserved for
SHORT the variable LIST and each data specified in the
instruction are stored as initial value in the reserved
MACRO memory location
ENDM 81
8086 Microprocessor
Assemble Directives
DB Define Word
PROC
FAR Example:
NEAR ALIST DW 6512H, 0F251H, 0CDE2H
ENDP
Six consecutive memory locations are reserved for
SHORT the variable ALIST and each 16-bit data specified in
the instruction is stored in two consecutive memory
MACRO location.
ENDM 82
8086 Microprocessor
Assemble Directives
ORG
END Segnam SEGMENT
EVEN
…
EQU … Program code
… or
PROC … Data Defining Statements
…
FAR …
NEAR
ENDP Segnam ENDS
SHORT
ORG
User defined name of
END Segment Register
the segment
EVEN
EQU
Example:
PROC
FAR ASSUME CS: ACODE, DS:ADATA Informs the assembler that the
instruction for the program are in
NEAR the logical segment named as
ENDP ACODE and data items related to
the program are available in the
logical segment named as ADATA.
SHORT
MACRO
ENDM 84
8086 Microprocessor
Assemble Directives
ORG
Examples:
END
EVEN ORG 1000H Informs the assembler that the statements
EQU following ORG 1000H should be stored in
memory starting with effective address
1000H
PROC
FAR
LOOP EQU 10FEH Value of variable LOOP is 10FEH
NEAR
ENDP
SDATA SEGMENT In this data segment, effective address of
SHORT ORG 1200H memory location assigned to A will be 1200H
A DB 4CH and that of B will be 1202H and 1203H.
EVEN
MACRO B DW 1052H
ENDM SDATA ENDS 85
8086 Microprocessor
Assemble Directives
General form
ASSUME
ORG
procname PROC[NEAR/ FAR]
END
EVEN …
… Program statements of the
EQU procedure
…
DB
Examples:
DW
RET
ORG ADD64 ENDP
END
EVEN
EQU CONVERT PROC FAR The subroutine/ procedure named CONVERT
is declared as FAR and so the assembler will
… code the CALL and RET instructions involved
PROC … in this procedure as far call and return
ENDP …
FAR
RET
NEAR CONVERT ENDP
SHORT
MACRO
ENDM 87
8086 Microprocessor
Assemble Directives
PROC
ENDP
FAR
NEAR
SHORT
MACRO
ENDM 88
8086 Microprocessor
Assemble Directives
PROC
ENDP
FAR User defined name of
NEAR the macro
SHORT
MACRO
ENDM 89
MODULAR PROGRAMMING
90
MODULAR PROGRAMMING
91
MODULAR PROGRAMMING
92
STACKS
93
STACKS cont……
94
STACKS cont……
• In an 8086 processor, the content of the register can be stored in the
stack using the PUSH instruction and the stored information can be
retrieved back to the register using the POP instruction.
• The stack in an 8086 is called Last- In-First-Out (LIFO) stack, i.e., the
last stored information can be read first.
95
STACKS cont……
PUSH OPERATION:
96
STACKS cont……
POP OPERATION:
97
PROCEDURES
98
PROCEDURES cont…
5. The 8086 processor has two types of call instructions
Intrasegment call or near call (call within a segment)
Intersegment call or far call (call outside a segment)
99
PROCEDURES cont…
10. The near return instruction is used to terminate a procedure
stored in the same segment.
100
PROCEDURES cont…
At the end of procedure, RET instruction is encountered.
101
PROCEDURES cont…
At the end of procedure, RET instruction is encountered.
On executing the RET instruction, the top of stack (which is the
previous stored value) is popped to IP.
102
Reentrant Procedure:
Recursive Procedure:
103
Example: Program using procedures (Near Call)
ASSUME CS:CODE, DS:DATA, SS:STACK_SEG
DATA SEGMENT
NUM1 DB 50H
NUM2 DB 20H
ADD_RES DB ?
SUB_RES DB ?
DATA ENDS
STACK_SEG SEGMENT
DW 40 DUP(0) ; stack of 40 words, all initialized to zero
TOS LABEL WORD
STACK_SEG ENDS
CODE SEGMENT
START:
MOV AX, DATA ; initialize data segment
MOV DS, AX
MOV AX, STACK_SEG ; initialize stack segment
MOV SS, AX
MOV SP, OFFSET TOS ; initialize stack pointer to TOS
CALL ADDITION
CALL SUBTRACTION
MOV AH, 4CH
INT 21H
CODE ENDS
END START
104
MACROS
• When a group of instructions are to be used several times to
perform a same function in a program.
105
MACROS cont…
• In other words, the macro call is like shorthand expression which
tells the assembler, “ Every time you see a macro name in the
program, replace it with the group of instructions defined as
macro” .
• Actually the assembler generates machine codes for the group of
instructions defined as macro, whenever it is called in the
program.
• The process of replacing the macro with the instructions it
represent is called expanding the macro. Hence, macros are also
known as open subroutines because they get expanded at the
point of macro invocation.
106
Example: Addition of two 16-bit numbers using macro
ADDITION MACRO NO1, NO2, RESULT
MOV AX, NO1
MOV BX, NO2
ADD AX, BX
MOV RESULT, AX
ENDM
DATA SEGMENT
NUM1 DW 1000H
NUM2 DW 2000H
RES DW ?
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA ; initialize data segment
MOV DS, AX
ADDITION NUM1, NUM2, RES
MOV AH, 4CH
INT 21H
CODE ENDS
END START
107