Module 2 (MPMC)
Module 2 (MPMC)
Module 2 (MPMC)
MICROCONTROLLERS
Chanthini Baskar
Assistant Professor Gr-2/SENSE
Mail id: [email protected]
Module – 2:
MICROPROCESSOR ARCHITECTURE
& INTERFACING : INTEL x86
Introduction to 8086
• Backward compatible with 8085
• Memory interfacing technique is similar, though
memory addressing is different
• 40-pin DIP, 5V supply
• 29,000 transistors
• 20 bit address to access memory
• (memory space = 220 = 1MB)
8086 Registers
• “General Purpose” & “Special Purpose”
• 16 bit registers
• GP Registers:
– Can be used as 8 bit or 16 bit
– Used for holding data, variables, and intermediate
results temporarily
• SP Registers:
– Used as segment registers, pointers, index registers or
as offset storage registers for some addressing modes
Register Groups
• General data registers
• Segment registers
• Pointers & index registers
• Flag registers
General Data Registers
• X, H, L ?
• AX - Accumulator
• CX – Default counter in string
and loop operations
• BX – Offset storage for forming
physical address
• DX – Implicit operand/
destination in few instructions
Segment Registers
• 8086 addresses segmented memory
• Total 1MB is divided into 16 logical
segments; each segment having 64KB
memory
• 4 segment registers
• CS – used for addressing a memory location
in the code segment of the memory
• DS – points to the data segment of the
memory
• ES – Another data segment used along with
DS
• SS – used to address stack segment,
memory to store stack data, main
operations are Push & Pop
Segment Registers
BIU
Contains circuit for phy add calculation
and a precoding instruction byte queue.
It makes the system’s bus signals
available for external interfacing of
devices
Condition Flags
Control Flags
Execution Unit (EU)
This flag is set, when the result This flag is set, if the result of the This flag is set to 1, if the lower byte of
of any computation is negative computation or comparison performed the result contains even number of 1’s ;
by an instruction is zero for odd number 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
Trap Flag
Over flow Flag If this flag is set, the processor enters
This flag is set, if an overflow occurs, i.e, if the result of a signed operation is
the single step execution mode by
large enough to accommodate in a destination register. The result is of more
than 7-bits in size in case of 8-bit signed operation and more than 15-bits in
generating internal interrupts after the
size in case of 16-bit sign operations, then the overflow will be set. execution of each instruction
• By specifying the name of the register as an operand to the instruction, you may
• This instruction copies the data from the source operand to the destination
operand.
• The eight and 16 bit registers are certainly valid operands for this instruction.
• The only restriction is that both operands must be the same size.
Basics of Addressing Mode
mov ax, bx ;Copies the value from BX into AX
• The content of the segment register is shifted left bit-wise four times (Multiply the
16-bit hex value by 10H).
• To this result, the content of an offset register is added, to produce 20-bit physical
address.
• Offset registers for the different segments are indicated below:
• BX/ SI/ DI – Data Segment
• IP – Code Segment
• BP/SP– Stack segment
• DI – Extra segment
Example
The value of Code Segment (CS) Register is 4042H and the value of
different offsets is as follows: BX: 2025H , IP: 0580H , DI: 4247H.
Calculate the effective address of the memory location pointed by
the CS register.
• The offset of the CS Register is the IP register.
• Shift base address 4-bits and Add offset address
= (469A0)H
Practice Problem
33360H
Practice Problem
• You are provided with the following values:
DS: 3056H, IP: 1023H, BP: 2322H and SP: 3029H.
Can you calculate the effective address of the memory location as per
the DS register?
Example
2.Arithmetic Instructions
3.Logical Instructions
SP decremented by 2
PPUSH − Put a word at
the top of the stack
PUSHA − Used to put
all the registers into
the stack
Pushing data to Stack Memory
Data Transfer/Copy Instructions
POP
This instruction loads the specified register/ memory location with the
contents of the memory location of which the address is formed by the SS
& SP.
• SP is incremented by 2, with each execution of the instruction.
• Sequence of operation:
1. Contents of stack top memory location is stored in AL & SP is
incremented by 1.
2. The contents of the memory location pointed now by SP is
copied to AH & SP is again incremented by 1.
POP
• Used to get a word from top of the stack
• POP AX
• POP DS
• POP [5000H]
SP incremented by 2
• INC
– Increase the content of specified register or memory
location by 1
– INC AX
– INC [BX]
– INC [5000H]
– Affect all condition code flags except carry flag (CF)
• DEC
– Subtract 1 from the contents of specified register or
memory location
– DEC AX
– DEC [BX]
– DEC[5000H]
SUB, SBB
• Subtract source from destination operand
• Result left in destination operand
• Source operand – Register, memory location or immediate
data
• Destination operand – Register/memory location
• Source and destination both must not be memory operands
• Destination cannot be an immediate data
• SUB AX, 0100H
• SUB AX, BX
• SUB AX, [5000H]
• SUB [5000H], 0100H
SBB
• Subtract the source operand and borrow flag
from the destination operand
• SBB AX, 0100H
• SBB AX, BX
• SBB AX, [5000H]
• SBB [5000H], 0100H
CMP
• Compares the source operand with destination operand
• Source operand
– Register/immediate data/memory location
• Destination operand
– Register/memory location
• Does not store the result anywhere
• Zero flag set – If both the operands are equal
• Carry flag is set – If the source operand > destination
operand
• Carry flag is reset - If the source operand < destination
operand
• CMP
DAA
• Decimal Adjust Accumulator
• Convert the result of the addition of two packed BCD
numbers to a valid BCD number
• The result has to be only in AL
• AL = 53 CL = 29
• ADD AL, CL ;
• AL (AL) + (CL) ;
• AL 53 + 29 ;
• AL 7C
• DAA ;
• AL 7C + 06 (as C>9) ;
• AL 82
DAA
DAS
• Decimal Adjust after Subtraction
• Converts the result of the subtraction of two packed BCD
numbers to a valid BCD number
• The subtraction has to be in AL only
• AL = 75, BH = 46
• SUB AL, BH ;
• AL (AL) - (BH) ;
• AL 2 F ;
• DAS ;
• AL 2 9 (as F>9, F - 6 = 9); CF = 1
Logical Instructions
• AND : Logical AND
• Bit by bit ANDs source operand to the destination operand
• Source operand – immediate, register or a memory location
• Destination operand a register or a memory location
• The result is stored in the destination operand
• AND AX, 0008H
• AND AX, BX
• AND AX, [5000H]
• AND [5000H], AX
Logical Instructions
• OR : Logical OR
– Bit by bit ORs the source operand to the destination
operand
– Result is stored in the destination operand
– OR AX, 0008H
– OR AX, BX
– OR AX, [5000H]
– OR [5000H], AX
REP
Used as a prefix to other instructions.
The instruction to which the prefix is provided, is
executed repeatedly
until the CX becomes zero.
When CX=0, the execution proceeds to next
instruction in sequence.
String Manipulation Instructions
MOVSB/MOVSW
Source string starting byte SI + DS
Destination string starting byte DI + ES.
Use REP as prefix to MOVS & length of the byte/ word string
in CX.
String Manipulation Instructions
CMPSB/CMPSW
Used to compare two strings of bytes or words.
Length of the byte/ word string in CX.
If both bytes/ words are equal, ZF is set.
Strings are stored in DS:SI & ES:DI
REP is used to repeat the comparison operation till CX=0 or
condition specified by REP fails.
CMPSB/CMPSW - Example
String Manipulation Instructions
Process Control & Branch
Transfer
Instructions
Branch Instructions
• Transfers the flow of execution of the program to a new
address specified in the instruction directly or indirectly
• CS and IP registers get loaded with new values of CS and IP
corresponding to the location to be transferred
MN/
MINIMUM / MAXIMUM
99
8086 Microprocessor Common signals
TEST
READY
RESET (Input)
101
8086 Microprocessor Common signals
CLK
102
8086 Microprocessor Common signals
103
MIN & MAX MODEL
Minimum mode signals
8086 Microprocessor Pins 24 -31
105
Minimum mode signals
8086 Microprocessor
Usually used by the DMA controller to get the control of the bus.
106
Maximum mode signals
8086 Microprocessor
During maximum mode operation, the MN/ is grounded
(logic low)
107
Maximum mode signals
8086 Microprocessor
During maximum mode operation, the MN/ is grounded
(logic low)
108
Maximum mode signals
8086 Microprocessor
During maximum mode operation, the MN/ is grounded
(logic low)
, (Bus Request/ Bus Grant) These requests are used by other local
bus masters to force the processor to release the local bus at the
end of the processor’s current bus cycle.
109
Peripheral Interfacing
• Microprocessor based system design involves interfacing of the
processor with one or more peripheral devices for the purpose of
communication with various input and output devices connected to it.
Control Logic
• Manage all internal and external transfer of data and control words.
• RD’, WR’, A1, A0 and RESET are inputs provided by MPU
• It issues commands to the individual group control blocks (Group A Control
and Group B Control)
Pin diagram -8255
Modes of Operation
• Bit Set-Reset Mode (BSR) – used to set or reset its
individual port bits.
CWR
Port Address
Steps to Communicate with 8255
ALP
ROL
• ROL Instruction : Rotate Left without Carry
• Rotates all bits in a specified byte or word to the left some
number of bit positions
– MSB is placed as a new LSB and a new CF
– ROL destination, count
– ROL CX, 1 MOV CL, 05H; ROL BL, CL
ALP
ALP
What is a Timer?
• OUT will be initially high. When the initial count expires, OUT will
go low for one CLK pulse and then go high again.
• Similar to Mode 2, except that the counter is not reloaded
automatically, count has to be reloaded.
Mode 5 – Hardware Triggered
• OUT will initially be high.
• Counting is triggered by a rising edge of GATE.
• When the initial count has expired, OUT will go low for one CLK
pulse and then go high again.
• After writing the Control Word and initial count, the counter will
not be loaded until the CLK pulse after a trigger.
Example 1
• Memory organization
– Each memory chip contains 2N memory locations, where
N is the no of address pin on the chip
Partial Decoding
• All the address lines are not used to generate chip select,
basically used in small systems
• Individual high order address lines are used to decode the
chip select for the memory chips using less hardware
• Disadvantages: Each memory location has more than one
address called roll-over addresses (fold back or shading)
DOS & BIOS Interrupt
EX:
MOV AH, 2
MOV DL, ‘A’
INT 21H
DOS Interrupt 21H
INT Function
• 5h Print Screen operation
• 10h Video display services
• 11h Equipment determination
• 12h Memory size determination
• 13h Diskette and hard disk services
• 14h Serial I/O services
• 15h Miscellaneous services
• 16h Keyboard services
• 17h Printer services
• 18h BASIC
• 19h Reboot
• 1Ah Real time clock services.
BIOS Interrupt
• The INT 10H BIOS of the 8086 are used to communicate with
the user through the screen.
• Input Parameter:
• AH = 00H
• AL = Mode Number