Microprocessors
Microprocessors
2
Contents
Chapter 1 Introduction to Microprocessors & Microcontroller 05 - 16
Chapter 2 The 8085 Microprocessors 17 - 28
Chapter 3 8085 Interrupts 29 - 37
Chapter 4 Instruction Set of Microprocessors 8085 39 - 76
Chapter 5 8085-Timing Diagrams 77 - 101
Chapter 6 Memory and I/O Interfacing 103 - 110
Chapter 7 DMA (Direct Memory Access 111 - 122
Chapter 8 8086 Microprocessor 123 - 136
3
4
Introduction to Microprocessors & Microcontroller
Chapter 1
Introduction to Microprocessors
& Microcontroller
Objective
Upon completion of this chapter, you will be able to:
• Understand the basics of Microprocessors & Microcontrollers
• Understand Microprocessors and their architecture and operation
• Types of Microcontrollers
• Operations Performed by Microprocessors
Introduction
Microprocessor is regarded as one of the most important devices in our everyday
machines called computers. It is an electronic circuit that functions as the central
processing unit (CPU) of a computer, providing computational control. It is also used in
other advanced electronic systems, such as computer systems, printers.
A Microprocessor incorporates arithmetic and logic functional units as well as the
associate control logic, instruction processing circuitry and a portion of the memory
hierarchy. It is a semiconductor component designed by using VLSI technology and
includes ALU, CU (control unit), and the resistor of the CPU in a single package.
Computer
CPU (MP)
ALU
I/P O/P
CU
Devices Devices
Resgister
Memory
5
Introduction to Microprocessors & Microcontroller
Note:
• For a microprocessor, memory is connected externally
• Busicom (Japan) is the first company to design a calculator by using discrete ALU,
CU and memory
• After Busicom, Intel designed a microprocessor in a single package
• 1st microprocessor, 1971 → Intel 4004 → 4-bit
• Bit → Binary digit (0 or 1)
• Nibble → 4-bit
• Byte → 8-bits
• Word length → Depends on type of processor
Microcontroller
A microcontroller is an integrated chip that is often part of an embedded system.
The microcontroller includes a CPU, ROM, RAM, I/O ports, and a Timer like a standard
computer but because these are designed to execute only a single specific task to
control a single system, they are much smaller and simplified so that they can include all
the functions required on a single chip. Microcontrollers are sometimes called embedded
microcontrollers, which just means that they are part of an embedded system that is one
part of a larger device or system. Microcontrollers have become common in various areas
and are found in home appliances, computer equipment and instrumentations. These are
most used in automobiles and have become a central part of industrial Robotics.
Micro-Controller
ALU
Timer/
CU Memory
Counter
Resgister
Interfacing
Circuits
6
Introduction to Microprocessors & Microcontroller
Microcontrollers
Family
Types of microcontrollers
Signetics: 87c552
7
Introduction to Microprocessors & Microcontroller
ALU
Control Unit
ALU
Input Output Instruction Control Data Memory
CPU Memory Unit
Memory Unit
I/O
Applications of Microcontrollers
Microcontrollers can be used to complete any task by interfacing sensors, actuators,
motors & appliances, etc. They are used in embedded systems-based applications
to control a specific task automatically. Following are some of the applications of
microcontrollers;
• Smart phones & handheld mobile devices
• Automobiles
8
Introduction to Microprocessors & Microcontroller
• Cameras
• Appliances
• Fire detection, security alarms & safety devices (including temperature & smoke
sensing)
• Electronic Measurements Instruments
• Domestic appliances such as microwave oven, alarm clock, washing machines, air
conditioners
• Industrial automation (conveyor belts, sorting, pick & place bots, etc.)
• Industrial Instrumentation & measurement devices such as volt & current meter,
object detection, inspection & sorting devices
• Communication devices
Embedded System
“Embedded Systems are devices which are used to control, monitor or assist the
operation of an equipment, machinery or plant”. The term “control” defines the main
function of an Embedded System because its purpose is to control an aspect of a
physical system such as pressure, temperature and so on. Also, the term “monitor”
defines the progress of activities. Where do we use Embedded Systems? Due to the
several examples listed earlier, these systems are extremely common in the home,
vehicles and in the workplace.
At Home: Washing machines, dishwashers, ovens, central heating system, burglar alarms,
etc.
In Motor Vehicles: Engine management, security (locking or anti-theft devices), air
conditioning, brakes, radio, etc.
In Industry and Commerce: Machine control, factory automation, robotics, electronic
commerce office equipment.
Embedded system
Software
Application Embedded OS
Input Output
Hardware
Embedded Peripheral
microprocessor device
9
Introduction to Microprocessors & Microcontroller
Microprocessor Microcontroller
Application Application
E.g.: Intel 8085, 8086, M6800, Z80, i3, i7 E.g.: Intel 8051, 8031, PIC-8 bit/ 16 bit
Microprocessor Architecture
Figure (1) and Figure (2) show the block diagram and programmers model of a
microprocessor. The microprocessor’s block diagram and the microprocessor
programming model show you how a specific microprocessor is constructed. The block
diagram shows the microprocessor’s functions for data processing and data handling. It
also shows how each of these logic functions are connected together. The programming
model assists you in the programming process. The difference is that the programming
model shows only those parts of the microprocessor which the programmer can change.
So we can say that the block diagram makes it easier to understand the architecture
of the microprocessor and the programming model makes it easier to understand the
working of the microprocessor in a programming environment.
8-bit
internal
data bus
Status Instruction
Temp
register register
Register
IN
A OUT file
L
U SP
IN Instruction
detector PC
Memory
Control Logic address
register
16-bit
Address
External input and output control lines Bus
10
Introduction to Microprocessors & Microcontroller
B7 B0 B7 B0
Reg B. Reg C.
Reg D. Reg E.
Reg H. Reg L.
Stack Pointer(SP)
Program Counter(PC)
B15 B0
Programmer's model / Register file
The block diagram shown in Fig. 1 includes three major logic devices.
• ALU
• Several registers / register file
• Control unit
The internal data bus is used to transmit data between these logic devices.
ALU
ALU (Arithmetic and Logic Unit) performs arithmetic and logic operations such as ADD,
SUBTRACT, AND, OR, NOT, etc.
Registers
Registers are a prominent part of the block diagram and the programming model of
any microprocessor. Basic registers found in most of the microprocessors are the
accumulator, the program counter, the stack pointer, the status register, the general
purpose registers, the memory address register, the instruction register and the
temporary data registers.
The Accumulator
The accumulator is the major working register of a microprocessor. Most of the time it
is used to hold the data for manipulation. Whenever the operation processes two words,
whether arithmetically or logically, the accumulator contains one of the words. The other
word may be present in another register or in a memory location. Most of the times the
result of an arithmetic or logical operation is placed in the accumulator. In such cases,
after execution of the instruction, the original contents of the accumulator are lost
because they are overwritten.
The accumulator is also used for data transfer between an I/O port and a memory
location, or between one memory location and another.
11
Introduction to Microprocessors & Microcontroller
Part of the
Subroutine call program to
be repeated
The program counter does the most in subroutine execution as it can be loaded with
the required memory address. With the help of instructions, it is possible to load any
memory address in the program counter. When the subroutine is to be executed, the
program counter is loaded with the memory address of the first instruction in the
subroutine. After execution of the subroutine, the program counter is loaded with the
memory address of the next instruction from where the program control was transferred
to the subroutine program.
12
Introduction to Microprocessors & Microcontroller
27FB E SP
27FC D
27FD C
27FE B
27FF A
Stack operation
It is important to note that as you go on storing (pushing) data on the stack, the stack
pointer always points the last data placed on the stack and when you try to remove
(pop) data you always get the last data placed on the stack. This kind of stack operation
is called LIFO (Last In First Out) operation.
13
Introduction to Microprocessors & Microcontroller
Control Logic
The control logic is an important block in the microprocessor. The control logic is
responsible for the working of all other parts of the microprocessor together. It
maintains synchronization in the operation of different parts in the microprocessor. The
synchronization is achieved with the help of one of the control logic’s major external
inputs which is the microprocessor’s clock. The clock is a signal which is the basis of all
the timings inside the microprocessor.
Usually, the microprocessor’s control logic is micro programmed. This means that the
architecture of the control logic itself is much like the architecture of a very special
purpose microprocessor.
The control logic receives the signal from the instruction decoder which decodes the
instruction stored in the instruction register. The control logic then generates the control
signals necessary to carry out this instruction. The control logic does a few other special
functions. It looks after the microprocessor power-up sequence. It also processes
interrupts. An interrupt is like a request to the microprocessor from other external
devices such as the memory and I/O. The interrupt asks the microprocessor to execute a
special program.
14
Introduction to Microprocessors & Microcontroller
Internal Operations
The microprocessor has to perform various internal operations to process data. These
operations are:
(1) Decode the instruction and generate appropriate control signals for the execution
of the instruction
(2) Perform arithmetic and logical operations
(3) Execute the instructions in sequence by properly updating the contents of the
program counter
(4) Update and store the status information in the form of flags after execution of
specific instructions
(5) Manipulate the stack pointer for the implementation of stack memory
(6) During arithmetic or logical operation, loading of second operand in the TEMP
register
Program
& Program Data
Data
• Program & data both are present • Program and data are separately
in same memory present in different memory
• E.g.: Intel 8085, Intel 8086 (MP) • E.g.: Intel 8051 (MC)
15
Introduction to Microprocessors & Microcontroller
Depending on the Program and Data Storage Technique, Two Techniques are Used
(1) Von-Neumann Architecture (Princeton Architecture)
(2) Harvard Architecture
16
The 8085 Microprocessors
Chapter 2
The 8085 Microprocessors
Objective
Upon completion of this chapter you will be able to:
• Understand the features of 8085 Microprocessors
• Architecture of 8085
• Functional description of 8085 PIN Diagram
Introduction
The 8085 microprocessor is an 8-bit microprocessor suitable for a wide range of
applications. It is a single-chip, NMOS device implemented with approximately 6200
transistors on a 164 × 222 mil chip contained in a 40-pin dual-in-line package.
17
The 8085 Microprocessors
(9) It provides five hardware interrupts: TRAP, RST 7.5, RST 6.5, RST 5.5 and INTR
(10) It has a serial I/O which allows serial communication
(11) The external hardware (another microprocessor or equivalent master) can detect
which machine cycle the microprocessor is executing using status signals
(IO/ M , S0, S1). This feature is very useful when more than one processor is using
common system resources (memory and I/O devices)
Architecture of 8085
It consists of various functional blocks as listed below:
• Registers
• Arithmetic and Logic Unit
• Instruction decoder and machine cycle encoder
• Address buffer
D (8) E (8)
Instruction
Decoder H (8) L (8)
ALU and Stack pointer
Machine 16
cycle Program counter
Encoder 16
Increment/Decrement
Address Latch
Crystal oscillator
X1 Timing & Control
Status DNA Add.Buffer Add/Data
X2
Ready ALE RD WR IO/M S1 S0 Hold HLDA Reset in Reset out Clock out A15 − A8 AD7 − AD0
Architecture of 8085
18
The 8085 Microprocessors
Register
The 8085 microprocessor includes six registers, one accumulator, and one flag register,
as shown in the Figure. In addition, it has two 16-bit registers: the stack pointer and the
program counter.
There are two types of registers.
(a) General purpose resistor
(b) Special purpose resistor
Example: MOV C, M
Here ‘M’ indicates memory contained or resistor whose address is present in HL pair
only.
Accumulator (A)
The accumulator is an 8-bit register that is a part of an arithmetic/logic unit (ALU). This
register is used to store 8-bit data and to perform arithmetic and logical operations. The
result of an operation is stored in the accumulator. The accumulator is also identified as
register A.
19
The 8085 Microprocessors
The function of the program counter is to point to the memory address from which
the next byte is to be fetched or the program counter contains the address of the next
instruction to be executed. When a byte (machine code) is being fetched, the program
counter is incremented by one to point to the next memory location.
Example: MOV A ,B
Op-Code Fetch
MP
Memory
8000H
XX
8001H
44
IR
XX
PC
8000
8001
20
The 8085 Microprocessors
Note:
• When data is stored or pushed into stack memory, stack pointer is decremented
• When data is accessed from stack memory stack pointer is incremented
• A single register data cannot be stored in stack memory
Example: Describe the output of the following code using graphical representation if the
stacks pointer points to F008H
LXI D, 5566 H
PUSH D
MP Memory
0000H
LIFO
SP-2 = F006H 66
SP-1 = F007H 55
SP
w w = write
F008 SP = F008H 44
F007
F009H 33 D E
F006
. . 55 66
. .
. .
FFFFH
Flag Register
It is an 8-bit register. There are 5 flags which are set or reset after an operation
according to the data conditions of the result in the accumulator and other registers.
They are called Zero (Z), Carry (CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags. The
most commonly used flags are Zero, Carry, and Sign. The microprocessor uses these
flags to test data conditions.
As the result is stored in the accumulator, for most of the ALU operations, flags are
affected by the content of the accumulator except for a few instructions.
21
The 8085 Microprocessors
Sign Flag
After execution of any arithmetic and logical operation, if D7 of the result is 1, the sign
flag is set. Otherwise it is reset. D7 is reserved for indicating the sign; the remaining is
the magnitude of the number. If D7 is 1, the number will be viewed as a negative number.
If D7 is 0, the number will be viewed as a positive number.
Zero Flag
If the result of an arithmetic and logical operation is zero, then the zero flag is set
otherwise it is reset. It may also be effected for other general purpose registers in the
same instruction.
Auxiliary Flag
If D3 generates any carry when doing any arithmetic and logical operation, this flag is set.
Otherwise it is reset.
Parity Flag
If the result of an arithmetic and logical operation contains an even number of 1’s then
this flag will be set and if it is an odd number of 1’s it will be reset.
Carry Flag
If any arithmetic and logical operation results in any carry then carry flag is set otherwise
it is reset.
D7 D6 D5 D4 D3 D2 D1 D0
S Z X AC X P X CY
22
The 8085 Microprocessors
Solved Examples
Problem: A = 15H, B = BEH, then find A + B = ? and also find the flags.
Solution:
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 1 0 1 0 1
1 0 1 1 1 1 1 0
0 1 1 0 1 0 0 1 1
CY
S Z X AC X P X CY
1 0 0 1 0 0 0 0
9 0
A + B = E3H
Solution:
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 1 1 1
0 1 1 1 1 0 0 1
1 0 0 0 0 0 0 0 0
CY
S Z X AC X P X CY
0 1 0 1 0 1 0 1
5 5
Note: Here only Zero flag, auxiliary carry flag, carry flag and parity flag is affected.
23
The 8085 Microprocessors
Temporary Register
W, Z are the two 8-bit registers which are not accessible by the user. They are used by
the processor in some instructions.
Notes: There are no separate instructions for multiplication and division in 8085
Micro-Programs
It is a program written by the manufacturer to make the processor understand what an
instruction is or it indicates the type of operations to be performed for an instruction.
Example: MOV B, C
X1 & X2
• A crystal oscillator is connected between X1 & X2 pin to produce the necessary and
suitable clock frequency for the processor
• A crystal is used as it produces stable oscillation compared to RC and LC oscillator
• An internal clock generator take the reference frequency and produces operating
frequency which is half of the reference frequency and also other frequencies which
are required internally
fcrystal
• Operating frequency fclock =
2
24
The 8085 Microprocessors
0; Memory operation
IO / M =
1; IO operation
1 0 1 IO/ R IO read
1 1 0 IO/ W IO write
25
The 8085 Microprocessors
S1 S0 Status
0 0 Halt
0 1 Memory write
1 0 Memory read
1 1 Opcode fetch
• HOLD
This indicates if any other device is requesting the use of the address and the data
bus. Then the microprocessor transfers the control to the requesting device as soon
as the current cycle is over. After the process of the requesting device is over, the
control is transferred back to the microprocessor.
• HLDA
HLDA is the acknowledgment signal for HOLD. It indicates whether the HOLD signal is
received or not. After the execution of HOLD request, HLDA goes low.
5 DMA operation
2
MP HOLD DMA
Controller
HLDA
3
4 1
HOLD
I/O
Regular path
When more or huge data is to be transferred between memory and I/O at a faster rate,
the DMA operation is used with the help of the DMA controller.
• Reset-in
Low active I/P signal to reset the processor and PC is initialized to 0000H
26
The 8085 Microprocessors
• Reset-out
Output signal which indicates that the processor is reset. It can be used to reset
IO devices.
• Clock-out
• O/P pin on which the same operating frequency of the processor is available. It
can be used to connect to the IO device for synchronizing operations
• Ready
I/P pin to processor from a slow speed IO device. If ready is high, only then will the
processor either transmit data or receive data from IO device.
• SID
I/P pin through which processor receives serial data.
• SOD
O/P pin by which processor transmit serial data.
MAR
Memory address register is used to hold the address before it is placed on the address
bus.
MDR
Memory data register is used to hold the data before it is transferred to memory or when
it is accessed from memory by the processor.
27
The 8085 Microprocessors
Functional Description
Classification of Signal
(i) Address bus (unidirectional)
(ii) Data bus (Bi-directional)
(iii) Control and status signal (partially uni/Bi-directional)
(iv) Interrupt and externally initiated
(v) Serial IO ports
(vi) Power supply and frequency signal
RST 6.5 RD
8085
RST 5.5 WR
(iii)
INTR IO/M
(iv) Control and status
S1
signal
S0
Ready
Reset-Out
Hold HLDA
Reset-in INTA
Clock-Out
28
8085 Interrupts
Introduction
The interrupt driven I/O is one of the data transfer techniques used in h microprocessor
systems. By using this technique, the external device or peripheral can inform the
processor that it is ready for communication. The request for communication informed
by the peripheral is of the asynchronous type, meaning that it can be initiated at any
time without reference to the system clock. These requests are of two types: Maskable
and Non-maskable. In the case of maskable requests, the microprocessor has the
complete right to either service the requested communication or to deny it.
Interrupts of 8085
It is an internal or external signal which may disturb or alter the sequence of execution
of process. Interrupt is an event that demands the attention of the CPU. In general, any
microprocessor is set to be in the fetch execute cycle of the main program, i.e., in the
processing of the main program. If the occurrence of an interrupt event is recognized
by the microprocessor, it performs the following steps (known as interrupts switching
steps):
1500H
) ← (P
P
.S.
(PC S) =
Occurance of
oI
t
interrupt event
(TO
te rs
en
29
8085 Interrupts
Step-1:
Microprocessor completes execution of commonly fetched instruction.
Step-2:
Microprocessor saves the next address or written address available in the program
counter by pushing it into the top of the stack & then the program counter with vector
address, i.e., starting address of I.S.R
Step-3:
Microprocessor processes interrupt device routine, through fetch & execute cycle
Step-4:
At the end of I.S.R, when the microprocessor executes RET interrupt, it retrieves the
contents of TOS back into the program counter & interrupt resumes the main program
processes.
Classification of Interrupts
The 8085 has a multilevel interrupt system. It supports two types of interrupts:
Hardware Interrupts
These interrupts are available in the form of input pins i.e., physically available.
• 8085 has 5 hardware interrupts or external interrupts
RST 7.5
RST 6.5
RST 5.5
30
8085 Interrupts
When any of these pins, except INTR, is active, the internal control circuit of the 8085
produces a CALL to a predetermined memory location. This memory location, where
the subroutine starts is referred to as the vector location and such interrupts are called
vectored interrupts. The INTR is not a vectored interrupt. It receives the address of the
subroutine from the external device.
In 8085, all interrupts except TRAP are maskable. When a logic signal is applied to a
maskable interrupt input, the 8085 is interrupted only if that particular input is enabled.
These interrupts can be enabled or disabled under program control. If disabled, 8089
disables an interrupt request. The interrupt TRAP is non-maskable which means that
E is not maskable by program control. The Fig. 6.6.1 shows the interrupt structure of
8085. The figure indicates that, the 8085 is designed to respond to edge triggering, level
triggering or both.
3 RST 003416
Level triggered 6.5
003016
M 6.5
4 RST
5.5 002C16
Level triggered 002816
1 M 5.5 002416
TRAP
Both +ve edge and 002016
EI
Level triggered S Interrupt Get 001816
DI enable Q
Reset R RST 001016
Any interrupt recognized code 000816
from 000016
5 INTR external
hardware
Level triggered
31
8085 Interrupts
TRAP
CALL 0024H
1 D Q
TRAP Q
RESET IN
TRAP
ACKNOWLEDGE
• TRAP is both edge and level triggered. It is edge triggered such that it may respond
quickly. It is level triggered in order to differentiate the original signal from practical
application and error signal due to noise
• The signal on the TRAP pin must be high for at least 3 clock periods such that the
error signal due to noise may be avoided
RST 7.5
As shown in the above figure, it is positive edge triggered and the positive edge trigger
is stored internally by an the D flip-flop until it is cleared by a software reset using SIM
instruction or byan internally generated ACKNOWLEDGE signal. The positive edge signal
on the RST 7.5 pin sets the D flip-flop. If the mask bit M7.5 is 0 i.e., RST 7.5 is unmasked,
then 8085 completes its current instruction. It then pushes the address of the next
instruction onto the stack and loads the PC with the fixed vector address 003CH. Due
to this, 8085 starts execution of instructions from address 003CH which is the starting
address of an interrupt service routine for RST 7.5.
32
8085 Interrupts
INTR
INTR is a maskable interrupt, but not the vector interrupt. It has the lowest priority. The
following sequence of events occur when the INTR signal goes high.
(1) The 8085 checks the status of the INTR signal during the execution of each
instruction
(2) If the INTR signal is high, then 8085 completes its current instruction and sends
an active low interrupt acknowledge signal (INTA) if the interrupt is enabled
(3) In response to the INTA signal, external logic places an instruction OPCODE on the
data bus. In the case of multibyte instruction, additional interrupt acknowledge
machine cycles are generated by the 8085 to transfer the additional bytes into the
microprocessor
(4) On receiving the instruction, the 8085 saves the address of the next instruction on
the stack and executes the received instruction
33
8085 Interrupts
Software Interrupts
These interrupts are available in the form of instructions.
• 8085 has 8 software interrupts
RST 0
RST 1
RST 2
RST 3 Eight, 1 Byte intruction
RST 4 (Priorlly is not needed here)
RST 5 Because processor don't execute two instruction at atime
RST 6
RST 7
Maskable Interrupts
These interrupts can be either enabled or disabled by the program. If enabled, only
the occurrence interrupt event is recognized by the microprocessor. If disabled, the
occurrence of the interrupt event will be ignored by the microprocessor.
• EI (Enable Interrupt) & DI (Disable Interrupt & SIM (Set Interrupt Mask) instruction
are provided for masking
• 8085 has 12 maskable interrupts & only one non-maskable interrupt which is TRAP/
RST 4.5
• All 12 maskable interrupts can be globally enabled or disabled by using ‘EI’ or ‘DI’
Non-Maskable Interrupts
These interrupts cannot be disabled i.e., they always exist in an enabled state. The
8085 microprocessor has only 1 non-maskable interrupt (TRAP/RST4.5) which is used in
emergency conditions.
• EI, DI & SIM instructions don’t affect TRAP
Vectored Interrupts
For these interrupts, vector address, i.e., the starting address of I.S.R is prefixed by the
manufactures. The 8085 microprocessor has 12 vectored interrupts and these are:
RST 0 to RST 7 and RST 4.5, RST 5.5, RST 6.5, RST 7.5
34
8085 Interrupts
Non-Vectored Interrupt
For these interrupts the vectored address is not prefixed by the designer. As such,
for servicing such interrupts externally, dedicated hardware is required, i.e., external
hardware supplies as well as a vector address are required for the interrupt request.
• 8085 has only 1 non-vectored interrupt (INTR) i.e., interrupt request
• 8259 PIC is normally used for serving a non-vectored interrupt
µP
8085µ 8259 IC
Step 2 Step 1
RST 6.5
Step 4
Vector Address
P.C
RST 5.5
Data Bus Address Register
35
8085 Interrupts
• In order to use INTR, the programmer must select one of the software interrupt
address to store ISR of I/O device
• INTA Generates the pulse only to recognize the INTR interrupt
• INTR is a pseudo interrupt input which can be used for increasing the number of
interrupts of 8085, with the use of 8259 PIC
• In the normal mode of operation 8259PIC supports 8 interrupting devices in a
cascaded mode of operation. 8259PIC supports 64 interrupting devices
• INTA is an active low interrupt ACK active pin. The 8085 microprocessor generates
an active low signal via this INTA output, when it receives and recognizes an
interrupt request
• INTR is monitored by the processor in the last clock period of an instruction
• INTA is required only for INTR and not for a vectored interrupt
• Every vectored interrupt in 8085 is given 8 bytes of memory to store the
corresponding program that must be executed in response to an interrupt which is
known as the interrupt service routine (ISR)
• By default all the interrupts are disabled
Example: If external interrupt signal is received via RST 4.5, then microprocessor initialize
PC with?
Solution: Due to the smaller amount of memory between two interrupts we used JMP
instructions.
For RST 4.5 PC initialize with 0024
PC
0024H JMP
JMP 1500H
00
15
0040
Main Program
14FF
1500H
I.S.R
For
RST 4.5
15FFH
1600H I.S.R
For
RST 6
USR = User
160FH define sevice
1610H USR routine
36
8085 Interrupts
37
8085 Interrupts
38
Instruction Set of Microprocessor 8085
Chapter 4
Instruction Set of Microprocessor 8085
Objective
Upon completion of this chapter, you will be able to:
• Understand the language of instructions in a Microprocessor
• Explanation of Addressing mode
• Instruction set of 8085
39
Instruction Set of Microprocessor 8085
Programming Model
• Program: Set of instructions
• Instruction: It is a command given to the computer to perform some specific task
• Machine level language:
It is a binary means of communication with a computer through a design set of
instructions specific to a system
• Assembly level language:
Instructions are written in separate words known as ‘Mnemonics’ which are partially
understood by the programmer
MOV B, C
Example: Here MOV, ADD are Mnemonic (Easy to understand)
ADD D
• Both assembly and machine level language are together called Machine level
language
• Overall cycle of writing the program till execution:
Assembly Program
Assembler
Execute
Machine-Code
Decode (Microprogram)
40
Instruction Set of Microprocessor 8085
• Instruction format:
Op-code Operands
• Operand:
It is the data on which an operation is to be performed. Operand can be a register,
memory location register pair, 8-bit data or address, 16-bit data or address.
Length of anInstruction
• Number of bytes occupied by the instruction in the memory
• There are three types of instructions classified on the basis of length
Example: MOV
A,C
Op −code
operands
Example:
4000H: MOV A, C → XX
4001H: MVI B, 77H → yy, 77H
4003H: LXI H, 9030H → ZZ, 30H, 90H
41
Instruction Set of Microprocessor 8085
Memory representation:
F → Fetch
R → Read
(Memory)
4000H XX F
4001H yy F
4002H 77 R
4003H ZZ F
4004H 30 R
4005H 90 R
Note:
• Op-code is always fetch (In any type of process, fetch is always done first)
• Data is read or write
Memory Rule
In all memory related operations, the data present in the lower byte of the register is
transferred to a lower address location whereas higher byte data is transferred to a high
address location and vice-versa.
Standard Codes
B → 000
C → 001 Memory(M) → 110
D → 010 BC → 00
E → 011 DE → 01
H → 100 HL → 10
L → 101 SP → 11
A → 111
• Every register is given a unique code. There are 74 different op-codes in 8085 which
result in 246 instructions
42
Instruction Set of Microprocessor 8085
Addressing Modes
The mode of specifying an operand’s address is known as addressing mode. There are
various formats specifying the operands. They indicate how the data is accessed for an
instruction. There are 5 types of addressing modes:
(1) Register addressing mode
(2) Implicit/implied addressing mode
(3) Immediate addressing mode
(4) Direct addressing mode
(5) Indirect addressing mode
Example: DAA
RAL; RLC; RAR; RRC
43
Instruction Set of Microprocessor 8085
Example: LDA 9000H; OUT F4H; STA 200H; SHLD 4652H; LHLD 2145H
44
Instruction Set of Microprocessor 8085
Notations
r = 8 bit register
rs = 8 bit source register
rd = 8 bit destination register
r16 or rp = 16 bit register pair or 16 bit pointer
A = Accumulator
PSW = Program status word
M = Memory location contents pointed by HL pointers
45
Instruction Set of Microprocessor 8085
Syntax Operation
46
Instruction Set of Microprocessor 8085
Note:
• In almost all data transfer operations, the container of source is unchanged after
the execution
• Flags are not affected by the execution of data transfer group of instructions, since
ALU is not involved
• Working principle of stack is LIFO i.e., last pushed number will be popped out first
• Stack pointer contents decrement by 2 for execution of PUSH and CALL
instructions
• When the PUSH instruction is executed, the stack pointer decrement firsts & writes
to the decremented address
• Stack pointer contents is incremented by 2 for execution of POP and RETURN
instruction
• When POP instruction is executed stack pointer first reads then increments
• Stack pointer contents are unaltered for XTHL instruction since XTHL = POPH
followed by PUSH H
IR
XX
3000H XX F
.
.
D .
.
R
H L C 3500H 77
35 00 77 C
77
IR
XX
3400H XX F
PC .
.
3400 D .
3401 .
W
H L E 3700H 66
37 00 66 E
66
47
Instruction Set of Microprocessor 8085
IR
XX
3800H XX Fetch (F)
PC R
3801H FF
3800 A
D
3801 FF
A
FF
Z IR
33 XX
4000H XX F
R
PC 4001H 33
4000 D .
4001 . 33 Z
.
4002
W
4600H 33
H L
46 00
IR
XX
4700H XX F
PC
4700 4701H 00
R
4701 4702H 50 R
D
4702
4703 H L
50 00
H L
50 00
48
Instruction Set of Microprocessor 8085
IR
W Z
54 00 XX
5100H XX F
5101H 33 R
PC R
5102H 54
5100 D
. W Z
5101 .
54 00
5102
A 5400H 89
5103 R
89
89 A
IR
W Z
60 00 XX
5600H XX F
5601H 00 R
PC R
5602H 60
5600 D
. W Z
5601 .
60 00
5602
A 6000H 3F
5603 W
3F
3F A
IR
XX
6200H XX F
PC .
.
6200 D .
6201 .
R
B C A 6300H 79
63 00 79 A
79
49
Instruction Set of Microprocessor 8085
IR
XX
6400H XX F
PC .
.
6400 D .
6401 .
W
B C A 6900H 28
69 00 28 A
28
IR
D E
7000H XX
98 76 XX
. F
.
.
PC D
SP - 2 = F003H 76
7000
W
SP SP - 1 = F004H 98 W
7001
F005 SP = F005H WW
D E
F004 .
98 76
F003 .
.
FFFFH
IR
7300H XX
XX
. F
.
.
PC D
SP = D009H 30
7300 R
SP SP + 1 = D00AH 40 R
7301
D009 SP + 2 = D00BH WW
H L
D00A .
40 30
D00B .
.
FFFFH
50
Instruction Set of Microprocessor 8085
Example: 7700H: IN 50 H
IR
Z
7000H XX F
50 XX
50 R
7701H
Z
D
50
PC
Port address 50H
7700
7701
7702 A I/P
Device
WW
IR
Z
XX F
8000H
70 XX
70 R
8001H
Z
D
70
PC Port address 70H
8000
8001
8002 A O/P
Device
43
51
Instruction Set of Microprocessor 8085
IR
WZ
E4 00 XX
E000H XX F
E4 01 00
E001H R
E4 R
D E002H
.
. W Z
PC
. E4 00
E000
H L E400H 46
E001
E401H 8A R R
E002 8A 89
H L
E003
8A 46
IR
WZ
EB 00 XX
E600H XX F
E601H 00 R
EB R
D E602H
.
. W Z
PC
. EB 00
E600
H L E800H 57
E601
E801H 39 W W
E602 39 57
H L
E603
39 57
52
Instruction Set of Microprocessor 8085
Arithmetic Instruction
• No multiplexer/division operation is supported by 8085
• 8085 microprocessor has accumulator based ALU i.e., in most of the arithmetic &
logical operations, the accumulator is one of the source operands and also acts as a
destination operand for result storage
(a) Addition; ADD C
(b) Subtraction; SUB M
(c) Increment; INX H
(d) Decrement; DCR M
Syntax Operation
53
Instruction Set of Microprocessor 8085
Example: ADD C
DAA
(89)BCD = 1 0 0 0 1 0 0 1
(77)BCD = 0 1 1 1 0 1 1 1
CY = 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
CY 0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0 = 66H
54
Instruction Set of Microprocessor 8085
F9 = 1 1 1 1 1 0 0 1
68 = 0 1 1 0 1 0 0 0
CY = 1 0 1 1 0 0 0 0 1
(A) <= 61
S Z X AC X P X CY
0 0 0 1 0 0 0 1
38 = 0 0 1 1 1 0 0 0
C7 = 1 1 0 0 0 1 1 1
CY = 0 1 1 1 1 1 1 1 1
S Z X AC X P X CY
1 0 0 0 0 1 0 0
5B = 0 1 0 1 1 0 1 1
2E = 0 0 1 0 1 1 1 0
CY = 0 1 0 0 0 1 0 0 1
(A) <= 89
S Z X AC X P X CY
1 0 0 1 0 0 0 0
1
89 = 1 0 0 0 1 0 0 1
76 = 0 1 1 1 0 1 1 0
CY = 1 0 0 0 0 0 0 0 0
S Z X AC X P X CY
0 1 0 1 0 1 0 1
55
Instruction Set of Microprocessor 8085
94 = 1 0 0 1 0 1 0 0 94 = 1 0 0 1 0 1 0 0
−31 = 1 1 0 0 1 1 1 1 +CF = 1 1 0 0 1 1 1 1
CY = 1 0 1 1 0 0 0 1 1 CY = 1 0 1 1 0 0 0 1 1
S Z X AC X P X CY S Z X AC X P X CY
0 0 0 * 0 1 0 0 0 0 0 1 0 1 0 1
Using the manual method, we can’t find the ‘AC’ flag but the method used by the
processor has the capability to determine (assign) the Auxiliary flag (AC).
Trick
Find ‘AC’ by using the manual method.
If result is Nibble<Accumulator lower Nibble
Then AC = 1
Else AC = 0
24 = 0 0 1 0 0 1 0 0
−9C = 0 1 1 0 0 1 0 0
CY = 0 1 0 0 0 1 0 0 0
S Z X AC X P X CY
1 0 0 0 0 1 0 0
5A = 0 1 0 1 1 0 1 0
−9F = 0 0 1 0 0 0 0 1
CY = 0 0 1 1 1 1 0 1 1
S Z X AC X P X CY
1 0 0 0 0 1 0 1
56
Instruction Set of Microprocessor 8085
68 = 0 1 1 0 1 0 0 0
−AE = 0 1 0 1 0 0 1 0
CY = 0 1 0 1 1 1 0 1 0
S Z X AC X P X CY
1 0 0 0 0 0 0 1
FF = 1 1 1 1 1 1 1 1
+1 = 0 0 0 0 0 0 0 1
CY = 0 0 0 0 0 0 0 0 0
S Z X AC X P X CY
0 1 0 1 0 1 0 X'
8F = 1 0 0 0 1 1 1 1
+1 = 0 0 0 0 0 0 0 1
1 0 0 1 0 0 0 0
S Z X AC X P X CY
1 0 0 1 0 1 0 X'
FFFF = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
No flag will affect
+1 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57
Instruction Set of Microprocessor 8085
00 = 0 0 0 0 0 0 0 0
−1 = 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
S Z X AC X P X CY
1 0 0 0 0 1 0 X’
F000 = 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
−1 = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1
F00F = 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1
+9876 = 1 0 0 1 1 0 0 0 0 1 1 1 0 1 1 0
CY = 1 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 1
(HL)=8886H
Logical Instruction
8085 microprocessor has an accumulator base ALU i.e., in most logical operations, one of
the source operands is the accumulator which is also the destination operand for result
storage.
(a) AND; ANA D
(b) OR; ORI FFH
(c) Ex-OR; XRA M
(d) Compare; CDI 00H
(e) Compliment; CMA
(f) Rotate; RRC
58
Instruction Set of Microprocessor 8085
Syntax Operation
Complement contents of
CMA
accumulator
CMC CY <= CY
STC CY <= 1
59
Instruction Set of Microprocessor 8085
• For CMP M operation results are not stored in ‘M’. It differs from SUB instruction. We
have to check status from the flags
• CMA instruction is used for 1’s compliment performing
• Rotate operations include only change of carry flag. No other flags are affected using
the rotate operation
• For any AND operation AC=1 & CY=0
• For any OR operation AC=0 & CY=0
• Set by microprocessor, remaining flags depend on results
• Comparison is performed by doing internal subtraction but result is not stored
in accumulator i.e., both the operands involved in comparison are unaltered. Flag
register is updated after comparison operation
Z CY – (B) Result
1 0 Zero (A)=(B)
0 0 Positive (A)>(B)
0 1 Negative (A)<(B)
CY
MSB D6 D5 D4 D3 D2 D1 LSB
60
Instruction Set of Microprocessor 8085
CY
MSB D6 D5 D4 D3 D2 D1 LSB
CY
MSB D6 D5 D4 D3 D2 D1 LSB
CY
MSB D6 D5 D4 D3 D2 D1 LSB
61
Instruction Set of Microprocessor 8085
even or odd just by looking LSB, if LSB=0 then number is even otherwise it is odd
55 = 0 1 0 1 0 1 0 1
AA = 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0
S Z X AC X P X CY
0 1 0 1 0 1 0 0
62
Instruction Set of Microprocessor 8085
DB = 1 1 0 1 1 0 1 1
59 = 0 1 0 1 1 0 0 1
1 1 0 1 1 0 1 1
S Z X AC X P X CY
1 0 0 0 0 1 0 0
Z = 0 & CY = 0
A > B, Positive number
FF = 1 1 1 1 1 1 1 1
FF = 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
S Z X AC X P X CY
0 1 0 0 0 1 0 0
59 = 0 1 0 1 1 0 0 1
−BE = 0 1 0 0 0 0 1 0
1 0 0 1 1 0 1 1
S Z X AC X P X CY
1 0 0 0 0 1 0 1
63
Instruction Set of Microprocessor 8085
CY
MSB D6 D5 D4 D3 D2 D1 LSB
0 1 0 1 0 1 1 1
1 0 1 0 1 0 1 1
(A) <= AB
CY
MSB D6 D5 D4 D3 D2 D1 LSB
0 1 1 0 1 1 0 0
1 0 1 1 0 1 1 0
(A) <= B6
64
Instruction Set of Microprocessor 8085
Branching Instruction
This group of instructions is also called the program transfer control group. In this
group, the control program is transferred from one location to another conditionally or
unconditionally. These instructions are operated on the program counter and in turn they
change or alter the sequence of processing.
Conditional Instruction
They depend on the status of the flags affected by the previous ALU operation (except
Auxiliary carry flag (AC)).
• When condition is true, control of program is transferred to a 16-bit address. 3
machine cycles i.e., 10T states consumed
• When condition is false, the very next instruction is executed. 2 machine cycle i.e.,
7T states are consumed
Test conditions
JUMP Instruction
Syntax Operation
65
Instruction Set of Microprocessor 8085
W Z
30 02
+1
PC 3000
3006
3003
• In the above program, if the content of the register ‘c’ is ’n’, the loop executes for
n-times where the condition is true for (n-1) times and, when it is false, only once
• When the condition is false, the PC is incremented twice to execute the next
instruction
• The operation of the remaining conditional jump instructions is similar to JNZ
except that the flags are different
CALL Instruction
Syntax Operation
When condition is true, the operation is similar to an un-condition call that is 5 machine
cycles i.e., 18 T-States.
• When condition is false, 2 machine cycles i.e., 9 T-States are consumed
• When the condition is false, the SP (Stack Pointer) is unchanged
66
Instruction Set of Microprocessor 8085
Return Instruction
Syntax Operation
Unconditional Instruction
The control of the program is transferred to 16 bit address unconditionally.
Syntax Operation
67
Instruction Set of Microprocessor 8085
• The term used for call in ‘c’ language is function calling, but in a microprocessor,
this function is termed ‘Subroutine’
• If length of instruction is large, it is termed ‘Procedure’
• If length of instruction is small it is termed ‘Macro’
• Call instructions are used to call the subroutine main program
Subroutine
A set or a group of instructions which perform specific functions can be written as a
separate program away from the main program and this is known as Subroutine.
Step-2: The control of the program is transferred to the Subroutine address and
execution continues.
Step-2: Control of the program is transferred to the vector address of RST n and
execution is completed.
• CALL & RET operations are known as subroutine handling operations. CALL
instruction is used for transferring the program control to a subroutine from the
main program and RET instruction is used for transferring the control program back
to the main program from the subroutine.
68
Instruction Set of Microprocessor 8085
MOV A, C
JMP QUIT
ORI FFH
These are not executed because of jump instructions.
ANI FFH
OUIT: HLT .
6000H
.
.
.
Example: Main Program: 6005H XX F
69
Instruction Set of Microprocessor 8085
C = 03
02, Z = 0 → True
01, Z = 0 → True
00, Z = 1 → False
Let the above program provide ‘x’ µ second delay, then if we introduce ‘NOP’, the delay is
increased by 4 T-States
• DI (Disable interrupt) → 1 Byte instruction
Used to disable the maskable interrupt. Used at the initial instruction of ISR such
that the processor may not be disturbed by other interrupts.
• EI (Enable interrupt) → 1 Byte instruction. It is used to enable maskable interrupts.
Used at the initial instruction of the main program and at the last instruction of
an ISR, such that the processor may be ready to serve another interrupt. Internally
enabled interrupt flip-flop is set.
• SIM (Set interrupt mask) → 1 Byte instruction
It is a multipurpose instruction used to mask the interrupts or make them available
valid only for RST 7.5, RST 6.5, RST 5.5. It is used along with the contents of the
Accumulator. It is also used to transfer serial data out the processor through SOD
pin.
SOD pin
D7 D6 D5 D4 D3 D2 D1 D0
Serial O/P
data if 1 = Masked
0 = Available
Reset
Serial data RST 7.5 F.F Mask set enable
Enable 1 = Reset
1 = Enable SOD 1 = D2 − D0 = Valid/significant
0 = Disable SOD 0 = D2 − D0 =Invalid/Insignificnt
• 'D3' bit is the control over D2 − D0. If it is 1 they are valid/significant else invalid/
insignificant
70
Instruction Set of Microprocessor 8085
Solution: 4C → 01001100
0 1 0 0 1 1 0 0
SID pin
D7 D6 D5 D4 D3 D2 D1 D0
Serial I/P
data Status of pending if 1 = Masked
Interrupts 0 = Available
1 = Pending
Interrupt Enable Flip-Flop
1 = Interrupt Enable (For EI)
0 = Interrupt Disable (For DI)
• D7 is the serial data received into the processor through the SID pin
71
Instruction Set of Microprocessor 8085
Example: The content of Accumulator after execution of RIM instruction is 9CH. Find:-
(i) Interrupt masked
(ii) Interrupt available
(iii) Interrupt pending
(iv) Serial data received
1 0 0 1 1 1 0 0
Notes:
SIM → Controls the interrupt
RIM → Represents status of the interrupt
Conclusion:
* PUSH Rp
* POP Rp
* CALL SP → SP-2 → SP → SP+2
* Return
* RST n
Solved Examples
Problem:
9900H: LXI H, 1230H
9903H: PCHL
9904H: MVI A, FFH
9906H: HLT
What is content of “A” after execution of above program
Solution: Since the PCHL operation changes the PC to 9906H, the instruction at 9904H is
not executed. Hence, the content of A is undefined.
72
Instruction Set of Microprocessor 8085
Problem:
After the execution, what is the content of SP and data present at CFFEH
LXI SP, FF00H
LXI H, D000H
SPHL
PUSH B
POP B
HLT
Solution: (SP)=FF00H
(HL)=D000H
(SP)=D000H
SP=D000H after PUSH & POP operation because PUSH and POP cancel each other out.
At CFFEH → 00H (When push perform, SP → SP-2 i.e., CFFEH and at this position lower bit
of HL is place i.e., 00H)
Problem:
Write an assembly language program (ALP) to perform Ex-Or operation between the first
two memory location data and to store the contents of the flag register and accumulator
to the next memory location.
Solution:
LDA 6000H
MOV B, A
LDA 6001
XRA B
LXI SP 6004
PUSH PSW
HLT
B = E7 = 1 1 1 0 0 1 1 1
A = −B1 = 1 0 0 0 0 0 0 1
0 1 1 0 0 1 1 0
S Z X AC X P X CY
0 0 0 0 0 1 0 0
73
Instruction Set of Microprocessor 8085
Problem:
Write an assembly language program to access a data byte from port address 70H,
complement it, and rotate the result left side 5 times. Store the resultant value at 900FH
and after transferring it to port, add 90H.
Solution:
IN 70H
CMA
MVI B, 05 H
L1: RLC
DCR B
JNZ: L1
OUT 90H
STA 900FH
HLT
Problem:
LHLD 7000H
LXI D, 7003H
LDAX D
MOV B, M
ANA B
DAD H
SPHL
PUSH PSW
HLT
Then find address stored in SP and the top of the stack & also find the value stored in
the accumulator.
7000H 02
7001H 70
7002H BD
7003H 3C
74
Instruction Set of Microprocessor 8085
Solution:
(i) H = 70, L = 02
D = 70, E = 02
(ii) A = 3C
(iii) B = BD
(iv) 3C = 0 0 1 1 1 1 0 0
BD = 1 0 1 1 1 1 0 1
0 0 1 1 1 1 0 0 = 3CH
S Z X AC X P X CY
0 0 0 1 0 1 0 0
PSW = 3C14H
7002
(v) 7002
E004
(vi) SP → E004
(vii) SP → E002
Problem:
Write an assembly language program for 8085 to transfer 4-bytes of data starting from
7000 to 8000H
Solution:
LXI H 7000H
LXI D 8000H
MVI B, 04H
Rept: MOV A, M
STAX D
INX H
INX D
DCR B
JNZ: Rept
HLT
75
Instruction Set of Microprocessor 8085
Problem:
Find the content of SP and data present at the top of the stack after the execution of the
following program:
900H: LXI SP, FF00H
9003H: LXI H, 9009H
9006H: PCHL
9007H: MVI B, 66H
9009H: CALL R1
900CH: JMP QUIT
R1: 900FH: XRA A
9010H: RP
QUIT: 9011H: HLT
Solution:
SP = FF00H
HL = 9009H
PC = 9009
B = 66H
Due to the Call instruction, the contents of the Program Counter are stored in Stack and
the Program counter contains the address of the subroutine.
PC = 900F & SP = FEFEH
A = 00H & Z = 1, P = 1, CY = 0, AC = 0, S = 0
S = 0 i.e., return to 900CH
PC = 900CH
Hence, at the top of SP, after execution of program = 55 at address FF00H, but content
of SP is OC, 90, 55 as shown in the diagram with the address.
SP-2 = FEFEH 0C
SP-1 = FEFFH 90
SP = FF00H 55
90 0C
76
8085-Timing Diagrams
Introduction
During a normal operation, the microprocessor sequentially fetches, decodes and
executes one instruction after another until a halt instruction (HLT) is executed. The
fetching, decoding and execution of a single instruction constitutes an instruction cycle
which consists of one to five read or write operations between processor and memory
or input/output devices. Each memory or I/O operation requires a particular time
period, called machine cycle. In other words, to move a byte of data in or out of the
microprocessor, a machine cycle is required. Each machine cycle consists of 3 to 6 clock
periods/cycles, referred to as T-states. Therefore, we can say that one instruction cycle
consists of one to five machine cycles and one machine cycle consists of three to six
T-states i.e., three to six clock periods, as shown in the figure.
Instruction Cycle
Timing Diagram
Timing diagram is pictorial representation of execution of an instruction with the help of
various control and status signals.
There are seven different types of machine cycles in the 8085A. Three status sin IO/, S1,
and S0 identify each type as shown in below table. These signals are generated at the
beginning of each machine cycle and remained valid for the duration of the cycle.
77
8085-Timing Diagrams
IO/ M S1 S0 RD WRINTA
Opcode Fetch 0 1 1 0 1 1
Memory Read 0 1 0 0 1 1
Memory Write 0 0 1 1 0 1
I/O Read 1 1 0 0 1 1
I/O Write 1 0 1 1 0 1
INTR Acknowledge 1 1 1 1 1 0
Bus Idle 0 0 0 1 1 1
Representation of Signals
Before going to see the timing diagram, we will see the signals and their representation
used in the timing diagrams.
Clock Signal
The 8085 divides the clock frequency provided at X1 and X2 inputs by 2, which is called
operating frequency. All the operations within the 8085 are synchronized with this
operating frequency. Therefore, in the timing diagram operating frequency clock is on the
top and then the signals are shown with reference to operating frequency clock. Ideally,
the clock signal should be square wave with zero rise time and fall time, as shown in the
figure. But in practice, we don’t get zero rise time and fall time. Therefore, the clock and
other signals are always shown with finite rise and fall times.
T-State T-State Tf Tr
1 Clock cycle
(a) Ideal (b) Practical
Figure: Clock signal representation
Single Signal
Single signal is represented by a line. It may have status either logic 0 or logic 1 or
tri-state. The change in the state of the signal takes finite time and hence the state
change of signal is represented with finite rise time and fall time, as shown in the Figure.
78
8085-Timing Diagrams
Logic - 1 Logic - 1
Tri-state
Logic - 0 Logic - 0 Logic - 0
Tr Tf
Group of Signals
Group of signals is also called a bus, e.g. address bus and data bus. To avoid
complications in the timing diagram these signal are grouped and shown in figure.
Tri-state
Figure: Group of signals representation
In the group representation individual state is not considered, but the group state is
considered. Change in state of single signal changes the state of group. It is represented
by the cross as shown in the above figure. The tri-state condition of the group signals is
shown by dotted lines. Two straight lines represent valid state/stable state.
In microprocessor systems, activation of signal/signals depends on the state of other
signal/signals. Such situations are shown in the timing diagrams with the help of specific
symbols. There are four possibilities:
• Activation of a signal with the change in state of other signal
• Activation of a signal with the change in state of other signals
• Activation of signals with the change in state of other signal
• Activation of signals with the change in state of other signals
Figures show the representation of dependence of the signal/signals in the timing diagram.
Other signal
Activated signal
(a) Activation of signal with the (b) Activation of signal with the
change in state of other signal change in state of other signal
(c) Activation of a signal with the (d) Activation of signals with the
change in state of other signals change in state of other signals
79
8085-Timing Diagrams
Signal Timings
In 8085 microprocessor, signals are activated at a specific instant for a specific time period.
Once we understand this, it is very easy to draw timing diagrams. The following section
explains when the signals are activated and for what period they remain in active state.
T1 T2 T3 T4 T1 T2 T3
ALE
T1 T2 T3 T4 T1 T2 T3
AD0 − AD7 A0 − A1 A0 − A7
D0 − D7 (Data Bus)
The data from memory or I/O device and from microprocessor to memory or I/O device
is transferred during T2 and T3-states. It is important to note that in read machine cycle,
data will appear on the data bus during the later part of the T2-state, as shown in the
figure, whereas in write cycle data will appear on the data bus at the beginning of the T2
state, as shown in the figure.
80
8085-Timing Diagrams
T1 T2 T3 T1 T2 T3
To read data from memory or I/O device, it is necessary to select memory or I/O device.
After selection, device will put the data from selected location on the data bus. This
action needs finite time. This time is referred to as access time. In case of write cycle,
data is available in the registers of the microprocessor and it can put that data on the
data bus with zero access time.
T1 T2 T3 T4 T1 T2 T3
IO/ M , S0, S1
T1 T2 T3 T4 T1 T2 T3
81
8085-Timing Diagrams
These signals are called status signals. They decide the type of machine cycle to be
executed. They are activated at the beginning of T1 state of each machine cycle and
remain active till the end of the machine cycle.
RD and WR
These signals decide the direction of the data transfer. When RD signal is active, data
is transmitted from memory or I/O device to the microprocessor, and when WR signal
is active, data is transmitted from microprocessor to the memory or I/O device. Both
signals are never active at the same time.
As we know data transfer in 8085 takes place during T2 and T3, these signals are
activated during T2 and T3, as shown in the Figure.
T1 T2 T3 T1 T2 T3
RD
WD
Machine Cycle
It is defined as the time required to access either memory or Input-Output or it is also
equivalent to the time required to transfer a data byte to memory or Input-Output. One
machine cycle may contain 3 to 6 T-States:
Processor only does this 5 operations:
(1) Opcode (Fetch)
(2) mr (Memory Read)
(3) mw (Memory Write)
(4) IOR (Input-Output Read)
(5) IOW (Input-Output Write)
82
8085-Timing Diagrams
Step 1:
(State T1) In T1 state, the 8085 places the contents of program counter on the address
bus. The high-order byte of the PC is placed on the A8-A15 lines. The low-order byte of the
PC is placed on the AD0- AD7 lines which stays on only during T1. Thus, microprocessor
activates ALE (Address Latch Enable) which is used to latch the low-order byte of the
address in external latch before it disappears.
IR data
Instruction B C
register
D E
(IR)
H L
SP
PC
Instruction
decoder
(IR)
AD7 AD0
Timing ALE
and Latch
control
A7 A0
Memory
A15 A8
Memory
read
Data bus
In T1, 8085 also sends status signals IO/M, S, and So. IO/M, S1 and S0. IO/specifies
whether it is a memory or I/O operation, S1, status specifies whether it is read/write
operation; S1 and S0 together indicates read, write, opcode fetch, machine cycle
operation, or whether it is in HALT state. In opcode fetch machine cycle status signals
are: I0/M = 0, S1 = 1
83
8085-Timing Diagrams
Opcode Fetch
T1 T2 T3 T4
CLK
A15
High order memory address Unspecified
A8
AD7
Low order Opcode
AD0
Memory address
ALE
RD
Step 2:
(State T2) In T2, low-order address disappears from the AD0 – AD7 lines. (However A0 – A 7
remain available as they were latched during T1). In T2 8085 sends signal low to enable
the addressed memory location. The memory device then places the contents of
addressed memory location on the data bus (AD0- AD7).
Step 3:
(State T3) During T3, 8085 loads the data from the data bus in its Instruction Register and
raises RD to high which disables the memory device.
Step 4:
(State T4) In T4, microprocessor decodes the opcode, and on the basis of the instruction
received, it decides whether to enter state T5 or to enter state T1 of the next machine
cycle. One byte instructions those operate on eight bit data (8 bit operand) are executed
in T4.
For example: MOV A, B, ANA D, ADD B, INR L, DCR C, RAL and many more.
Note: For one byte instructions which operate on eight bit data, data is always
available in the internal memory of 8085 i.e., registers.
84
8085-Timing Diagrams
Step 5:
(State T5 and T6) State T5 and T6, when entered, are used for internal microprocessor
operations required by the instruction. During T5 and T6 8085 performs stack write,
internal 16 bit, and conditional return operations depending upon the type of instruction.
One byte instructions those operate on sixteen bit data (16 bit operand) are executed in
T5 and T6.
For example: DCX H, PCHL, SPHL, INX H, etc.
IR data
Instruction B C
register
(IR) D E
H L
SP
Instruction
PC
decoder
(IR)
AD7 AD0
Timing and ALE
Latch
control
A7 A0
Memory
A15 A8
Memory
read
Data bus
85
8085-Timing Diagrams
Memory read
T1 T2 T3
CLK
ALE
RD
Step 1:
(State T1) In T1 state, microprocessor places the address on the address lines from stack
pointer, general purpose register pair or program counter and activates ALE signal in
order to latch low-order byte of address. During T1 8085 sends status signals: IO / M = 0,
S1 = 1, and S0 = 0 for memory read machine cycle.
Step 2:
(State T2) In T2 8085 sends RD signal low to enable the addressed memory location. The
memory device then places the contents of addressed memory location on the data bus
(AD0 − AD7).
Step 3:
(State T3) During T3, 8085 loads the data from the data bus into specified register (F, A, B,
C, D, E, H, and L) and raises RD to high which disables the memory device.
86
8085-Timing Diagrams
Step 1:
(State T1) In T1, state, the 8085 places the address on the address lines from stack
pointer or general purpose register pair and activates ALE signal in order to latch low-
order byte of address. During T1 8085 sends status signals:
IO/M = 0, S1 =0 and S0 = 1 for memory write machine cycle.
Step 2:
(State T2) In T2 8085 places data on the data bus and sends WR signal low for writing into
the addressed memory location.
Step 3:
(State T3) During T3, WR signal goes high, which disables the memory device and
terminates the write operation.
IR data
Instruction B C
register D E
(IR)
H L
SP
Instruction PC
decoder
(ID)
AD7 AD0
ALE
Timing and Latch
control
A7 A0
Memory
A15 A8
Memory
read Data bus
87
8085-Timing Diagrams
T1 T2 T3
CLK
RD
A B C
IR
D E
H L
SP
PC
Figure 1: (a) Data (opcode) flow
from memory to ID
microprocessor
AD7 AD0
ALE
Timing and Latch
control
A15 − A8
Output OR
device
A7 − A0
I/O
write Data bus
Indicates
Indicates address flow,
data flow,
88
8085-Timing Diagrams
T1 T2 T3
CLK
ALE
WR
B C
A IR D E
H L
SP
PC
ID
A15 − A8
Output OR
device
A 7 − A0
I/O
write Data bus
89
8085-Timing Diagrams
I/0 Write
T1 T2 T3
CLK
ALE
WR
90
8085-Timing Diagrams
MR or IOR MR or IOR
T1 T2 T3 T1 T2 TWAIT T3
CLK
I0/M
I0/M= 0 (MR) OR 1 (I0R), S1 = 1, S0 = 0 I0/M = 0(MR) OR 1 (I0R), S1 = 1, S0= 0
S1, S0
A8 − AD7
OUT IN OUT IN
AD0 − AD15 A0 − AD7 D0 − D7 A0 − A7 D0 − D7
ALE
RD
READY
T1 State
When reset-in becomes inactive, the 8085 enters the state T1. This is the first clock cycle
of a machine cycle. At the end of T1, if the HALT flip-flop status is 0, it enters state T2
otherwise it will enter into Thalt state.
T2 State
At the end of T2
• If the ready input of 8085 is 0 and the machine cycle is not a BI machine cycle then
the 8085 enters Twait state
91
8085-Timing Diagrams
Note: Intel 8085 executes a BI machine cycle only for DAD instruction or when it
is required to respond to a vector interrupt.
• If the ready input of 8085 is 1 or the machine cycle is a BI machine cycle, then 8085
checks the HOLD input. If the HOLD input is not active, 8085 enters T3 state. If the
HOLD input is active, 8085 sets the HLDA flip-flop and enters the T3 state.
Treset
Reset in
HLDA F/F = 1
N
T3 OF 6 CLK
T4
OF 4 CLK
N Y
HLT in IR HOLD = 1
Y N HLDA F/F = 1
HALT F/F = 1
T6 T5
HCDA F/F Y
=1
N Activate
HLDA
N Last M/C
cycle of
insth Thold
Y
N Valid
interrupt
Y
Reset INTE F/F
N
Set INTA F/F
92
8085-Timing Diagrams
TWait State
As long as the ready input remains 0, the 8085 remains in TWait state. When the ready
input becomes 1, 8085 comes out of TWait state.
T3 State
If it is a first machine cycle of an instruction (opcode fetch (OF) machine cycle), the 8085
enters T4 state from T3. If it is not an opcode fetch machine cycle, it checks the status of
the HLDA flip-flop.
T4 State
At the end of T4:
• If it is a six-clock machine cycle, the 8085 again checks the HOLD input. If the
HOLD input is not active, the 8085 enters T5 state. If the HOLD is active, the 8085
sets the HLDA flip-flop and then enters T5 state.
• If it is a four-clock machine cycle, in the last clock cycle, 8085 checks if the code
for HLT instruction is in the IR. If yes, the 8085 sets the HALT flip-flop, and then
checks the status of HLDA flip-flop. If the IR is not having the code for HLT, the
8085 directly checks the status of the HLDA flip-flop.
T5 State
From state T5, 8085 enters state T6. At the end of T6, the HLDA flip-flop status is checked.
Valid Interrupt
If there is any valid interrupt at the end of an instruction cycle, the 8085 resets the
INTE flip-flop. This ensures that the execution of ISR can proceed without any further
interrupts. Then 8085 checks to find out if INTR is the only valid interrupt. If yes, it
93
8085-Timing Diagrams
sets the INTA flip-flop that activates INTA output pin. Then the 8085 goes ahead with
receiving a 3-byte CALL instruction, or a 1-byte RSTn instruction from an I/O device, by
entering the T1 state of an INTA machine cycle. If an interrupt other than INTR is a valid
interrupt, the 8085 directly goes ahead with BI machine cycle, by entering T1 state again.
Thalt State
At the end of T1 if HALT flip-flop status is 1, the 8085 enters state Thalt. If the HOLD input
remains inactive and there is no valid interrupt request, the 8085 remains in Thalt. It
leaves the Thalt state in case of a valid interrupt or active HOLD input.
If the HOLD input becomes active during Thalt the 8085 sets the HLDA flip-flop, and
activates the HLDA output pin and enters Thold state. As discussed earlier, the 8085
remains in the Thold state as long as the HOLD input is active. When the HOLD input is
deactivated, it comes out of the HOLD state and resets the HLDA flip-flop. Then the
8085 re-enters Thalt state from T1 state.
If a valid interrupt becomes active during Thalt the 8085 resets the HALT, and INTE flip-
flops. This ensures that the 8085 has come out of the halt state, and the execution of
ISR can proceed without any further interrupts.
Thold State
It remains in the Thold state as long as the HOLD input is active. When the HOLD input
is deactivated, the 8085 comes out of the HOLD state and resets the HLDA flip-flop.
Then the 8085 goes ahead with the first clock cycle for the next machine cycle in the
instruction by entering state T1.
Instruction Cycle
It is the time required to complete the execution in instruction. One instruction cycle
may contain 1 to 5 machine cycles
• =
IC IFC + EC
•=
IC1B OPFC + EC
Execution
• Internal 8 bit operation will be performed during T4 of OPFC
• Internal 16 bit operation requires two clock cycle extra (2T state)
• External 8 bit operation [MWC, MRC, IOWC, IORC] requires 3T state
94
8085-Timing Diagrams
Note:
• Op-code fetch MCs are of 2 types
• Normal OPFC = 4T
• Special OPFC = 6T
PCHL ⇒ 1 Byte instruction
⇒ OPFC + 2T
⇒ 6T states
OUT F8H ⇒ 2B
⇒ OPFC + mr1c + IOW
⇒ 3MC = 4T + 3T + 3T = 10T states
IN F9H ⇒ 2B
⇒ OPFC + mc + IOR
⇒ 3MC = 4T + 3T + 3T = 10T states
95
8085-Timing Diagrams
96
8085-Timing Diagrams
ADI 84H ⇒ 2B
⇒ OPFC + mr1c
⇒ 2MC = 4T + 3T = 7T states
• ACI F4H, SUI 44H, SBI 20H, ORI 40H, ANI 00H, XRI 10H, CPI 11H
97
8085-Timing Diagrams
• JC 1001H, JPE 1200H, JPO Delay, JNZ 1010H, JZ 1210H, JP 1001H, JM 2100H
• CC 1000H, CPE 1100H, CPO Delay, CNZ 1010H, CZ 1111H, CP 1212H, CM LOOP
RET ⇒ 1 Byte instruction
⇒ OPFC + MR1C + MR2C
⇒ 4T + 3T + 3T = 10T states
98
8085-Timing Diagrams
Timing Diagram
It is a representation of the various control signals generated during execution of an
instruction.
Following Buses and control signals must be shown in the timing diagram
AD7 − AD0 Z
00H XX 01H 99H
IO/M, IO/M = 0 S1 = 1, S0 = 0
IO/M = 0 S1 S0 = 1
S1 S0
Steps RD
(1) Fetch
(2) Decode
(3) Execute
• Machine cycle: (here 2-machine cycle)
99
8085-Timing Diagrams
• 7 T-States
• For any instruction to be executed, the first machine cycle is op-code fetch which
may be of 4 or 6 T-State.
T1 State
• ALE = 1 (high) is indicating all 16 lines act as address buses
• A15 − A8 contain higher byte address present in program counter (PC)
• AD7 − AD0 contain lower byte of PC
• IO / M = 0 indicates memory operation
• S1 = S0 = 1 for fetch
T2 State
• As ALE becomes low, AD7 − AD0 act as data bus
• When RD is activated, op-code from the memory location is access onto data bus.
T3 State
• Op-code from the data bus is accessed into the instruction register (IR)
T4 State
• The op-code is decoded (D) and execution may also be completed for some
instruction like MOV A, B; but when the instruction is considered a memory read,
operation is required
• Status of higher order bus (address) is unknown
Memory Read
T5 State
• ALE is high in order to point to the next memory location
• T6 and T7 are similar to fetch except that S1 = 1, S1 = 0, for memory use.
• 99H is accessed into Accumulator (A) in T6 and T7 for the instruction given.
100
8085-Timing Diagrams
Conclusion
• Length of instruction = 2 byte
• No. of machine cycles = 2 (F, R)
• Total T-State = 7 (F → 4, R → 3)
• Total execution time = count period × no. of T-State × count value
1 1
= × T - States × C.V = × 7 × 1= 2.31 µ sec
fclk 3 × 106
T-State
Min Max
Fetch 4 6
Machine cycle 3 6
Instruction 4 18
Note:
• The number of machine cycles required for the execution of an instruction may or
may not be equal to the length of the instruction
• ALE is high in first T-State of a machine cycle
101
8085-Timing Diagrams
102
Memory and I/O Interfacing
Chapter 6
Memory and I/O Interfacing
Objective
Upon completion of this chapter, you will be able to understand:
• Memory Interfacing
• I/O mapped I/O
• Memory mapped I/O techniques
Introduction:
Memory is an integral part of a microprocessor system, and in this chapter, we will
discuss how to interface a memory device with the microprocessor. The memory
interfacing circuit is used to access memory quite frequently in order to read instruction
codes and data stored in the memory. This read/write operations are monitored by
control signals. The microprocessor activates these signals when it wants to read
from and write into memory. In this chapter we will see memory structure and its
requirements, concepts in memory interfacing and interfacing examples.
Types of Memory
The internal memory is a semiconductor random access memory.
Classification of Memory
Memory
103
Memory and I/O Interfacing
Static RAM contains less memory cells per unit Dynamic RAM contains more memory cells as
1
area compared to static RAM per unit area
2 It has less access time hence faster memories Its access time is greater than static RAM's
104
Memory and I/O Interfacing
Word Line
Vcc
Address Line
105
Memory and I/O Interfacing
The chip can be reprogrammed. This memory is ideally suitable for product development,
experimental projects and college laboratories, since this chip can be reused many times.
Disadvantage
EEPROMS are most expensive and are the least dense ROMs.
Memory Interfacing
Memory location = 2Number of address i/p lines
• A memory with n address i/p lines will have 2n bytes
• Number of address i/p lines is going to decide the memory
E.g.: For 10 address line, 210 bytes = 1KB memory
Memory Mapping
Given names to or addressing memory location is known as memory mapping, Memory
map indicates starting and ending and the range of a memory chip.
106
Memory and I/O Interfacing
Solved Examples
Problem: Find the memory map for given interfacing logic
A15
A14
A13
A12
A11
A10
CS RD WR
A0
.
.
. 1 KB
.
. n = 10
.
.
.
A9
Solution: For chip select, NAND gate output must be zero, it happens only when
A15
A14
A13
A12
A11
CS RD WR
A0
.
.
. 2 KB
.
. 11 address line
.
.
.
.
A10
107
Memory and I/O Interfacing
Solution: For chip select, NAND gate output must be zero. It happens only when
A 15 A 14 A 13 A 12 A 11 A 10 A9 A8 A 7 A6 A5 A 4 A 3 A 2 A 1 A0
1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 = 8800H
1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 = 8FFFH
Problem: Find the ending address of a 4KB ROM if starting address is C3A9H
Solution:
4 KB = 12 address line [4KB = 212 ⇒ n = 12]
Problem: Calculate the starting address for a 8KB RAM if ending address is 60AB H
Solution:
8 KB = 13 address line [8KB = 213 ⇒ n = 13]
Problem:
A15
A14
E Y0
Y1
A13 C A0 CS
Y2
Y3 2 KB
A12 B
Y4 RAM
Y5 A10
A11 A
Y6
Y7
108
Memory and I/O Interfacing
Solution:
C B A O/P
1 0 0 Y4
A 15 A 14 A 13 A 12 A 11 A 10 A9 A8 A 7 A6 A5 A 4 A 3 A 2 A 1 A0
1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 = A000H
1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 = A7FFH
• In this device address is 16-bit. Thus, A0 • In this I/O device address is 8-bit. Thus,
to A15 lines are used to generate device A0 to A7 or A8to A15 lines are used to
address generate device address
• 28 → 256; 256 I/P and 256 O/P devices • 216 → 65,536; Address are shared
are possible between memory and I/O
109
Memory and I/O Interfacing
110
DMA (Direct Memory Access)
Chapter 7
DMA (Direct Memory Access)
Objective
Upon completion of this chapter, you will be able to understand:
• Hardware Controlled Data Transfer
• Data Transfer Modes of DMA
Introduction:
In microprocessor-based systems data transfer can be controlled by either the software
or the hardware. Up till this point we have used program instructions to transfer data
from I/O device to memory or from memory to I/O device. To transfer data by this
method, the microprocessor has to do following tasks:
(1) Fetch the instruction
(2) Decode the instruction and
(3) Execute the instruction
To carry out these tasks, the microprocessor requires considerable time, so this method
of data transfer is not suitable for large data transfers such as data transfer from
magnetic disk or optical disk to memory. In such situations hardware-controlled data
transfer technique is used.
111
DMA (Direct Memory Access)
Start
Initialization Counter
Initialize Source Pointer
Get byte
Send byte
No
Last byte
?
Yes
Stop
Flowchart
Program
Transfer Subroutine
LXI H, 6000H
BACK: MOV A, M
OUT PA
MOV A, L
CPI 20H
JNZ BACK
RET
112
DMA (Direct Memory Access)
Address
X
AD0 − AD15 Bus
Latches
ALE Y Data
X
Microprocessor Bus
Data Bus Memory
Y
IOR, IOW, X
HLDA HOLD
MEMR, MEMW
HRQ Y Control
DMA Bus
HLDA Controller Peripheral
Control
Bus device (Disk
DRQ Controller)
DACK
Operation of DMA Controller in a Microprocessor System
113
DMA (Direct Memory Access)
When the data transfer is complete, the DMA controller unasserts the HOLD request
signal to the microprocessor and releases the bus by changing the switch position from
B to A. After getting the control of all buses the microprocessor executes the remaining
program.
114
DMA (Direct Memory Access)
115
DMA (Direct Memory Access)
Start
Is No
I/O device
ready for data
transfer
?
Yes
Is
terminal
No
count
exhausted
?
Yes
Stop
116
DMA (Direct Memory Access)
Start
Is No
I/O device
ready for data
transfer
?
Yes
Is
terminal
No count
exhausted
?
Is Yes
No I/O device
ready for data DMA relinquishes control of
transfer buses to processor
?
Yes Stop
117
DMA (Direct Memory Access)
Start
Is No
I/O device
ready for data
transfer
?
Yes
Is Is
I/O device terminal
Yes ready for data No count
transfer exhausted
? ?
No Yes
Stop
118
DMA (Direct Memory Access)
• Address Strobe (ADSTB): This signal is used to demultiplex higher byte address and
data using external latch
(
• Memory Read and Memory Write MEMR, MEMW : )
These are active low tri-state signals. The signal is used to access data from the
addressed memory location during a DMA read or memory-to-memory transfer and
signal is used to write data to the addressed memory location during DMA write or
memory-to-memory transfer.
119
DMA (Direct Memory Access)
• RESET:
This active high signal clears the command, status, request, and temporary
registers. It also clears the first flip-flop and sets the master register. After reset
the device is in the idle cycle.
• READY:
This input is used to extend the memory read and write pulses from the 8237A to
interface slow memories or I/O devices.
120
DMA (Direct Memory Access)
A8-A15
COMMAND
CONTROL
WRITE READ
BUFFER BUFFER D0-D1
DREQ0- 4 COMMAND
PRIORITY IO
DREQ3 ENCODER (8) INTERNAL DATA BUS
BUFFER
HLDA AND
ROTATING MASK
DB0-DB7
HRQ (4)
4
PRIORITY
DACK0- LOGIC STATUS TEMPORARY
DACK3 REQUEST MODE (8) (8)
(4) (4 X 6)
(1) Timing Control Block: It generates internal timing and external control signals for
8237A by er: Point-to-TCP/IP, IP session
(2) Program Command Control Block: It decodes various commands given to the
microprocessor before servicing a DMA request. It also decodes the Mode Control
Word, which is used to select the type of DMA during the servicing
(3) Priority Encoder Block: It prioritizes between the DMA channels requesting service
simultaneously
(4) Internal Registers: The 8237A contains 344 bits internal memory in the form of
registers. The below table gives the name, size, and number of each register
121
DMA (Direct Memory Access)
122
8086 Microprocessor
Introduction
The INTEL 8086 was the first 16-bit microprocessor. It was developed using HMOS (high
density short channel MOS) technology containing 29,000 transistors housed in 40 pin
DIP package. The 8086 does not have an internal clock circuit. The 8086 requires an
external asymmetric clock source with 33% duty cycle. In this chapter we will study the
features, architecture and addressing modes of 8086.
Features of 8086
(1) The 8086 is a 16-bit microprocessor. The term “16-bit” means that its arithmetic
logic unit, internal registers and most of its instructions are designed to work with
16-bit binary words
(2) The 8086 has a 16-bit data bus, so it can read data from or write data to memory
and I/O ports in either 16-bits or 8-bits at a time
(3) The 8086 has a 20-bit address bus, so it can directly access 220 or 1048576 (1 MB)
memory locations. Each of the 1048576 memory locations is byte (8-bit) wide.
Therefore, a sixteen-bit word is stored in two consecutive memory locations
(4) The 8086 can generate 16-bit I/O address, hence it can access 216 = 65536 I/O
ports
(5) The 8086 provides fourteen 16-bit registers
(6) The 8086 has multiplexed address and data bus which reduces the number of pins
needed, but does slow down the transfer of data (draw back)
(7) The 8086 requires one phase clock with a 33% duty cycle to provide optimized
internal timing as shown in the figure It requires 5 MHz clock range
(8) With 8086, it is possible to perform bit, byte, word and block operations. It
performs the arithmetic and logical operations on bit, byte, word and decimal
numbers including multiply and divide
(9) The Ințel 8086 is designed to operate in two modes, namely the minimum mode
and the maximum model. When only one 8086 microprocessor is to be used in a
microcomputer system, the 8086 is used in the minimum mode of operation. In
this mode, the microprocessor issues the control signal required by memory and
I/O devices. In multiprocessor (more than one processor in the system) systems,
the 8086 operates in maximum mode. In maximum mode, the control signals are
generated with the help of the internal bus controller (8288)
123
8086 Microprocessor
TON TOFF
T/3 2T/3
(10) The Intel 8086 supports multiprogramming. In multiprogramming, the code for two
or more processes is stored in memory at the same time and is executed in a
time-multiplexed fashion
(11) An interesting feature of the 8086 is that it fetches up to six instruction bytes
from memory and queue stores them in order to speed up instruction execution
Architecture of 8086
The functional block diagram of the 8086 is shown in the below figure. The Architecture
of 8086 can be divided into two units. These are Bus Interface Unit (BIU) and Execution
Unit (EU). These two functional units can work simultaneously to increase system speed
and consequently the throughput. Throughput is a measure of instruction executed per
unit time.
Memory
Interface
BIU C-Bus
∑ 6
5 Instruction
B-bus 4 Stream
3 Byte
ES
CS 2 Queue
1
SS
DS
IP
Control
System
EU A-Bus
AH AL
BH BL Arithmetic
CH CL Logic Unit
DH DL
SP
BP
SI Operands
DI Flags
124
8086 Microprocessor
Instruction Queue
To speed up program execution, the BIU fetches six instruction bytes ahead of TIME
from the memory. These prefetched instruction bytes are held for the execution unit in
a group of registers called the queue. With the help of the queue it is possible to fetch
the next instruction when the current instruction is in execution. The BIU is fetching and
storing the instructions in the queue. The queue operates on the principle of first in first
out (FIFO). So that the execution unit gets the instructions for execution in the order in
which they are fetched. The size of the queue is 6 bytes in an 8086 processor. The BIU
fetches the instruction code from memory and stores it in the queue. The Execution Unit
(EU) fetches instruction codes from the queue for execution.
125
8086 Microprocessor
SP
15 8 7 0
AX AH AL CS BP
BX BH BL DS SI
CX CH CL ES DI
DX DH DL SS IP
General Purpose Register Segment Register Pointer & Index Register
126
8086 Microprocessor
Usually, the letters H and L specify the higher and lower bytes of a particular register. For
example, CH means the higher 8-bits of the CX register and CL means the lower 8-bits of
the CX register. The letter X is used to specify the complete 16-bit register. The register
CX is also used as a default counter case of string and loop instructions. The BX register
is used as an offset storage for forming physical addresses in case of certain addressing
modes. DX register is a general purpose register which is used as an implicit operand or
destination in case of a few instructions.
Segment Registers
The physical address of the 8086 is 20-bit wide to access 1-Mbyte location. However,
its registers memory locations which contain logical address are just 16-bits wide.
Here 8086 uses mem segmentation. It treats the 1-M byte of memory as divided into
segments, with a maximum size segment as 64 Kbytes. The 8086 allows only four active
segments. The 16 bit segment registers are provided within BIU or the 8086. These four
registers are:
(1) Code Segment (CS) Register
(2) Data Segment (DS) Register
(3) Stack Segment (SS) Register
(4) Extra Segment (ES) Register
These are used to hold the upper 16-bits of the starting addresses of the four memory
segments as shown in the figure on which the 8086 works at a particular time. For
example, the value in CS identifies the starting address of the 64-byte segment known
as code segment. By starting address we mean the lowest addressed byte in the active
code segment. The starting address is also known as base address or segment base.
Physical
address
FFFFFH
7 FFFFH Highest address
127
8086 Microprocessor
The BIU always inserts zeros for the lowest 4-bits (nibble) in the contents of the
segment register to generate 20-bit base address. For example, if the code segment
register contains 348AH, then segment will start at address 348AOH.
Instruction Pointer
The instruction pointer register holds the 16-bit address of the next code byte within the
code segment. The value contained in the IP is referred to as an offset. This value must
be offset from (added to) the segment base address in CS to produce the required 20-bit
physical address. The Instruction pointer is also called as the program counter in other
microprocessors.
Top of code
segment 4489H
3 4 8 A 0
CS
IP +
4 2 1 4
Physical
3 8 A B 4
address
IP = 4214 H Code byte 38AB4H
128
8086 Microprocessor
Flag Register
A Flag is a flip-flop which indicates some condition produced by the execution of an
instruction or control certain operations of the EU. The flag register contains nine active
flags as shows in the Figure.
Six of them are used to indicate some conditions produced by instructions.
The Three Remaining Flags are Used to Control Certain Operations of the Processor
(1) Trap Flag (TF)
One way to debug a program is to run the program one instruction at a time and
see the contents of the used registers and memory variables after execution of
every instruction. This process is called single stepping through a program. Trap
Flag is used for single stepping through a program. If set, a trap is execution after
execution of each instruction, i.e., interrupt service routine is executed which
displays various registers and memory variable contents on the display after
execution of each instruction. Thus, a programmer can easily trace and correct
129
8086 Microprocessor
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
U U U U OF DF IF TF SF ZF U AF U PF U CF
Carry flag-set by
U = Undefined carry out of MSB
Parity flag-set if
result has even
parity
Overflow flag
130
8086 Microprocessor
SP = 9F20 H
SS = 4000 H
Start of stack segment 40000H
SS 40000
+ SP 9F20
Physical address 49F20H
Base Pointer: We can use the BP register instead of SP for accessing the stack using the
based addressing mode. In this case, the 20-bit physical stack address is calculated from
BP and SS.
Source Index: Source Index (SI) can be used to hold the offset of a data word in the data
segment. In this case, the 20-bit physical data address is calculated from SI and DS.
Destination Index: The ES register points to the extra segment in which data is stored.
Storing instruction always uses ES and DI to determine the 20-bit physical address for
destination.
131
8086 Microprocessor
132
8086 Microprocessor
The memory banks are selected when these signals are low (active low). Any memory
location in the memory bank is selected by the address lines A1 to A19.
The organization of memory into two banks and providing bank select signals allows the
programmer to read/write the byte (8-bit) operand in any memory address through 16-bit
data bus. Also, it allows the programmer to read/write the word (16-bit) operand starting
from even address or odd address. There are four possible ways to access the data from
memory. The four ways are as listed below.
(1) 8-bit data from Even (Lower) address bank
(2) 8-bit data from Odd (Higher) address bank
(3) 16-bit data starting from Even address
(4) 16-bit data starting from odd address
Data bus
D8 - D15
Address
D0 - D7
bus
Address
8086 Latches
A1 - A19
A1 - A19
CPU
bus
BHE A0
Odd memory bank select signal Even memory bank select signal
1 MB memory
address space 512 KB odd memory 512 KB even memory
FFFFF H address space address space
FFFFE H FFFFF H FFFFE H
FFFFD H FFFFD H FFFFC H
FFFFD H FFFFB H FFFFA H
FFFF9 H FFFF8 H
⇒
00004 H
00003 H 00007 H 00006 H
00001 H 00005 H 00004 H
00001 H 00003 H 00002 H
00000 H 00001 H 00000 H
Figure: Organisation of Even and Odd memory bank in 8086 based system
133
8086 Microprocessor
Odd Even
X+1 X
X+3 X+2
X+5 X+4
Address D8 - D15 D0 - D7
Data bus
BHE = 1 A0 = 0
Consider an example for loading a byte of data into CH register from the memory
location with an even address. Here, the data will be accessed from the even bank via
the (D0-D7) data bus. Even though this data is transferred into the 8086 over lower 8-bit
lines, the 8086 processor will automatically redirect the data to the higher 8-bit of its
internal 16-bit data path and hence to the CH-register. Such capability permits bytes to
do input-output transfer via the AL register to access I/O device connected to either the
upper half of the data bus or the lower half of the 16-bit data bus.
134
8086 Microprocessor
Odd Even
X+1 X
X+3 X+2
Address bus
A1 - A9 D8 - D15 D0 - D7
BHE = 0 A0 = 0
Odd Even
X+1 X
X+3 X+2
X+5 X+4
D8 - D15 D0 - D7
Address bus
A1 - A9
Data bus
A0 = 0
BHE = 0
BHE = 0 and A0 = 0 ⇒ Both banks enabled
135
8086 Microprocessor
(a) First access from odd address (b) Next access from even address
136
8086 Microprocessor
137