Chapter 4F
Chapter 4F
Table of Contents
4.3 Interrupts
4.3.1 Software interrupts
4.3.2 Hardware interrupts
4.4 Stack memory
4.4.1 Stack Instructions
4.4.2 How data is transferred into stack and retrieved from
the stack using PUSH and POP command?
Summary
Exercise
Glossary
References
4.1 Introduction
After having studied the details of architecture of microprocessor 8085,
it’s various components and functions performed by it we need to go into further details
of how these functions are performed by microprocessor (µP). One of the very important
unit which co-ordinates the interaction between the µP and other devices including
memory is timing and control unit. We will discuss control signals, timing diagrams and
how the process of communication is managed by this unit. Stack memory is a
read/write memory which again plays an important role in the functioning of µP.
Interrupts are externally initiated signals with which the external user can ask µP to
perform some task other than the one which it is performing and depending on the
priority of the task µP has to perform it at that very moment or may even perform it
after sometime. Interfacing devices are special hardware circuits through which the µP
connects to the peripheral devices for e.g. keyboard, printers, display device etc. and the
process through which this connection is made is called interfacing. In this chapter we
will discuss these parameters i.e. timing and control unit, interrupts, stack memory and
interfacing devices in detail.
All these operations are performed within a given time interval, which is
provided by the clock of the system. With reference to the above mentioned operations
certain terms can be defined. The definitions are as follows
1) Instruction cycle: Time required for completing the execution of an
instruction is known as instruction cycle. The 8085 instruction cycle consists of
one to six machines cycles or operations.
2) Machine cycle: It is the time required for completing a single operation. This
operation can be accessing memory for read/write operation or accessing I/O
device. There can be 3 to 6 clock periods or T-states in a machine cycle.
These three cycles can be represented with the help of a diagram which is
shown in Fig.4.1 below.
Instruction Cycle
T1 T2 T3 T4 T1 T2 T3
CLK
1 CLK
M1 (Machine Cycle)
M2 (Machine Cycle)
So far as the timing diagram of this instruction is concerned it consists of two machine
cycles M1—opcode fetch and M2—memory read. M1 consists of 4 T-states and M2 consists
of 3 T-states. Figure 4.2 (a) and (b) show the opcode fetch and memory read machine
cycles respectively.
(3MHz)
A15
20H
A8
(3MHz)
High order address Unspecified
ALE
AD7
24H 3EH
AD0
Low order address Opcode
IO/
So, S1
Figure 4.2 (a) Opcode fetch Machine cycle (M1) for instruction MVI A , byte
M2 (Memory read)
T1 T2 T3
CLK
(3MHz)
(3 A15
20H High order address
5
A8
ALE
AD7
25H data
AD0
Low order address Opcode
IO/M
So, S1
RD
Figure 4.2 (b) Memory read Machine cycle (M2) for instruction MVI A, byte
There are certain points that should be remembered while drawing the timing diagrams
as they make it convenient to draw any timing diagram. These points are:
1) In each instruction cycle, there can be one or more than one machine cycles. The
first machine cycle is always Opcode fetch. It can have four to six T-states.
2) The Memory read cycle requires three T-states
3) As is evident in both the figures that the high order address (A8-A15) bus carries
high order address for the first 3 T-states.
4) ALE (Address Latch Enable) is a positive going pulse which is generated every
time a machine cycle begins and remains positive for one T-state.
5) Low order address bus (AD0-AD7) carries low order address so long as ALE is
positive.
6) Low order address bus (AD0-AD7) acts as data bus as soon as signal goes low.
7) If the µP is interacting with the memory i.e. reading instruction or data from the
memory or writing information into the memory then is low and if µP is
interacting with input or output device than it is high.
Value addition:
1) Memory + Read
2) Memory + Write
3) Input + Read
4) Output + Write
is used when µP is reading from memory and is used when µP is reading from
input device.
is used when µP is writing into the memory location and is used when µP is
sending data to the output device. Figure below shows how the control signals are
generated.
Value addition:
74LS32
IO/M
RD
8085
8085
WR
R
74LS04
4.3 Interrupts
An interrupt can be defined as any signal to the µP that alters the normal
sequence of execution of a program. The interrupt can be introduced in the µP through
an instruction written in the program or it can even be initiated by external device.
Whenever µP receives any interrupt it’s control gets shifted to some other location in
order to execute a set of instructions called service routine which is written at that
location. The µP resumes its operation after completing the service routine. The interrupt
process in 8085 is controlled by the Interrupt Enable flip-flop, which is internal to the
processor and can be set or reset by using software instructions. There exist two types
of interrupts:
a) Software interrupts
b) Hardware interrupts
1) INTR
2) RST 5.5
3) RST 6.5
4) RST 7.5
5) TRAP
a) Vectored interrupts: Vectored interrupts are the ones which have some specific
memory locations on page 00H associated with them and the
control is automatically transferred to the respective memory
location without any external hardware. Example of vectored
interrupt is RST5.5, RST6.5, RST7.5 and TRAP.
b) Non-vectored interrupts: Non-vectored interrupts are the ones in which user has
to specify the address along with the interrupt where the
control is to be transferred. Example of non-vectored
interrupt is INTR.
c) Maskable interrupts: Maskable interrupts are the one which µP need not attend
immediately as and when it comes instead µP can ask it to
wait for some time. Example of maskable interrupt is
RST5.5, RST6.5, RST7.5 and INTR.
d) Non-Maskable interrupts: It is also known as NMI. It is the interrupt which µP has
to attend as and when it comes i.e. it can’t be ignored or
asked to wait. Example of non-maskable interrupt is TRAP.
Value addition:
Value
Before addition:
discussing various interrupts we need to discuss certain instructions in brief.
These instructions are used to enable or disable the interrupts. The instructions are:
RIM: a) EI-
This Enable interrupt
instruction is used to read the status of interrupts RST5.5, 6.5 and 7.5 and
b) DI- Disable
also to read serial interrupt
data input bit. The bits of accumulator in case of RIM command can be
c) SIM-
interpreted Set Interrupt Mask
as follows:
d) RIM- Read interrupt Mask
D7 instruction,
EI : This is 1-byte D6 D5 which
D4 Dsets
3 D2 interrupt
the D1 D0enable flip-flop and enables
the interrupt process, after a system reset the interrupt enable flip-flop, thus
SIDinterrupts.
disabling the I7 I6 ThisI5 instruction
IE 7.5 is 6.5 5.5 to re-enable the interrupts
necessary
(except TRAP).
DI : This is 1-byte instruction, which resets the interrupt enable flip-flop and disables
the interrupt
Serial Input dataprocess. All the interrupts except the TRAP are of
If anyone disabled.
the three bits
bit (D0, D1 and D2) =1 then it
SIM : SIM is a multipurpose one byte instruction used to implies implement
that thethe 8085
respective
interrupts (RST5.5, 6.5 and 7.5) and serial data output. interrupt is masked. More of the
The interpretation
accumulator If contents
bit = 1 forthenSIM
theinstruction can be understood with the help of bit-
than one interrupts can
pattern shown below:
interrupts are pending
also be masked
If D3=1 then the
D7 D6 D5 D4 D3 D2 D1 simultaneously
D0
Interrupt Enable
SOD SDE XXX R7.5Flip-flop MSE is set
M7.5 M6.5 M5.5
control to reset
RST7.5
INTR: While executing a program, the µP checks the INTR line on execution of each
instruction. If the interrupt enable flip-flop is set and INTR is high, the µP after executing
the current instruction resets the interrupt enable flip-flop and sends interrupt
acknowledge signal ( ). In order to attend any other interrupt the µP has to enable
interrupt enable flip-flop again.
With the help of INTR interrupt the user can also extend the interrupt capability
of 8085 µP. The interrupt controller device used for this purpose is IC8259, which helps
in catering upto eight peripheral devices.
RST 7.5, RST 6.5, RST 5.5: All the three interrupts are vectored and maskable
interrupts. In order to enable these interrupts the µP requires two instructions:
a) EI (Enable Interrupt)
b) SIM (Set Interrupt Mask)
INTR
Level triggered
RST5.5
Level triggered
RST6.5
Level triggered
RST7.5
Edge triggered
TRAP
Level and edge
triggered
The stack memory can be described as a set of memory locations in the R/W
memory that are used to store binary information temporarily during the execution of a
program. The stack memory is used by both µP and programmer.
Whenever µP comes across any interrupt or subroutine the sequence of
program execution is altered, in such a situation µP automatically places the address of
the memory location present in the program counter on to the stack and after
executing the interrupt or the subroutine the µP returns back to the original program
by checking the address present in the stack.
Similarly the contents of the register can be stored on to the stack and
retrieved from the stack by the programmer. During the execution of a program
sometimes it becomes necessary to save the contents of certain registers and data in
memory so that the registers may be used for other operations. After completing these
operations the contents saved in memory can be transferred back to the registers.
Memory locations for this purpose are set aside by the programmer in the beginning.
The set of memory locations kept for this purpose is called stack.
Stack pointer is initialized in the beginning of the program by using the
instruction LXI SP. This instruction loads the stack pointer register with the 16-bit
memory address. Any area of the RAM can be used as stack but to prevent the
program from being destroyed by the stack information, it is a general practice that the
beginning of the stack is at the highest available memory location. The stack memory
is based on last in first out principle (LIFO). The entering of data into the stack is called
‘PUSH’ operation and retrieving data from the stack is called ‘POP’ operation. The stack
pointer always holds the address of the stack top.
Value addition:
LXI Rp: Load register pair immediate: It is a 3-byte command and is used to load the
specified register pair with 16-bit data. For example if we want to load 3075H in
register pair DE then the instruction is written as:
POP Rp: Pop off Stack to register pair: It is 1-byte instruction used to copy the
contents from the stack memory to the register pair. When POP instruction is executed
then following steps occur:
Suppose stack pointer contains memory address 3050H and data byte stored in 3050H
is A7. The memory location 3051H contains C2, then on using POP B following steps
are executed:
The contents of memory location 3050H i.e. A7 are transferred to low-order
register C
Stack pointer is incremented by one to get the new value (SP+1) i.e. 3051H
The contents of 3051H i.e. C2 is transferred to high-order register B and now
the contents of register pair BC = C2A7
The stack pointer is again incremented to get a new value (SP+1) i.e. 3052H
Therefore it is seen that when POP instruction is executed the contents of the memory
location pointed out by the stack pointer register are copied to the low-order register
(such as C, E, L and flag) of the operand. The stack pointer is incremented by 1 and
the contents of that memory location are copied to the high-order register (B, D, H, A)
of the operand.
PUSH Rp: Push register pair onto the stack: It is 1-byte instruction used to copy the
contents of the register pair onto the stack. When PUSH instruction is executed then
following steps occur:
Suppose stack pointer contains memory address 2058H, register D contains 5AH and
register E contains 63H, then on using PUSH D following steps are executed:
Stack pointer (SP) is decremented by one i.e. (SP-1) which here happens to be
2057H.
Contents of register D (High order register) i.e. 5AH are copied into memory
location 2057H (MSP-1)
Stack pointer is again decremented by one i.e. (SP-1) which now becomes
2056H.
The contents of register E (Low order register) are copied into the new value of
memory location (MSP – 1) i.e. 2056H.
Therefore in general we can say that when PUSH command is used the memory
location address present in the stack pointer register is decremented and the contents
of the high-order register (B, D, H, A) are copied into that location. The stack pointer
register is decremented again and the contents of the low-order register (C, E, L and
flag) are copied to that location.
The commands used for writing into the stack memory and reading from it are
PUSH and POP. The details of how these commands work are discussed in the next
section. These instructions that write and read from the stack are called stack
instructions. In these instructions indirect addressing mode is used, because a 16-bit
register called stack pointer (SP) holds the address of the desired memory location.
4.4.2 How data is transferred into stack and retrieved from the stack
using PUSH and POP command?
Suppose register B contains 6AH and register C contains B7H and we want to
transfer this data to register pair DE using stack then first of all we write a short
program for this purpose. Here we are explaining function of each instruction in the
program with the help of diagrams.
3000 LXI SP, 3079H This instruction loads stack pointer register
6AB7H.
A F
B 6AH C B7H
D E
H L
SP 3079H
A F
B 6AH C B7H
D E
H L B7H 3077
A F
B C
D 6AH E B7H
H L
SP 3079H
Figure 4.6: Contents of Register and stack memory after POP instruction is executed
Interfacing devices are basically hardware circuits that are specially designed
to connect µP to external or peripheral devices like display unit, keyboard, printer or any
other input/output device. The process through which this connection is made is called
interfacing. This becomes clearer with the help of diagram shown below:
8085
In this chapter we will give a brief idea of some of the commonly used Programmable
Peripheral Interfacing (PPI) devices/chips\ with 8085 microprocessor.
The Intel 8155 is a 40-pin IC. It contains 256 bytes RAM, two
programmable I/O ports and a timer so it can be used as I/O interfacing chip or as a
memory chip or as a timer chip. The IC 8156 is identical to the chip 8155 except that
8156 accepts active high chip enable (CE) signal and 8155 an active low CE signal. The
main features of 8155/8156 can be summarized as follows:
The 8155 chip is specifically designed to be compatible with the 8085 µP, because
control signals like , and and special signal like ALE from 8085 can be
directly connected to the device which in turn eliminates the need for generating control
signals like , , and , not only this it even eliminates the
requirement of external demultiplexing of the low-order address bus AD7-AD0.
Direct Memory Access is an I/O technique which is commonly used for high
speed data transfer. In this technique the µP leaves it’s control over the buses to a
DMA controller device. This DMA controller device manages data transfer between
memory and peripheral device, thus bypassing the microprocessing unit. The DMA
controlled data transfer does not require software; hence, it is faster than the µP
controlled data transfer. This technique is used in any system that requires a high
speed data transfer for example CRT system, hard disk drive system etc. The 8257
DMA controller consists of following parts:
The 8237 is also a DMA controller device specially designed to improve the
systems performance. It allows the peripheral devices to directly transfer
information from the system memory. Unlike 8257, memory-to-memory transfer
capability is also provided in 8237.
SUMMARY
In this chapter we have discussed some of the very important units and
features of 8085 µP like timing and control unit, stack memory, interfacing devices
and interrupts. Timing and control unit provides synchronization between the slow
peripheral devices and microprocessor. Timing diagrams and the calculations of
execution time of an instruction has also been discussed.
What is stack memory and how it is used by the microprocessor and the
programmer has been explained in detail. Commands like PUSH and POP have also
been discussed.
Programmable Peripheral Interfacing devices like IC 8155, 8255, 8279, 8257
etc. have been briefly explained as to how they are used for interfacing different
peripheral devices with 8085 µP and some of their salient features have also been
mentioned.
Interrupt, which is an important feature of 8085 µP has been discussed.
Different interrupts and commands required for implementing these interrupts have
also been explained.
EXERCISES
(3) For how many T-states ALE remains high during a machine cycle?
Correct answers
(1)
1) Control signal used when microprocessor
(2) Timing diagramreads from Input device_________.
Institute of (3)
Lifelong ALE(Address
Learning, Latch Enable)
University
2) Graphical representation of the time taken by the ofµPDelhi
to fetch, decode and
(4) RIM
execute an instruction is known as ___________________.
(5) PUSH
3) A positive going pulse which is generated every time machine cycle
(6) Accumulator, Flags
begins___________.
(7) Interfacing devices
Microprocessor 8085 – Timing and control; Interrupts; Stack
Memory; Interfacing devices.
3 Subjective questions
GLOSSARY
Stack memory: It is a read/write memory which is used for temporarily storing the
data during the execution of a program. Stack memory is shared by both the µP and the
user.
Interrupt: It is an externally initiated signal through which the user can ask the µP to
perform some other task in between the program it is executing.
Interfacing: The process through which the peripheral devices are connected to the µP
is known as interfacing.
Service routine: A set of instructions which the µP executes on any interrupt request.
Instruction decoder: It identifies the instruction, takes the information from instruction
register and decodes or translates the instruction to be performed.
Polling: Polling is a commonly used method in which the processor checks all the
devices in sequential order to see if it requires service or not. However this technique
wastes a lot of processor time, as it checks the status of all the devices all the time.
References
1. Suggested readings