MPMC U1 Ece
MPMC U1 Ece
AND
MICROCONTROLLER
1
S.KARTHICK, AP/ECE 2
8086
Microprocessor
S.KARTHICK., AP/ECE 3
Introduction to 8086 Microprocessor
Features:
1. Intel 8086 was launched in 1978.
2. It was the first 16-bit microprocessor.
3. It is available as 40-pin Dual-Inline-Package (DIP).
4 It requires +5 V power supply.
5. It consists of 29,000 transistors.
6. It operates in two modes Minimum and
Maximum.
7. 8086 has a 20 bit address bus can access up to
220 Memory locations (1 MB).
8. It provides fourteen 16 -bit registers.
9. It has multiplexed address and data bus
AD0- AD15 and A16 – A19.
S.KARTHICK., AP/ECE 4
8086
PIN DIAGRAM
S.KARTHICK., AP/ECE 5
Pin Description
1. AD15 ± AD0: ADDRESS DATA BUS - These lines constitute the time
multiplexed memory/IO address and data bus.
9. MN/MX ‾ :
• MINIMUM MODE - The 8086 processor works in a single
processor environment. All control signals for memory and I/O are
generated by the μp.
• MAXIMUM MODE - is designed to be used when a coprocessor
exists in the system. 8086 works in a multiprocessor environment.
Control signals for memory and I/O are generated by an external
BUS Controller
S.KARTHICK., AP/ECE 7
Pin Description
MINIMUM MODE:
3. LOCK ‾: Other system bus master will be prevented from gaining the
system bus
4. RQ‾/GT1‾: REQUEST/GRANT1 5. RQ‾/GT0‾: REQUEST/GRANT0
S.KARTHICK., AP/ECE 9
8086
ARCHITECTUR
E
S.KARTHICK., AP/ECE 10
8086 ARCHITECTURE
S.KARTHICK., AP/ECE 11
8086 Architecture
8086 has two blocks Bus Interfacing Unit (BIU) and Execution Unit
(EU).
S.KARTHICK., AP/ECE 12
BUS INTERFACE UNIT (BIU)
The function of BIU is to
Fetch the instruction or data from memory.
Write the data to memory.
Write the data to the port.
Read data from the port.
Instruction Queue:
1. To increase the execution speed, BIU fetches as many as six
instruction bytes
ahead to time from memory.
2. All six bytes are then held in FIFO 6 byte register called instruction
queue.
3. Then all bytes have to be given to EU one by one.
4. This pre fetching operation of BIU may be in parallel with execution
S.KARTHICK., AP/ECE 13
operation of EU, which improves the speed execution of the
EXECUTION UNIT (EU)
The functions of EU are
To tell BIU where to fetch the instructions or data from.
To decode the instructions.
To execute the instructions.
The EU contains the control circuitry to perform various internal
operations.
A decoder in EU decodes the instruction fetched memory to generate
different internal or external control signals required to perform the
operation.
EU has 16-bit ALU, which can perform arithmetic and logical
operations on 8-bit as well as 16-bit.
Both units operate asynchronously to give the 8086 an overlapping
instruction fetch and execution mechanism which is called as
S.KARTHICK., AP/ECE 14
Pipelining. This results in efficient use of the system bus and system
8086 REGISTERS
The 8086 microprocessor has a total of fourteen registers
that are accessible to the programmer. It is divided into four
groups.
They are:
S.KARTHICK., AP/ECE 15
General Purpose Registers of 8086
• It can be used as 8 bit registers individually or can be used as 16 bit
in pair.
1. AX Register: AX register is also known as accumulator register that
stores operands for arithmetic operations.
2. BX Register: This register is mainly used as a base register. It holds
the starting base location of a memory region within a data segment.
3. CX Register: It is defined as a counter. It is primarily used in loop
instruction to store loop counter.
4.DX Register: Data register is used to hold 16 bit data result
S.KARTHICK., AP/ECE 16
Index & Pointer Registers
S.KARTHICK., AP/ECE 17
Segment Register
• Segment register is used to hold the upper 16 bits of the starting
address for each of the segments.
• The four segment registers are:
1. Code segment (CS) : The CS register is used for addressing a
memory location in the Code Segment of the memory, where the
executable program is stored.
2. Data Segment (DS): The DS contains most data used by program.
Data are accessed in the Data Segment by an offset address or the
content of other register that holds the offset address.
3. Stack Segment (SS): SS defined the area of memory used for the
stack.
4. Extra Segment (ES): used to hold the starting address of Extra
segment. Extra segment is provided for programs that need to access a
second data segment. Segment registers cannot be used in arithmetic
S.KARTHICK., AP/ECE 18
operations.
Segment Register
S.KARTHICK., AP/ECE 19
Other Register
1. Instruction Pointer (IP) is a 16-bit register. This is a important
register which is used to control which instruction the CPU executes.
The IP or program counter, is used to store the memory location of the
next instruction to be executed.
S.KARTHICK., AP/ECE 21
Control Flags: There are three control flags
1. The Direction Flag (D): Affects the direction of moving data blocks by
such instructions as MOVS, CMPS and SCAS. The flag values are 0 = up and 1
= down and can be set/reset by the STD (set D) and CLD (clear D) instructions.
2. The Interrupt Flag (I): Dictates whether or not system interrupts can
occur. The flag values are 0 = disable interrupts or 1 = enable interrupts and
can be manipulated by the CLI (clear I) and STI (set I) instructions.
3. The Trap Flag (T): Determines whether or not the CPU is halted after the
execution of each instruction. When this flag is set (i.e. = 1), the programmer
can single step through his program to debug any errors. When this flag = 0
this feature is off. This flag can be set by the INT 3 instruction.
S.KARTHICK., AP/ECE 22
Programmers model of 8086
S.KARTHICK., AP/ECE 23
8086
ADDRESSING
MODES
S.KARTHICK., AP/ECE 24
Operand Types of 8086
The 8086 supports the following types of operand
1. Bytes (8-bit)
2. Words (16-bit)
3. Short integers (8-bit)
4. Integers (16-bit)
5. Double words (32-bit)
6. Long integers (32-bit)
7. Strings (Series of alphanumeric characters
defined by ASCII codes)
S.KARTHICK., AP/ECE 25
Operand Addressing
Addressing mode indicates a way of locating data or operands, We can
classify the addressing modes of 8086 into 6 groups:
S.KARTHICK., AP/ECE 26
ADDRESSING MODES of 8086
S.KARTHICK., AP/ECE 27
ADDRESSING MODES of 8086
3. Memory addressing mode
One of the operands is in memory
8086 must use
a segment register
a 16-bit offset (effective address)
By default, DS register is used for accessing data from memory
16-bit offset can be specified in many ways
Ex:
MOV AL, DS
MOV DS, DL
MOV AX, DS
cont…
S.KARTHICK., AP/ECE 29
ADDRESSING MODES of 8086
3. Memory addressing mode
2. Register Indirect or Indirect Addressing mode
• In this mode, the Effective Address is specified in either a pointer register (BX or
BP) or an index register (SI or DI).
Ex: MOV BX,[CX] ;DS=10000H CX=2000H
;Physical Address: 12000H=30 12001H=40
;BX=4030H BH=40H BL=30H
cont…
S.KARTHICK., AP/ECE 30
ADDRESSING MODES of 8086
3. Memory addressing mode
4. Register Relative Addressing mode
CH CL
CX
S.KARTHICK., AP/ECE 33
ADDRESSING MODES of 8086
4. Port addressing
Two I/O port addressing modes can be used
Direct (e.g. IN AL, 02H)
Indirect (e.g. IN AL, DXH)
5. Relative addressing
S.KARTHICK., AP/ECE 34
8086
ASSEMBLER
DIRECTIVES
S.KARTHICK., AP/ECE 35
Assembler Directives of 8086
Assembler is a program which converts assembly language to machine language.
Syntax errors, logical errors and other program errors are not found out by the
assembler.
For completing all these tasks the assembler needs some hints from the program,
these hints are given to the assembler using some predefined alphabetical strings
called “Assembler Directives”
1. ASSUME: The directive is used to inform the assembler the names of the logical
segment which are to be assigned to the different segments used in an assembly
language program
2. DB (Define Byte): It defines a byte type variable which occupies 1byte of memory
space.
S.KARTHICK., AP/ECE 36
Assembler Directives of 8086
3. DW (Define Word): It defines a word type variable which occupies 2bytes of
memory space.
4. DD (Define Double Word): It defines a double word type variable which occupies
4bytes of memory space.
5. DQ (Define Quad Word): It defines a quad word type variable which occupies
8bytes of memory space.
6. DT (Define Ten Bytes): It defines a variable which occupies 10bytes of memory
space.
7. END (End of Program): It informs assembler the end of program module.
8. ENDP (End Procedure): It informs assembler the end of procedure (subroutines)
9. ENDM (End Macro): It informs assembler the end of the macro. It used with the
directive MACRO to enclose macro instructions.
10. ENDS (End Segment): It informs assembler that it is the end of a segment.
S.KARTHICK., AP/ECE 37
Assembler Directives of 8086
11. EQU (Equate): It is used to give a name to certain value or symbol which is used
many times in an assembly language program to make programming easy.
12. EVEN (Align or Even memory address): It informs assembler to increment the
content of the location counter to the next memory address, if it is already no at
an even address.
13. EXTRN (External): It informs that the names, procedures and labels following this
directive have already been defined in some other program module.
14. GLOBAL: It can be used in place of public or external directive.
15. GROUP: It informs assembler to form a logical group of the segments named after
this directive.
16. INCLUDE (Include source code from file): It informs assembler to insert a block of
codes from a named file in to the current program module. It is convenient to keep
all data and macros in a file called header file or include file.
S.KARTHICK., AP/ECE 38
Assembler Directives of 8086
17. LABEL: In assembly language program, labels are used to give names to memory
addresses.
18. LENGTH: It is an operator to determine the no. of elements in a data item such as
an array or a string.
19. LOCAL: When certain variables, constants, procedures or labels are to be used in
only one program module, they are declared local using LOCAL directive
20. MACRO: A sequence of instructions to which a name is assigned. Same as
subroutines.
21. NAME: A large program module contain several program modules so specific
name can be given to each program module using NAME directive.
22. OFFSET: It is an operator to determine the offset of a variable or procedure with
respect to the base of the segment which contains the named variable or
procedure.
S.KARTHICK., AP/ECE 39
Assembler Directives of 8086
23. ORG (Originate): The ORG directive directs the assembler to set the location
counter at memory address specified after the directive.
24. PROC (Procedure): It indicate the start of a procedure. The type of the procedure
FAR or NEAR is to be specified after the directive.
NEAR is used to call a procedure which is within the program module and FAR is
used to call from some other program module.
25. PTR (Pointer): It indicates the type (BYTE, WORD or DW) of a variable or label.
26. PUBLIC: a large program usually consist of several program modules. The
variables, constants, procedures and labels defined in a program module may be
used in some other program module. So such items are to be declared public using
PUBLIC directive.
27. RECORD: It defines the bit pattern within a byte or word
28. SEG(Segment): It is an operator used before a variable, procedures and label
S.KARTHICK., AP/ECE 40
Assembler Directives of 8086
29. SEGMENT (Logical Segment): It indicates the beginning of a logical segment. The
SEGMENT and ENDS directives are used to enclose a logical segment containing
code or data.
30. SHORT: It is an operator. It informs assembler that only one byte for the
displacement is required to code a jump instruction.
31. SIZE: it is an operator to determine the number of bytes allocated to a data item.
It differs from the LENGTH operator as it determines the no. of elements in a data
item.
32. STRUCK or STRUC (Structure Declaration): It defines the beginning of a data
structure which is a collection of primary data types such as DB, DW, DD is
declared.
33. TYPE: It is an operator that determines the type of a variable. It actually
determines the no. of bytes allocated to the variable and substitutes the no. in
place ofAP/ECE
S.KARTHICK., the variable before which TYPE
41appears.
8086
INSTRUCTION
SET
S.KARTHICK., AP/ECE 42
8086 INSTRUCTION SET
It is classified into 7 Categories.
They are:
S.KARTHICK., AP/ECE 43
1.DATA TRANSFER INSTRUCTIONS
GENERAL PURPOSE BYTE OR WORD TRANSFER
INSTRUCTIONS
copies the value of SF, ZF, AF, PF, and CF, into bits of 7, 6, 4, 2, 0 respectively of
AH register.
SAHF instruction - Store AH Register into FLAGS
SAHF instruction transfers the bits 0-7 of AH of SF, ZF, AF, PF, and CF, into the
Flag register.
PUSHF Instruction - Push flag register on the stack
This instruction decrements the SP by 2 and copies the word in flag register
to the memory location pointed by SP.
POPF Instruction - Pop word from top of stack to flag – register.
S.KARTHICK., AP/ECE 46
2.ARITHMETIC INSTRUCTIONS
ADDITION INSTRUCTIONS
ADD Instruction - ADD destination, source
Example: ADD DX, BX
ADC Instruction - Add with carry
Example: ADC CL,BL
INC Instruction - Increment - INC destination
Example: INC BL
AAA Instruction - ASCII Adjust after Addition
We can add two ASCII numbers directly and use AAA after addition
so as to get result directly in BCD. (Works with AL only)
DAA Instruction - Decimal Adjust Accumulator
S.KARTHICK., AP/ECE 47
2.ARITHMETIC INSTRUCTIONS
SUBTRACTION INSTRUCTION
SUB Instruction - Subtract two numbers
Example: SUB CX, BX
SBB Instruction - Subtract with borrow SBB destination, source
Example: SBB CX, BX
DEC Instruction - Decrement destination register or memory.
NEG Instruction - Form 2’s complement – Syntax: NEG destination
CMP Instruction - Compare byte or word and sets the flag
Syntax: CMP destination, source.
AAS Instruction - ASCII Adjust for Subtraction
DAS Instruction - Decimal Adjust after Subtraction
S.KARTHICK., AP/ECE 48
2.ARITHMETIC INSTRUCTIONS
MULTIPLICATION INSTRUCTION
MUL Instruction - Multiply unsigned bytes or words
Syntax: MUL source Example: MUL BL
IMUL Instruction - Multiply signed number
Syntax: IMUL source Example: IMUL BH
AAM Instruction - ASCII adjust after Multiplication
DIVISION INSTRUCTION
DIV Instruction - Unsigned divide Syntax: DIV source
Example: DIV BH ; AX / BH
; AX =Quotient & AH =Remainder.
IDIV Instruction - Divide by signed byte or word Syntax: IDIV source
Example: IDIV BL ; Signed word in AX is divided by signed byte in BL
AAD Instruction - ASCII adjust before Division
CBW Instruction - Convert signed Byte to signed word
CWD Instruction - Convert Signed Word to Signed Double word
S.KARTHICK., AP/ECE ( CBW and
49 CWD works only with AL,AX and DX registers.)
3.LOGICAL INSTRUCTIONS
LOGICAL INSTRUCTION
NOT Instruction - Invert each bit of operand
Ex: NOT BX ; Complement contents of BX register.
AND Instruction - AND corresponding bits of two operands
Ex: AND BH, CL ; AND byte in CL with byte in BH ;result in BH
OR Instruction - Logically OR corresponding of two operands
Ex: OR AH, CL ; CL is OR’ed with AH, result in AH.
XOR Instruction - Exclusive XOR destination, source
Ex: XOR BX, CX ; Exclusive OR CX with BX and Result BX
TEST Instruction – AND operand to update flags
Ex: TEST AL, BH ; AND BH with AL. no result is stored .
S.KARTHICK., AP/ECE Update 50
PF, SF, ZF
3.LOGICAL INSTRUCTIONS
SHIFT INSTRUCTION
SAL/SHL Instruction - Shift operand bits left, put zero in LSB(s)
Ex: ; CF = 0, BX = 11100101 11010011
SAL BX, 1 ; Shift BX contents by 1 bit position towards left
; CF = 1, BX = 11001011 10100110
SHR Instruction - Shift operand bits right, put zero in MSB
Ex: ; SI = 10010011 10101101 , CF = 0
SHR SI, 1 ; Result: SI = 01001001 11010110 and CF = 1
SAR Instruction - Shift operand bits right, new MSB = old MSB
Ex: ; AL = 00011101 = +29 decimal, CF = 0
SAR AL, 1 ; Shift signed byte in AL towards right
; AL = 00001110 = +14 decimal, CF = 1
S.KARTHICK., AP/ECE 51
3.LOGICAL INSTRUCTIONS
ROTATE INSTRUCTION
ROL Instruction - Rotate all bits of operand left, MSB to LSB
Ex: ;CF =0, BX = 10111011 01110101
ROL BX, 1 ;Result: CF =1, BX = 01110110 11101011
ROR Instruction - Rotate all bits of operand right, LSB to MSB
Ex: ;CF =0, BX = 00111011 01110101
ROR BX, 1 ;Result: CF =1, BX = 10011101 10111010
RCL Instruction - Rotate operand around to the left through CF
Ex: ;CF=0, BH = 10110011
RCL BH, 1 ;Result : BH =01100110, CF = 1
RCR Instruction - Rotate operand around to the right through CF
Ex: ;CF = 1, BL = 00111000
RCR BL, 1 ;Result: BL = 10011100, CF =0
S.KARTHICK., AP/ECE 52
4.CONTROL INSTRUCTIONS
S.KARTHICK., AP/ECE 53
4.CONTROL INSTRUCTIONS
CONDITIONAL TRANSFER INSTRUCTIONS
JA/JNBE - Jump if above/Jump if not below or not equal
JAE/JNB - jump if above or equal/Jump if not below
JB/JNAE - jump if below/jump if not above or not equal
JBE/JNA - jump if below or equal/jump if not above
JC – jump if carry
JE/JZ – jump if equal/jump if zero
JG/JNLE – jump if greater/jump if not less or not equal
JGE/JNL - jump if greater or equal/jump if not less than
JL/JNGE- jump if less/jump if not greater or not equal
Cont…
S.KARTHICK., AP/ECE 54
4.CONTROL INSTRUCTIONS
Cont…
loaded in CX register
LOOPE/LOOPZ – decresae CX, jump to label if CX equal/decresae CX,
jump to label if CX not zero.
LOOPNE/LOOPNZ - decresae CX, jump to label if CX not
equal/decresae CX, jump to label if CX not zero.
JCXZ – jump if CX is zero.
S.KARTHICK., AP/ECE 56
5.PROCESSOR CONTROL INSTRUCTIONS
These instructions are used to change the process of the Microprocessor.
CMC - complement carry flag ESC - When 8086 fetches an ESC instruction,
STD - set direction flag the coprocessor decodes the instruction and
carries out the action specified by the 6 bit
CLD - clear direction flag
code. In case of 8086 it treats ESC instruction
STI - set interrupt enable flag
as an NOP. The coprocessor treats all of the
CLI- clear interrupt enable
8086 instruction as an NOP except ESC.
flag LOCK - bus lock signal
NOP - no operation
S.KARTHICK., AP/ECE 57
6.STRING CONTROL INSTRUCTIONS
• The string instructions function easily on blocks of memory. help for easy
program writing and execution. They can speed up the manipulating code.
S.KARTHICK., AP/ECE 59
ASSEMBLY
LANGUAGE
PROGRAMMIN
G
S.KARTHICK., AP/ECE 60
PROCEDURES
&
MACROS
S.KARTHICK., AP/ECE 61
PROCEDURES
S.KARTHICK., AP/ECE 62
PROCEDURES
Multiple Call
Nested Call
S.KARTHICK., AP/ECE 63
MACROS
MACRO is a group of instructions given with a name
Each time we call the macro in our program, the assembler will
insert the defined group of instructions in place of the call
Macro call is like a short hand expression which tells the
assembler “every time you see a macro name in the program,
replace it with the group of instructions defined as that macro at
the start of the program”
Using a macro reduces the time involved in calling and returning
from a procedure
More memory taken is the disadvantage
S.KARTHICK., AP/ECE 64
COMPARISION OF PROCEDURE
&MACROS
PROCEDURE
Accessed by CALL and RET mechanism during program execution
Machine code for instruction put in memory only once
Parameters passed in register memory location or stack
Length of machine code is less
It does a specific task and return value
MACROS
Accessed during assembly with the name given to MACRO when
defined
Machine code generated for instruction each time called
Parameters passed as part of statement which calls macro
Length of the machine code is more
It just substitute the group of statements and does not return
S.KARTHICK., AP/ECE 65
value
INTERRUPTS & ISR
S.KARTHICK., AP/ECE 66
S.KARTHICK., AP/ECE 67