A Notebook On Microprocessor System: August 2012
A Notebook On Microprocessor System: August 2012
net/publication/299514203
CITATIONS READS
0 19,929
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Shree Krishna Khadka on 31 March 2016.
Prepared By
Er. Shree Krishna Khadka
teaching.official @gmail.com
Inside
1. Microprocessor – An Introduction
2. Microprocessor Instructions
3. Assembly Language Programming
4. Bus Structure and Memory Devices
5. Input/Output Interface
6. Interrupts
7. Programming with 8085 and 8086
HW HIC GSSE
BLEX IV
Chapter: 1 Introduction
1.1 Introduction to Development of Computer -------------- 002
1.1.1 Historical Background -------------------------- 002
1.1.2 Automated Calculator --------------------------- 003
1.1.3 Stored Program Computer ------------------------ 003
1.1.4 The Von-Neumann Architecture ------------------- 004
1.1.5 Harvard Architecture --------------------------- 004
1.1.6 Von-Neumann Architecture Vs Harvard Architecture 005
1.2 Microprocessor --------------------------------------- 006
1.2.1 Introduction ----------------------------------- 006
1.2.2 Microcomputer ---------------------------------- 006
1.2.3 Evolution of Microprocessor -------------------- 007
1.2.4 Microprocessor as Programmable Device ---------- 007
1.2.5 Microprocessor as CPU -------------------------- 007
1.3 Microprocessor Based System -------------------------- 008
1.3.1 Address Bus ------------------------------------ 009
1.3.2 Data Bus --------------------------------------- 009
1.3.3 Control Bus ------------------------------------ 009
1.4 Microprocessor Architecture -------------------------- 010
1.4.1 8085A CPU -------------------------------------- 010
1.4.2 Description of 8085A Block Diagram ------------- 012
1.4.3 Description of 8085A Pin Diagram --------------- 014
1.4.4 Application of 8085A Microprocessor: MCTS ------ 018
1.4.5 INTEL 8086 CPU --------------------------------- 020
1.4.6 Description of 8086 Block Diagram -------------- 020
1.4.7 Description of 8086 Pin Diagram -------- 024
1
HW HIC GSSE
BLEX IV
1
HW HIC GSSE
BLEX IV
1
HWHIC
…
BLEX
Microprocessor
Introduction
Contents:
…
BLEX
Microprocessor
Historical Background
Computer is the most efficient and versatile electronic machine, basically developed by the
enhancement of calculator. Charles Babbage, the father of computer developed the
mechanical computer named “Difference Engine” and “Analytical Engine”.
o The Difference engine could perform the arithmetic operations like add and subtract. But
it could perform only single algorithm. Its output system was compatible to write on
medium such as punch card and early optical disk.
o The Analytical engine provides more advanced features in comparison to Difference
engine. It consists of mainly four components.
The store is used to hold the variables and results. The mill accepts operands from the store
and performs addition, subtraction, multiplication or division and returns a result back to store.
It reads the instruction and data from punched cards operates on it and have the results back to
the store or writes to the punch card.
The evolution of vacuum tubes led to the development of computer of new era. The world
first general purpose computer was ENIAC (Electronic Numerical Integrator and
Calculator). It was constructed in 1940 under the supervision of John Mauchly and John
Presper Eckert at the Universities of Pennsylvania. The ENIAC built by using vacuum tubes
was enormous in size and consumed very high power. However it was faster than mechanical
computers. The ENIAC was a decimal machine in which numbers were decimal number system
and the operation was performed in the same numbering system. Its memory consisted of 20
accumulators each capable of holding 10 digit decimal numbers. The major drawback of ENIAC
was that it had to be programmed manually by setting switches and plugging and unplugging
cables.
…
BLEX
Microprocessor
Automated Calculator
An automated calculator is a data processing device that carries out logic and arithmetic
operation but has limited capability for the user. The calculator accepts data from a small
keyboard one digit at a time performs the arithmetic and logic calculation and shows the result
on the visual display i.e. LCD or LED. The calculators programs are stored in ROM while the
data that the user enters in RAM.
Features:
Store program computer is one of the most important breakthroughs in the entire field of
information technology. Stored program computer are those where the program (instruction) are
stored in same memory locations and brought into processor and decoded to perform the
intended operations. The idea was first glimpsed by Ada Lovelace & Charles Babbage in
1840’s; later in 1946 Von Neumann and his colleagues began the design of new stored
program computer called IAS (Institute of Advance Studies) in Princeton, NJ, USA.
Program
Control Unit
…
BLEX
Microprocessor
Since, the task of entering and altering the programs for the ENIAC was extremely tedious.
The programming process could be facilitated if the program could be facilitated if the program
could be represented in a form suitable for storing in memory alongside the data. Then a
computer could get its instructions by reading them from the memory and a program could be
set or altered by setting the values of a portion of memory. This approach was based on
“Stored Program Concept” and was first adopted by John Von Neumann. The general
structure of Von Neumann’s machine is shown below.
The main memory is used to store both data and instructions. The arithmetic logic unit is
capable of performing arithmetic and logical operations on binary data. The program control
unit interprets the instructions in memory and causes them to be executed. The I/O unit gets
operated from the control unit.
Harvard Architecture
This architecture based computer consists of separate memory spaces for the program and
data. Each memory space has its own address and data buses. As a result of this both instruction
and data can be fetched from memory concurrently. This feature provides a significant
processing speed improvement when compared with microprocessor devices based on Von-
Neumann type architecture.
…
BLEX
Microprocessor
…
BLEX
Microprocessor
Microprocessor
Introduction
Memory
Micro-
processor Input
Output
This system may be simple or sophisticated, depending on its applications and recognized
by various names depending upon the purpose for which it is designed. The microprocessor
applications are classified primarily in two categories:
o Reprogrammable Systems.
o Embedded Systems.
In embedded systems, the microprocessor is a part of a final product and is not available for
reprogramming to the end user. A copying machine is a typical example of an embedded
system.
Microcomputer
The microprocessor when embedded in a larger system can be a standalone unit controlling
processes or it can function as a CPU of a computer is called microcomputer. So, a computer
designed using a microprocessor as its CPU is the microcomputer.
…
BLEX
Microprocessor
Evolution of Microprocessor
The microprocessor is essentially the product of research and development in two allied
fields: digital computer and semiconductor technology. Recognition as the first digital computer
is given to a machine called ENIAC, which was designed in 1940. After the development of
transistor in 1948 and development of integrated circuit, mainframe computer was developed in
1960’s and mainframe followed it.
The first microprocessor Intel 4004 was announced in 1971 by Intel Corporation. The
Intel 4004 was the first chip to contain the entire component on a CPU in a single chip. It was a
4-bit microprocessor which was shortly replaced by Intel 4040. At the same time Rockwell
International’s PPS4 and Toshiba’s T3 472 were developed.
The first 8-bit microprocessor 8008 was introduced again by Intel in 1972 that was followed
by a better version the 8080 from the same company. Some other 8-bit microprocessor like
Motorola’s M6800, National Semiconductors SC/MP, Zilog Corporation’s Z800, Fair
Child’s F8 and Intel 8005. Since then Intel & Motorola are leading companies for developing
microprocessor. After that Intel 8086, 80186, 80286, 80386, 80486 & Pentium Series whereas
Motorola 6802, 68000 etc. were developed.
Microprocessor has a several set of instruction embedded in its memory to perform the
various task intended by the programmer. Thus the fact that the microprocessor is
programmable means it can be instructed to perform given tasks within its capability.
…
BLEX
Microprocessor
Microprocessor
Input Output
as a CPU
Memory
ADDRESS BUS
I/O Port
M
M E
M Input
P O Port
U R
Y
Output
Port
CONTROL BUS
DATA BUS
…
BLEX
Microprocessor
All these operations part of the communication and processing of data between the
microprocessor and peripheral devices (including memory). To communicate with the
peripheral or a memory, the microprocessor needs to perform the following steps.
Step 1: Identify the peripheral or memory location with its address.
Step 2: Transfer binary information (data and instruction) using buses.
Step 3: Provide timing and synchronization signals.
In 8085 microprocessor all these functions are performed by using three sets of
communication lines called Buses. They are Address Bus, Data Bus and Control Bus as shown
in figure. In other word, it can also be called as “Three Bus Architecture System”.
Address Bus
In a microcomputer system each peripheral or memory location is identified by a binary
number called an address and the address bus is used to carry the address. The address bus is
unidirectional i.e. bit flows in one direction from the microprocessor to memory or peripheral
devices. The microprocessor uses the address bus to perform the first function mentioned in step
one. The width of the address bus clearly determines the maximum possible memory capacity of
the system.
In Intel 8085, there is 16-bit address, so it has capability of addressing memory up to 64 KB.
Data Bus
The data bus is a group of lines used to carry the data between various components of
microcomputer system. Data bus is bidirectional i.e. data flows in both direction between the
microprocessor and memory and peripheral devices. The microprocessor uses the data bus to
perform the second function mentioned in step 2.
In Intel 8085, there is 8-bit data bus so it can process 8-bit of data at a time. That’s why it is
called 8-bit microprocessor.
Control Bus
The control lines are somewhat different from address bus and data bus. The control bus is
comprised of various single lines that carry timing or synchronization signals. The
microprocessor uses the control bus to perform the third function mentioned in step 3.
The microprocessor generates specific control signals for every operation such as memory
read\write or I\O read\write. Some of the control signals are:
o Memory Read: It causes data from the memory to be placed on the data bus.
o Memory write: It causes the data on the data bus to be loaded into the memory.
o I\O Read: It causes data from the addressed I\O port to be placed on data bus.
o I\O Write: It causes the data on the data bus to be outputted to the addressed I\O port.
o Interrupt Request: Indicate that interrupt has been pending.
…
BLEX
Microprocessor
Microprocessor Architecture
o A microprocessor has general purpose and special purpose registers. The general purpose
registers are use for storing intermediate data and operands. The special purpose registers
are the Accumulator, Program Counter and Stack Pointer.
o The Accumulator is used to store operands and/or to store the result of operations.
o The program counter and stack pointer registers are used to keep track of the memory
location from where the next instruction is to be fetched and location of the most recent
stack entry, respectively.
o The ALU in the microprocessor can add and operand and operand in the accumulator to an
operand in another register or add and operand in the accumulator with data specified by the
program. It can also carryout the Boolean operations and shift operations.
o The control circuitry in the microprocessor is responsible for issuing signal to control
functions of various components within as well as external to the microprocessor as per the
instruction executed. All the operations are coordinated by clock signals.
…
BLEX
Microprocessor
…
BLEX
Microprocessor
1. Register
The 8085A has both 8-bit and 16-bit registers. It has 8-bit registers: B, C, D, E, H, L, A
(Accumulator) & F (Flag) and 16-bit registers: PC (Program Counter), SP (Stack Pointer)
& IR (Instruction Register). The PC and SP are addressable while IR is not. The registers of
8085A can be classified as:
o General Purpose Registers
o Special Purpose Register
1.1 General Purpose Registers
B, C, D, E, H and L are 8-bit general purpose registers and can be used either single
or as 16-bit register pairs BC, DE and HL. When used in the register pair mode, the high
order byte resides the first register and the low order byte in the second.
High Low
Order Order
Byte Byte
B C
Fig: BC Register Pair
Whereas register pair HL can be used as two independent 8-bit registers, functions
as a data pointer. It can hold memory addresses that are referred to a number of instructions,
which use ‘Register Indirect Addressing’. Hence, general purpose registers are used to
temporarily store operands or intermediate data in calculations.
o Accumulator
The accumulator (register A) is an 8-bit register accessible to the programmer. This
register is used to store 8-bit data and to perform arithmetic and logical operations. It is part
of the arithmetic and logical unit because one of the operand in the ALU operation is an
accumulator. The result of the operations is also stored in the accumulator. It is also to
access the data from the input output ports. When the data is read from input port, it is first
moved to the accumulator. Similarly, when data is send to the output port, it must be first
placed in the accumulator.
o Flags
Registers containing of five flip-flops which are set or reset according to the arithmetic
and logical operation and result in accumulator is known as flag register and each flip-flops
are flags. These flags are Carry (CY), Zero (Z), Sign (S), Parity (P) and Auxiliary carry
(AC). The microprocessor uses these flags to test data condition and for decision making
processes. These are described below.
…
BLEX
Microprocessor
S Z × AC × P × CY
D7 D6 D5 D4 D3 D2 D1 D0
The Carry Flag (CY): If an arithmetic operation results in a carry, the carry flag is set
otherwise it is reset. The carry flag also serves as a borrow flag for subtraction.
The Zero Flag (Z): The zero flag is set if the ALU operation results in zero otherwise it
is reset. This flag is modified by the results in the accumulator as well as in other
registers.
The Auxiliary Carry (AC): In an arithmetic operation when a carry is generated by digit
D3 and passed onto the digit D4, the AC flag is set otherwise it is reset. This flag is used
in BCD arithmetic.
The Parity Flag (P): Since 8085 operates in even parity, parity flag is set when the result
of arithmetic and logical operation has even number of 1’s. Otherwise it is reset.
The Sign Flag (S): If the bit D7 or MSB (most significant bit) of the result is 1, the sign
flag is set. This flag is used with signed number. If D7 is 1, the number will be viewed as
negative; if it is 0, then it will be viewed as positive.
o Program Counter:
This is 16-bit register and used by microprocessor to sequence the execution of
instructions. A computer program consists of sequence of coded instruction. These
instructions are stored sequentially in the memory location. As the 8085 begins to execute an
instruction, the memory address of the first instruction to be executed is placed in program
counter. So it contains the memory address from which the next byte is to be fetched. Hence
the microprocessor uses these registers to sequences the execution of instruction.
o Stack Pointer
A stack is an area of memory set aside for the purpose of storing data by operation
known as stacking. As data is stored and retrieved, its location is specified by a 16-bit
register known as the stack pointer. The beginning of the stack is defined by loading a 16-bit
address on the stack pointer.
The stack pointer register holds the address of the last byte written into the stack. The
stack pointer is decremented automatically each time data is pushed onto the stack and is
incremented automatically when the data is popped off the stack.
o Temporary Register
The temporary register is an 8-bit register which is not accessible to the programmer.
These registers are internally used by the microprocessor to hold 8-bit data during the
execution of some instruction as a ‘Memory Reference’ instruction such as reading data
from a given address of memory or writing data to a given address of memory.
…
BLEX
Microprocessor
The ALU performs the arithmetic operations like add, subtract etc and logical operations
like AND, OR, XOR etc. Besides this ALU carries out left and right shifting of the 8-bit data
stored in accumulator. When ALU perform arithmetic and logical operations one of the data is
stored in accumulator and the result of the operations is also referred to the accumulator itself.
The flags are affected by the arithmetic and logical operations in ALU.
This unit synchronizes all the microprocessor operations with the clock and generates the
control signals necessary for communications between the microprocessor and peripherals. The
RD and WR signals are sync pulses indicating the availability of data on the data bus.
The control circuitry is responsible for all the operation. All the operations are driven by the
clock signal. All operations are synchronously timed according to the clock signals. This
includes the following stages:
The control circuitry is also responsible for interaction with signals external to the CPU e.g.
receiving signals like interrupt request and wait request.
…
BLEX
Microprocessor
X1 1 40 VCC (+5V)
X2 2 39 HOLD
SID 5 36 RESET IN
TRAP 6 35 READY
RST 6.5 8 33 S1
RST 5.5 9 32 RD
10 31
INTR 8085A WR
INTA 11 30 ALE
AD0 12 29 S0
AD1 13 28 A15
AD2 14 27 A14
AD3 15 26 A13
AD4 16 25 A12
AD5 17 24 A11
AD6 18 23 A10
AD7 19 22 A9
(GND) VSS 20 21 A8
…
BLEX
Microprocessor
1. Address Bus
The 8085 has eight signal lines (A15-A8), which are unidirectional and used as a higher order
address bus.
This group of signal includes two control signals ( RD & WR ), three status signals ( IO / M ,
S1 & S0) to identify the nature of operation and one special signal (ALE) to indicate the
beginning of the operation. These signals are described below.
o RD - Read
This is an active low Read control signal that indicates the selected I\O or memory device is
to be read and data are available on the data bus.
o WR - Write
This is a write control signal (active low). This signal indicates that the data on the data bus
are to be written into a selected memory or I\O location.
…
BLEX
Microprocessor
o INTR (Input): This pin is interrupt request used as a general purpose interrupt.
o INTA (Output): This is an interrupt acknowledge pin used to acknowledge an
interrupt.
o Restart Interrupt: There are three restart interrupt; RST7.5, RST6.5 and RST5.5 in
8085. These are vectored interrupt and transfer the program control to specific memory
locations. They have higher priorities than the INTR interrupt. Among these three the
priority order is as 7.5, 6.5 and 5.5.
o TRAP (Input): This is a non mask able interrupt and has a highest priority.
o HLDA (Output): This hold acknowledge signal. This signal acknowledges the HOLD
request.
o READY (Input): This signal is used to delay the microprocessor read or write cycles
until a slow responding peripheral is ready to send or accept data. When this signal goes
low, the microprocessor waits for an integral number of clocks until it goes high.
o RESET IN: When the signal on this pin goes low, the program counter is set to zero, the
buses are tri-stated and the microprocessor is reset.
Prepared By: SriKisna Khadka 17
2006 Batch
HWHIC
…
BLEX
Microprocessor
o RESET OUT: This signal indicates that the microprocessor is being reset. This signal
can also be used to reset other devices.
o Directly compatible with TTL IC’s leading to low cost of integrating the complete
microprocessor based system.
o 8085- based microprocessor
o Performing the high speed arithmetic and logic operations.
Based on the concepts we discussed in the general instrumentation system, we can examine
a typical microprocessor controlled temperature system. This system is expected to read the
temperature in a room, display the temperature ate a liquid crystal display (LCD) panel, turn on
fan if the temperature is above a set point, and turn on a heater if the temperature is below a set
point.
Temperature
Sensor
A/D
Fan Heater
Converter
Micro
Processor
LCD
Fig: Microprocessor Controlled Temperature System
…
BLEX
Microprocessor
Microprocessor:
The above figure shows a processor with a system bus. The processor will read the binary
instructions from memory and execute those instructions continuously. It will read the
temperature, display it at the LCD display panel, and turn on/off the fan and the heater based on
the temperature.
Memory:
The system includes two types of memory. ROM will be used to store the program, called
the monitor program that is responsible for providing the necessary instructions to the processor
to monitor the system. This will be a permanent program stored in ROM and will not be altered.
The R/W memory is needed for temporary storage of data.
Input:
In this system, we need a device that can translate temperature into an equivalent electrical
signal; a device that translates one form of energy into another form is called a transducer. On
these days temperature sensors are available as integrated circuits. A temperature sensor is a
three-terminal semiconductor electronic device that generates a voltage signal that is
proportional to the temperature However, this is an analog signal and since the processor is
capable of handling only binary bits. Therefore, this signal must be converted into digital bits.
The analog-to-digital converter performs that function. It is an electronic semiconductor chip
that converts an input analog signal into the equivalent eight binary output signals. In
microprocessor-based systems, devices that provide binary inputs are connected to the processor
using devices such as buffers called input ports. In our system A/D converter is an input port,
and it will be assigned a binary number called an address. The microprocessor reads this digital
signal from the input port.
Output:
The above figure shows three output devices: fan, heater and liquid crystal display (LCD).
These devices are connected to the processor using latches called output ports.
Fan: This is an output device, identified as Port 1 that is turned on by the processor when
the temperature reaches a set higher limit.
Heater: This is also an output device, identified as Port 2 that is turned on by the processor
when the temperature reaches a set lower limit.
Liquid Crystal Display (LCD): This display is made of crystal material placed between
two plates in the form of a dot matrix or segments. It can display letters, decimal digits, or
graphic characters. The LCD in above figure will be used to display temperatures.
…
BLEX
Microprocessor
The 8086 is a far more powerful 16-bit machine with 1 MB memory capacity, in addition to
wider data path and larger registers. It has a feature of instruction pipelining. For this purpose it
consists of an instruction cache that pre-fetches a few instructions before they are executed. It
has 16- bit wide data bus and can operate on 16-bit of data from memory and ports.
Both these units are designed to work simultaneously. The BIU is designed to function as
the external interface of the processor. The BIU generates address and sends them on the
address bus and then reads (or writes) data from memory (and ports) through the data bus.
Therefore BIU acts an interface of execution unit to the outside world.
The EU handles all controlling functions such as reading and writing the data, decoding the
instruction and executing the instruction. Block diagram of internal architecture of 8086
microprocessor is shown and described below.
The Bus Interface Unit can be divided into the following sub-units.
1. Instruction Queue:
The Instruction Queue is a 6-byte First-In-First-Out (FIFO) register which fetches
6 bytes of instruction from memory ahead of time. It helps to speed up execution of
program by overlapping instruction fetch with execution and this mechanism is known
as pipelining.
t1 t2 t3 t4 t5 t6
BIU Inst. fetch Inst. fetch Inst. fetch Inst. fetch Inst. fetch
EU Execution Execution Execution Execution Execution
Pipelined Execution
8086
…
BLEX
Microprocessor
2. Instruction Pointer:
The instruction pointer stores the offset of the physical address in the segment of
memory as defined by the segment registers.
3. Segment Registers:
The 8086 has memory segmentation. Memory segmentation allows the 8086
microprocessor to be able to access four 64 Kbytes segments within its 1 MB memory
range at any given time. These four segments registers are:
o Code Segment Register (CS): All the instruction are located in memory (Code
Segment) pointed by the 16-bit code segment register and a 16-bit offset contained
in the instruction pointer (IP). The BIU computes 20-bit address called physical
address by using the content of CS and IP register.
o Data Segment Register (DS): The data segment register points to the current data
segment. Operands for the instruction are fetched from this segment.
o Stack Segment Register (SS): The stack segment register points to the current
stack.
o Extra Segment Register (ES): The extra segment register points to the extra
segment in which data (in excess of 64 K pointed to the DS) is used. String
instruction always uses extra segment.
…
BLEX
Microprocessor
o Index Registers:
The two index register Source Index (SI) and Destination Index (DI) are used in
indexed addressing mode.
o Flag Register:
The 8086 has a 16-bit flag register which contains nine active flags. These active
flags can be divided into two types.
× × × × OF DF IF TF SF ZF × AF × PF × CF
Fig: 8086 flag register
Conditional Flags:
The flag register in the EU, holds the conditional/status flags. These flags are
set or reset on the basis of result generated from the ALU. Out of nine, the 8086
has six status flags. They are:
1. Auxiliary Carry Flag-AF: It is set if a carry from the lower nibble into the
higher nibble or borrow from higher nibble into the lower nibble of the low
or high 8-bits of 16-bit number. This flag is used by BCD arithmetic
instruction; otherwise it remains reset.
2. Carry Flag-CF: It is set if a carry from addition or borrow from subtraction
is produced otherwise remains reset.
3. Overflow Flag-OF: It is set if arithmetic overflows, i.e. if the size of the
result exceeds the capacity of the destination location.
4. Sign Flag-SF: It is set if the most significant bit of the result is 1; otherwise
it is zero.
5. Parity Flag-PF: It is set if the result has even parity and remains zero for odd
parity of the result.
6. Zero Flag-ZF: It is set if the result is 0. Zero flag is 0 for non zero result.
Control Flags:
The 8086 contains three control flags which are used for controlling the
microprocessor. The control bits in the flag register can be set or cleared by the
programmer.
1. Trap Flag-TF: It is used for single stepping through a program.
2. Interrupt Flag-IF: When the interrupt flag is set a program can be interrupted
for other more important operations.
3. Direction Flag-DF: It is used with string operation.
…
BLEX
Microprocessor
The arithmetic and logic unit of 8086 microprocessor can perform various arithmetic and
logical operation on 16-bit data.
System Buses
Address Data
Bus Bus
External
Control
Signal
General
Purpose
Register
I
AH AL 6 N
S
BH BL T
5 R
CH CL U
Instruction C
6
Decoder 4 T
-
DH DL I
B
and 3 O
Y
BP Control T
CS N
E
Index subsystem
DI 2 Q
and ES Segment U
Pointer SI Register E
SS 1 U
Register E
SP DS
Instruction Pointer
ALU
Flags
…
BLEX
Microprocessor
Encoding of S3 and S4
S5 and S6
S4 S3 Segment Register Employed
0 0 ES The S5 status signal is
0 1 SS the interrupt enable flag
1 0 CS or None bit whereas bit S6 is
always at logic 0.
1 1 DS
o BHE (Bus/Bank High Enable)/S7: The 8086 has a 20-bit address bus and each address can
store 8-bits of data. So when the instruction is executed, the word is actually written into
two consecutive memory locations. It will take two machine cycles, as it needs to write the
data two times in memory. So to make it possible to read or write a word in one machine
cycle, the memory for 8086 is set up as two ‘Banks’.
One memory bank contains all the bytes which have even addresses. The data lines of
this memory bank are connected to the lower eight data line D0-D7of 8086.
The memory bank contains all the bytes which have odd addresses. The data lines of this
memory bank are connected to the higher eight data line D8-D15 of 8086.
Address line A0 is used to enable the memory device in the lower bank. When A0
become low, it selects the lower bank memory devices as it indicates the even address.
Address lines A1 through A19 are used to select the desired memory location in upper and
lower bank of memory.
…
BLEX
Microprocessor
BHE signal is use to enable the upper memory bank. BHE in conjunction with A0
determines whether a byte or words will be transferred from/to memory location as show
below.
During T2 and T4, the status line S7 is transmitted and it remains always high.
o RESET: It is a system reset and an active high signal. When it goes high the microprocessor
goes into reset state.
o TEST: This signal is used to test the status of math coprocessor 8087. The BUSY pin of
8087 is connected to the TEST pin of 8086.
Sometimes the 8086 needs the result of some computations that 8087 is doing,
before it could go to the next instruction of the program. When 8087 is busy, it sends the
high signal on TEST pin, which cause 8086 to wait in an idle state. When 8087 complete
computation, it makes BUSY signal low, thereby making TEST signal low. When TEST
signal become low the 8086 goes to the next instruction.
o ALE: This signal is used to latch the address into the address latch (8282/8283).
…
BLEX
Microprocessor
GND 1 40 VCC
AD0 2 39 AD15
AD1 3 38 A19/S6
AD2 4 37 A18/S2
AD3 5 36 A17/S1
AD4 6 35 A16/S3
AD5 7 34 BHE/S7
AD6 8 33 MN/MX
AD7 9 32 RD
AD10 12 29 WR (LOCK)
INTEL 8086
AD11 13 28 M/IO (S2)
AD14 16 ×
NMI 17 ×
INTR 18 ×
CLK 19 ×
GND 20 ×
RESET 21 ×
READY 22 ×
TEST 23 ×
(QS1)INTA 24 ×
(QS0)ALE 25 ×
…
BLEX
Microprocessor
Microprocessor Instruction
Contents:
o Definitions
o Instruction Description
o Instruction Sheets & Instruction Format
o Register Transfer Language
o 8085 & 8086 Addressing Modes
o 8085 Instruction Set
o 8085 Machine Cycles & Timing Diagram
o 8085A MP Machine Codes
o Counters & Time Delays
…
BLEX
Microprocessor
Definitions
Instruction
Computer instructions are normally stored in central memory locations and are executed
sequentially one at a time. The control reads an instruction from a specific address in memory
and executes it. It then continues by reading the next instruction in sequence and executes it, and
so on. This type of instruction sequencing needs a counter to calculate the address of the next
instruction after the execution of the current instruction is completed. Thus execution of a
program consists of a sequence of instruction cycles, with one machine instruction per cycle.
Instruction Cycle
The entire group of instruction that determines what functions the microprocessor can
perform is called instruction set. Instruction cycle is defined as the time required completing the
execution of an instruction. The 8085 instruction cycle consists of one to six machine cycles or
one to six operations. Since, instruction is decoded in binary form and stored in memory; on the
basis of its clock speed computer takes a certain period to complete the task such as fetching,
decoding and execution.
The instruction cycle is combination of different smaller units. Basically, the instruction
cycle consists of two cycles, they are:
The essential component of every instruction cycle is the fetch cycle. In the fetch cycle the
central processing unit obtains the instruction code from the memory for its execution. Once the
instruction code is fetched from memory, it is then executed.
The Execution cycle thus consists of different operations such as calculating the address of
the operands, fetching them, performing operations on them and finally outputting the results to
a specified location.
Machine Cycle
Machine cycle is defined as the time required for completing one operation of accessing
memory, I\O or acknowledging an external request. This cycle may consist of three to six T-
states. It consists of four operations: Op-code Fetch, Memory Read, Memory Write, I/O Read and
I/O Write. These micro operations will be discussed later.
…
BLEX
Microprocessor
T-States
T1 T2 T3 T4 T5 T6
T-State
T-state is defined as the sub division of the operation performed in one clock period. During
T-second microprocessor (a sequential machine) stays in a particular state called T-state. So a
T-state lasts for a period of one clock cycle. T state and clock cycle are used synonymously.
Instruction Description
The Op-code field specifies how data is to be manipulated. A data item may reside within a
microprocessor register or in the main memory. Thus, the purpose of the address field is to
indicate the address of a data item. The address field may contain more than one address to store
a data. For example let us consider the following example.
ADD R1 R0
Op-code Operand
If R0 is the source register and R1 is the destination register. The instruction then adds the
contents of register R0 with that of R1 and stores result in R1. Here, the combination of source
register (R0) and destination register (R1) is an operand whereas the command ADD is an Op-
code. Finally, Op-code and Operand form an instruction.
…
BLEX
Microprocessor
Each microprocessor can handle predefined number of instructions. For example an 8085A
can handle at the maximum of 256 instructions (2word length). The sheet which contains all these
instructions with their hex code, mnemonics, descriptions and functions is called an instruction
sheet.
Depending upon the number of address specified in instruction sheet, the instruction format
can be classified into three categories, they are:
1 Byte Instruction:
One byte will be Op-code and Operand will be default for that instruction. A one byte
instruction includes the Op-code and Operand in the same byte. These instructions are stored
in 8-bit binary format in memory; each requires one memory location.
Examples:
Task Op-Code Operand Binary Code Hex Code
Copy The contents of the accumulator
MOV C, A 0100 1111 4FH
in register C.
Add the contents of register B to the
ADD B 1000 0000 80H
contents of the accumulator.
Invert/Compliment each bit in the
CMA - 00101111 2FH
accumulator.
2 Byte Instruction:
In two byte instruction, the first byte specifies the operation code and the second byte
specifies the operand. These instructions would require two memory locations each to store
the binary codes.
Examples:
Task Op-Code Operand Binary Code Hex Code
Load an 8-bit data byte in the 0011 1110 3E
MVI A, 32H
accumulator. 0011 0010 32
Load an 8-bit data byte in the register 0000 0110 06
MVI B, F2H
B. 1111 0010 F2
…
BLEX
Microprocessor
2 Byte Instruction:
In three byte instruction, the first byte specifies the operation code and the following two
bytes specify the 16-bit address where the second byte is the low order address and the third
byte is the high order address.
Examples:
Task Op-Code Operand Binary Code Hex Code
0011 1010 3A
Load contents of memory 2050H into A LDA 2050H 0101 0000 50
0010 0000 20
1100 0011 C3
Transfer the program sequence to
JMP 2085H 1000 0101 85
memory location 2085H. 0010 0000 20
A language that uses the symbolic notation to literally define, express and describe the
transfer of data among the register called register transfer language. RTL describes the micro
operations. The operations executed on data stored in registers are called microoperations.
Microoperations are the functional or atomic operations of a processor, which is an elementary
operation performed on information stored in one or more registers e.g. shift, count, clear, load
etc. In micro operation each step is very simple and accomplishes very literally.
The term “Register Transfer” implies the availability of hardware logic circuits that can
perform a stated microoperation and transfer the result of the operation to the same or another
register. The word “Language” is borrowed from programmers, who apply this term to
programming language.
…
BLEX
Microprocessor
Examples:
Examples:
(i) MOV A, M
This instruction moves the contents of the memory location whose address is specified by
the contents of the register H & L to the accumulator. If register H & L contains 20H and
50H respectively then the contents of memory location 2050H will be transferred to the
accumulator.
…
BLEX
Microprocessor
(ii) ADD M
This instruction adds the contents of the memory location whose address is specified by the
content of the register H & L to the content of the accumulator.
(iii) MVI M, 8bit data
This instruction moves the immediate 8-bit data to the memory location whose address is
specified by the contents of the register H & L.
Examples:
MOV A, B
This instruction moves the contents of the register B directly to register A (Accumulator).
ADD B
This instruction adds the contents of the register B with the contents of accumulator directly
and stores the result in accumulator.
ORA B
This instruction stores the result in accumulator after bitwise OR-operation between the
contents of register B and Accumulator.
Examples
5) Immediate Addressing:
In this mode the data is specified immediately after Op-code in the instruction. For an 8-
bit data, this mode uses 2-bytes instruction, with first byte as the Op-code followed by 1 or
2 byte of data whereas for 16-bit data, this mode uses 3-bytes instruction with first byte as
the Op-code followed by 2 bytes of data. In both cases, the actual data is part of the
instruction, and hence called immediate addressing.
Examples:
MVI A, 05H (8-bit Data)
This instruction moves the immediate data 05H to the accumulator.
LXI H, 7A21J (16-bit Data)
This instruction loads register H with 7AH and register L with 21H.
…
BLEX
Microprocessor
The addressing mode is a way of specifying a rule for interpreting or modifying the address
field of the instruction before the operand is actually referenced. The way the operands are
chosen during program execution is dependent on the addressing mode of the instruction.
Purpose:
- To give programming versatility to the user by providing such facilities as pointers to
memory, counters for loop control, indexing of data and program relocation.
- To reduce the number of bits in the addressing field of the instruction.
- To provide flexibility for writing programs that are more efficient with respect to the
number of instructions and execution time.
The 8086 processors let us access memory in many different ways. The 8086 memory
addressing modes provide flexible access to memory, allowing us to easily access variables,
arrays, records, pointers and other complex data types. The 8086 provides various addressing
modes to access instruction operands. Operands may be contained in registers, within the
instruction Op-code, in memory or in I/O ports.
The 8086 has twelve addressing modes. These modes can be classified into five groups.
They are:
…
BLEX
Microprocessor
However, a segment override instruction can be placed before most of the memory
operand instructions whose default segment register is to be overridden. For example, INC
BYTE PTR [START] will increment the 8-bit contents of a memory location in data segment
(DS) with offset START by one. However, segment DS can be overridden by extra segment
(ES) as follows: INC ES: BYTE PTR [START]. Segments cannot be overridden for stack
reference instructions such as PUSH and POP. The destination segment of a string segment,
which must be ES (if a prefix is used with a string instruction, only the source segment DS
can be overridden) cannot be overridden. The code segment (CS) register used in program
memory addressing cannot be overridden.
The EU calculates an offset from the instruction for a memory operand. This offset is
called the operand’s effective address (EA). It is a 16-bit number that represents the
operand’s distance in bytes from the start of the segment in which it resides.
The various memory addressing modes are as follows:
Memory Direct Addressing
Register Indirect Addressing
Based Addressing
Indexed Addressing
Based Indexed Addressing
String Addressing
1. Memory Direct Addressing:
In this mode, EA is taken directly from the displacement field of the
instruction. No registers are involved. For example, MOV BX, START moves the
contents of the 20-bit address computed from DS and START to BX.
3. Based Addressing:
EA is the sum of a displacement value (signed 8-bit or unsigned 16-bit) and
the contents of register BX or BP. For example, MOV AX, 4[BX] moves the
contents of 20-bit address computed from a segment register and [BX+4] into AX.
The segment register is DS or SS. If a displacement (4 in this case) is 8-bit, then the
8086 sign extends this to 16-bit in order to use SS register when the stack is
accessed; otherwise, this mode uses segment register DS. When memory is accessed,
the 20-bit physical address is computed from BX and DS. On the other hand, when
the stack is accessed, the 20-bit physical address is computed from BP and SS. The
BP may be considered as the user stack pointer while SP is the system stack pointer.
…
BLEX
Microprocessor
4. Indexed Addressing:
EA is calculated from the sum of a displacement value and the contents of
register SI or DI. For example, MOV AX, VALUE [SI] moves the contents of the 20-
bit address computed from VALUE, SI and the segment register into AX. The
segment register is DS. The displacement (VALUE in this case) can be unsigned 16-
bit or sign-extended 8-bit.
6. String Addressing:
This mode uses index registers. SI is assumed to point to the first byte or
word of the source string ad DI is assumed to point to the first byte or word of the
destination when a string instruction is executed. The SI or DI is automatically
incremented or decremented to point to the next byte or word depending on DF. The
default segment register for source is DS and it may be overridden. The segment
register for destination must be ES.
In direct port mode, the port number is an 8-bit immediate operand to access 256 ports.
For example, IN AL, 02 move the contents of port 02 to AL.
In indirect port mode, the port number is taken from DX allowing 64K bytes or 32
words or ports. For example, suppose [DX] = 0020, [port 0020] = 0216, and [port 0021]
= 0316, then after IN AX, DX register AX contains 030216. On the other hand, after IN
AL, DX, register AL contains 0216.
…
BLEX
Microprocessor
…
BLEX
Microprocessor
2. Arithmetic Operations:
Arithmetic Operation performs following task
o Addition
o Subtraction
o Increment (Add by 1)
o Decrement (Subtract by1)
This adjusts A to packed BCD after addition of two BCDs. It functions in two steps.
a) If the lower 4-bit of A are greater than 9 or the auxiliary carry is set, then it adds 06H to A.
b) Subsequently if the higher 4-bits of A are now greater than 9 or the carry flag is set, it adds
60H to A.
Example:
A = 39BCD
Add 12BCD
A = 39BCD = 0011 1001
+ 12BCD = 0011 0010
51BCD = 0100 1011 = 4B
…
BLEX
Microprocessor
The binary sum is 4BH. The value of low order four bit is larger than 9. Add 06 to low order
4-bits.
0011 1001
+ 0001 0010
4B 0100 1011
+06 0110
51H 0101 0001
3. Logical Instructions:
This instruction performs following operations
o AND
o OR
o XOR (Exclusive OR)
o Compare
o Rotate Bits
o Complement
…
BLEX
Microprocessor
4. Branching Instruction:
This group consists of following set of instructions.
o JMP 16 bit address Jump unconditionally to the address.
o JCond. Address; Jump conditionally to the address given.
This instruction causes a jump to the given address if a specified condition is satisfied.
The condition could be:
JC Jump on carry C=1
JNC Jump on not carry C=0
JP Jump on positive S=0
JM Jump on minus S=1
JPE Jump on parity even P=1
JPO Jump on parity Odd P=0
JZ Jump on zero Z=1
JNZ Jump on not zero Z=0
o PCHL: Copies the contents of HL into the following program counter.
o CALL address: Call unconditionally a sub routine at the address given.
o Ccond. Address: Call sub routine at the given address conditionally.
This instruction calls the subroutine at the given address if a specified condition is
satisfied. The following conditional calls can be made
CC Call on carry C=1
CNC Call on no carry C=0
CP Call on positive S=0
CM Call on minus S=1
CPE Call on parity even P=1
CPO Call on parity odd P=0
CZ Call on Zero Z=1
CNZ Call on no zero Z=0
o RET: Return from the subroutine unconditionally.
o Rcond. : Return from the subroutine conditionally.
This instruction returns the control to the main program if the specified condition is
satisfied.
RC Return on carry C=1
RNC Return on no carry C=0
RP Return on positive S=0
RM Return on minus S=1
RPE Return on parity even P=1
RPO Return on parity odd P=0
RZ Return on zero Z=1
RNZ Return on no zero Z=0
…
BLEX
Microprocessor
o Stack Operations:
o Machine Control:
NOP: No Operation
HLT: Halt the processor
Status
Machine cycle Control signals
IO\M S1 S0
Op-code fetch 0 1 1 RD = 0
Memory Read 0 1 0 RD = 0
Memory Write 0 0 1 WR = 0
I\O Read 1 1 0 RD = 0
I\O Write 1 0 1 WR = 0
Interrupt Acknowledge 1 1 1 INTA = 0
…
BLEX
Microprocessor
For example to fetch the byte, the processor needs to identify the memory location 2005H
and enable the data flow from memory. The data flow is shown in figure and the timing diagram
is also shown below.
Data Bus
4F
Memory
B C
A 2000
Instruction D E
L Decoder H L
U Stack
Pointer
2004
Program 4F 2005
counter
Control
Logic Address Bus
RD
4F
Fig: Data Flow from memory to MPU
T1 T2 T3 T4
A15 - A8
Low order
AD 7 - AD 0 05H 4FH Opcode
mem. address
ALE
IO \ M
RD
…
BLEX
Microprocessor
A memory read cycle is a process of transferring a byte from memory to the microprocessor.
To read a data from memory, microprocessor needs to identify and enable the memory cell. For
this purpose microprocessor places the address of memory cell on address bus and issues
different control signal from control unit.
The MPU performs the following steps to read the data from memory. Suppose the memory
read cycle need to perform to read the data byte 32h stored in memory location 2000h.
Step 1: The microprocessor places the content of program counter on the address bus. In our
case, it is 2000h. The lower address byte ‘00’ is latched with the help of ALE signal. If it is
not latched, the lower address byte will disappear or lost when microprocessor places the
data in data bus.
Step 2: The address decoding unit decodes the address bits and find out the desired memory
cell.
Step 3: The control unit sends the control signal RD to enable the memory. The status signal
IO/M goes low to indicate that it is memory related operations. The next two status signals
go high and low respectively to indicate that it is read operation.
Step 4: The data byte from memory location 2000h is placed on the data bus and transfer to
the microprocessor.
To illustrate the memory read machine cycle, we need to examine the execution of a 2 byte
or 3 byte instruction because in a 1 byte instruction the machine code is an Op-code fetch. Let us
illustrate with an example:
…
BLEX
Microprocessor
T1 T2 T3 T4 T1 T2 T3
Clock
A LE
IO \ M
S1 , S 0 Status IO \ M = 0, S 0 = 1, S 1 =1 Opcode fetch IO \ M = 0 , S0 = 0, S 1= 1 Status
RD
To write into a register, the microprocessor performs similar steps as it reads from a register.
The following example shows the memory write cycle with an example of STA instruction. In
the write operation, the 8085 places the address & data and asserts the IO/M signal. After
allowing sufficient time for data to become stable, it asserts the write (WR) signal. The IO/M
and WR signals can be combined to generate the MEMW control signal that enables the input
buffer of the memory chip and stores the byte in the selected memory register.
Here it is assumed that the instruction is stored in memory location 2050H, 2051H and
2052H. The timing diagram for instruction STA 8000H is shown below:
…
BLEX
Microprocessor
The purpose of I/O Read is to read data from input device such as keyboard and places the
data in the accumulator. To illustrate the timing diagram for I/O Read, we examine the
execution of instruction IN 84h, stored at memory location: 2065.
Example: IN 84H
…
BLEX
Microprocessor
T1 T2 T3 T4 T1 T2 T3 T1 T2 T3
ALE
IO\ M
RD
MEMR
IOR
Explanation:
The First Machine Cycle (M1): Op-Code Fetch
The 8085 places the high order memory address 20H on A15 –A8 and the low order
address 50H on AD7-AD0. At the same time, ALE goes high and IO/ M goes low. The
IO\ M low indicates that it is a memory operation. At T2, the microprocessor sends the RD
control signal which is combined with IO\ M to generate the MEMR signal and the
processor fetches the instruction code D3 using the data bus and the instruction is decoded.
The Second Machine Cycle (M2): Memory Read
In the second machine cycle, M2 (Memory Read), the 8085 places the next address
2051H on the address bus and get the device address 84H via data bus.
The Third Machine Cycle (M3): I/O Write
In the third machine cycle, M3 (I\O Write), the 8085 places the device address 84H on the
low order (AD7 – AD0) as well as the high order (A15 – A8) address bus. The IO\ M signal
goes high to indicate that it is an I\O operation. The IOR signal is generated combining RD
and IO/M. The IOR signal enables the input port and data from input port are placed on the
data bus and transformed into the accumulator.
…
BLEX
Microprocessor
The purpose of I/O write is to send the content of accumulator to an O/P device such as LED
display. To illustrate the timing diagram for I/O write, we examine the execution of instruction
OUT 01h, stored in memory location: 2050as follows:
ALE
IO \ M
RD
MEMR
WR
IOW
…
BLEX
Microprocessor
Explanation:
The First Machine Cycle (M1): Op-Code Fetch
The 8085 places the high order memory address 20H on A15 –A8 and the low order
address 50H on AD7-AD0. At the same time, ALE goes high and IO/ M goes low. The
IO\ M low indicates that it is a memory related operation. At T2, the microprocessor sends
the RD control signal which is combined with IO\ M to generate the MEMR signal and
the processor fetches the instruction code D3 using the data bus and instruction is decoded.
The Second Machine Cycle (M2): Memory Read
In the second machine cycle, M2 (Memory Read), the 8085 places the next address
2051H on the address bus and get the device address 01h via data bus.
The Third Machine Cycle (M3): I/O Write
In the third machine cycle, M3 (I\O Write), the 8085 places the device address 01H on the
low order (AD7 – AD0) as well as the high order (A15 – A8) address bus. The IO\ M signal
goes high to indicate that it is an I\O operation. At T2, the accumulator contents are placed
on the data bus (AD7 – AD0) followed by the control signal WR . By adding the IO\ M and
WR signals, the IOW signal can be generated to enable an output device and data from
accumulator are displayed on O/P device such as LEDs.
Regular Examination: 2004 [Draw the Timing Diagram of OUT 23H Instruction]
Memory Address Machine Code Mnemonics Memory Contents
2050H D3 OUT 23H 2050: 1101 0011H = D3H
2051H 01 - 2051: 0010 0011H = 23H
ALE
IO \ M
RD
MEMR
WR
IOW
…
BLEX
Microprocessor
As we know that the specified task is performed during the execution cycle i.e. at the end of
last T-state of the instruction cycle. But this may not be always true. This is just the
generalization for easier purpose.
Let’s consider the instruction MOV Rd, Rs which takes one machine cycle M1 and consists of
4 T-states as shown in following timing diagram.
Clock
ALE
RD
PC + 1 PC Opcode IR
FEO
The T4, T-state is used as instruction decoding cycle and least duration of T4 is used to
perform the specified task. But for the MOV Rd, Rs instruction, at the end of T4, only the contents
of source register (Rs) is transferred to temporary register (Tr). The transferring of data from
temporary register (Tr) to destination register (Rd) is done at the T2 state of first machine cycle
next instruction. We know that the next immediate machine cycle is Op-code fetch as MOV Rd,
Rs is one byte instruction. It is clear from the timing diagram that T1 and T2 of the fetch cycle of
next instruction is used to fetch the Op-code as well as transferring of data from temporary
register to destination register of previous instruction. This is called fetch execution overlap
(FEO).
…
BLEX
Microprocessor
…
BLEX
Microprocessor
Counter
A counter is designed simply by loading an appropriate number into one of the registers and
using the INR (Increment by One) or the DCR (Decrement by One) instructions. A loop is
established to update the count and each count is checked to determine whether it has reached
the final number; if not, the loop is repeated.
The flowchart shown below illustrates these steps. However, this counter has one major
drawback; the counting is performed at such high speed that only the last count can be observed.
To observe counting, there must be appropriate time delay between counts.
Initialize
Display
Update
No Is this
Final
Count?
Yes
Fig: Flowchart of a
Counter
Time Delay
The procedure used to design a specific delay is similar to that used to set up a counter. A
register is loaded with a number, depending on the time delay required, and then the register is
decremented until it reaches zero by setting up a loop with a conditional Jump instruction. The
loop causes the delay, depending upon the clock period of the system.
…
BLEX
Microprocessor
Delay Calculation:
Clock Frequency of the System (f) = 2 MHz
Clock Period (T) = 1/f = 1/(2x10-6) = 0.5 s
Time to Execute MVI = 7 T-States x 0.5 = 3.5 s
To calculate the time delay in a loop, we must account for the T-states required for each instruction
and for the number of times the instructions are executed in the loop. In above example, register C is
loaded with the count FFH (25510) by the instruction MVI, which is executed once and takes seven T-
states. The next two instructions, DCR and JNZ, form a loop with a total of 14 (4+10) T-states. The loop
is repeated 255 times until register C = 0.
Now, the time delay in the loop TL with 2 MHz clock frequency is calculated as:
TL = (T x Loop T-states x N10)
Note: The T-states for JNZ instruction are shown as 10/7. This is why the 8085 microprocessor requires
10 T-states to execute a conditional Jump instruction when it jumps or changes the sequence of the
program and 7 T-states when the program falls through the loop (goes to the instruction following the
JNZ). This difference can be accounted for the delay calculation by subtraction the execution time of
three states. There for, adjusted loop delay is:
TLA = TL – (3 T-states x Clock Period)
= 1785 s – 1.5 s
= 1783.5 s
Now the total delay must take into account the execution time of the instructions outside the loop. In the
above example, we have only one instruction (MVI C) outside the loop. Therefore, the total delay is:
Total Delay = Time to Execute Instructions Outside Loop + Time to Execute Loop Instructions
TD = TO + TLA
= (7 x 0.5) + 1783.5 = 1787 s
= 1.8 ms
…
BLEX
Microprocessor
Delay Calculation:
The loop includes four instructions: DCX, MOV, ORA and JNZ and takes 24 clock periods for
execution. The loop is repeated 2384H times, which is converted to decimal as:
2384H = 2 x (16)3 + 3 x (16)2 + 8 x (16)1 + 4 x (16)0
= 909210
If the clock period of the system = 0.5 s, the delay in the loop T is:
TL = (0.5 x 24 x 909210)
= 109 ms (without adjusting for the last cycle)
Delay Calculation:
The delay in LOOP1 is TL1 = 1783.5 s as per the previous calculation. Now the calculation for the
delay in LOOP2 is as follows:
TL2 = 56(TL1 + 21 T-states x 0.5 s)
= 56 (1783.5 s + 10.5 s)
= 100.46 ms
…
BLEX
Microprocessor
…
BLEX
Microprocessor
Computer program is a set of instructions that, when executed, causes the computer to
behave in a predetermined manner. Without programs, computers are useless and can do
nothing. Most people are confused that computers are intelligent devices and can do anything;
but this concept is wrong. Computer can do anything, but only after it has appropriate
program(s). Without programs, it can not even add two numbers.
Computer cannot understand human natural languages like English or Nepali. To instruct a
computer to perform a certain job, we need languages which can be understood by the
computer. The languages which are used to instruct the computer to do certain jobs are called
“Computer Programming Languages”. There are many programming languages like C, C++,
Pascal, BASIC, FORTRAN, COBOL, LISP, etc.
Programming
uag
Low-level High-level
Machine-level Assembly-level
Low-Level Language
Machine-level Language
Machine language is a language that a computer actually understands. The least possible
level at which we can program a computer is in its own native machine code, consisting of
strings of 1's and 0's, and are stored as binary numbers. Thus, machine language is a
sequence of instructions written in the form of binary numbers consisting of 1’s and 0’s to
which the computer responds directly. The main advantage of machine languages is that
they execute fast as the computer understands them and doesn’t need translation into other
forms. However, machine languages are difficult to write.
…
BLEX
Microprocessor
Example: To add two numbers 3 and 6 in machine language, program may be like –
11 10111001 110
3 machine code for addition (say) 6
There are many different instruction sets (machine codes) for each operation. It is
difficult to remember them for programming.
Assembly Language
Assembly language is a symbolic representation (called mnemonics) of machine code.
They are close to machine code but the computer cannot understand them. The assembly-
language program must be translated into machine code by a separate program called an
assembler. The assembler program recognizes the character strings that make up the
symbolic names of the various machine operations, and substitutes the required machine
code for each instruction. The above program for addition two numbers in assembly
language may look like –
11 ADD 110 Suppose ADD is mnemonic for addition
Some of the examples of instructions for assembly language are as follows:
Code Meaning
ADD Addition
SUB Subtraction
INR Increase
DCR Decrease
CMP Compare
It is relatively easy for writing programs in assembly languages, but is slow in execution
as it has to be converted into machine language before execution.
…
BLEX
Microprocessor
…
BLEX
Microprocessor
High level source program must be translated first into a form the machine can understand.
This is done by the software called compiler. The compiler takes the source code as input and
produces the machine language code (object code) for the machine on which it is to be executed
as output. During the process of translation, the compiler reads the source programs statement-
wise and checks for syntax errors. In case of any error, the computer generates message about
the error. Examples: C, C++, Java, FORTRAN, Pascal etc
An interpreter, like compiler, is also translator which translates high level language into a
machine level language. The difference between compiler and interpreter is their working
principle. The interpreter translates and executes the program line by line. Each time the
program is executed; every line is checked for syntax error and then converted to the equivalent
machine code. Examples: QBASIC, PERL, PHP, ASP
Compiler Vs Interpreter
Compiler Interpreter
1) Compiler scans the entire program 1) Interpreter translates and executes the
before translating it into machine code. program line by line.
2) Syntax errors are found only after the 2) Syntax errors can be trapped after
compilation of complete program. translation of every line.
3) It takes less execution time 3) It takes more execution time
Programs in assembly language are represented by instructions that use English Language
Type commands called mnemonics. It is more convenient to write the programs in assembly than
in machine language. However a translator (assembler) must be used to convert the assembly
language programs into binary machine language programs (object codes) so that the processor
can execute them.
An assembly language program written for one microprocessor is not transferable to a
computer with another microprocessor unless the tow microprocessors are compatible in their
machine codes.
Example: The binary code 0011 1100 of the 8085 microprocessor is represented by the
mnemonic INR A, which suggests the operation of incrementing the accumulator contents by
one.
…
BLEX
Microprocessor
The program development utilities enable the user to write, assemble and test assembly
language programs; they include programs such as Editor, Assembler, Linker (or Loader) and
Debugger. These utility programs enable the user to perform such functions as copying, printing,
deleting and renaming files. Therefore they are necessary to develop assembly language
programs.
Editor:
The editor is a program that allows the user to enter, modify and store a group of
instructions or text under a file name. The editor programs can be classified in two groups:
line editors and full-screen editors. Line editors, such as EDIT in MS-DOS, work with and
manage one line at a time. Full screen editors (also known as word processor), such as MS
Word and WordPerfect, manage the full screen or a paragraph at a time. To write text, the
use must call the Editor under control of the operating system. The exit command of the
Editor program will save the program on the disk under the file name and will transfer the
program control to the operation system.
Assembler:
The assembler is a program that translates source code or mnemonics into the binary
code, called object code, of the microprocessor and generates a file called the object file.
This function is similar to manual assembly, whereby the user looks up the code for each
mnemonic in the listing. The translation requires that the source program be written strictly
according to the specified syntax of the assembler. The assembly language source program
includes three types of statements, they are:
- The program statement in 8085 mnemonics that are to be translated into binary code.
- Comments that are reproduced as part of the program documentation.
- Directives to the assembler that specify items such as starting memory locations, label,
definitions and required memory spaces for data
…
BLEX
Microprocessor
- Translates mnemonics into binary code with speed and accuracy, thus elimination
human errors in looking up the codes.
- Assigns appropriate values to the symbols used in program. This facilitates specifying
jump locations.
- Easy to insert or delete instructions in a program; the assembler can reassemble the
entire program quickly with new memory locations and modified addresses for jump
locations. This avoids rewriting the program manually.
- Checks syntax errors, such as wrong labels and expressions, and provides error
messages. However it cannot check logic errors in a program.
- Reserve memory locations for data or results.
- Provide files for documentation.
- A debugger program can be used in conjunction with the assembler to test and debug an
assembly language program.
Loader (Linker):
The loader is a program that takes the object file generated by the assembler program
and generates a file in binary code called the COM file or the EXE file. The COM or EXE
file is the only executable file i.e.; the only file that can be executed by the microcomputer.
To execute the program, the COM file is called under the control of the operating system
and executed. In different assemblers, the COM file may be labeled by other names.
Debugger:
The Debugger is a program that allows the user to test and debug the object file. The
user can employ this program to perform the following functions:
- Make changes in the object code.
- Examine and modify the contents of memory.
- Set breakpoints, execute a segment of the program and display register contents after the
execution.
- Trace the execution of the specified segment of the program and display the register and
memory contents after the execution of each instruction.
- Disassemble a section of the program i.e. convert the object code into the source code or
mnemonics.
…
BLEX
Microprocessor
A typical assembly language programming statement is divided into four parts called fields:
Label, Operation Code (Op code), Operand and Comments. These fields are separated by
delimiters as shown in table below:
Delimiter Placement
1. Colon After label (Optional)
2. Space Between an op code and operand
3. Comma Between two operands
4. Semicolon Before the beginning of a comment
In above sample assembly language program delimiters include the colon following START,
the space following LXI, the comma following SP, and the semicolon preceding the comments.
…
BLEX
Microprocessor
Types of Assembler
One Pass Assembler goes through the assembly language program once and translates the
assembly language program. This assembler has the program of defining forward references.
This means that a JUMP instruction using an address that appears later in the program must
be defined by the programmer after the program is assembled.
Two Pass Assembler scans the assembly language program twice. In the first pass the
assembler generates the table of the symbols. A symbol table consists of labels with
addresses assigned to them. In this way labels can be used for JUMP statements and no
address calculation here to be done by the user. On the second pass, the assembler translates
the assembly language program into the machine code. The two pass assembler is hence
more efficient and easier to use.
Cross Assembler
This type of assembler is typically resident on the processor and assembles programs for
another for which it is written. The cross assembler program is written in a high level
language so that it can run on different types of processor that understands the same high
level language.
For example, the 8085 cross-assembler from 2500AD Software Inc. has two programs:
one is as assembler named X8085 and the other is a linker with the file name LINK. After
assembling a program, the HEX file can be directly transferred to R/W memory of 8085
single-board microcomputer by using a Download Program. Thus programs and/or
hardware-related laboratory experiments can be easily performed. An assembly language
program using cross-assembler has following steps of operations:
…
BLEX
Microprocessor
Call an Editor (Such as EDIT in MS-DOS & WordPerfect or MS-Word in Windows) and
write an assembly language program in 8085 mnemonics. This is called source file.
Call a Cross-Assembler (Such as X8085) and assemble the source file. The X8085
generates an intermediate binary file called an object file and provides a list of errors.
Reassembling the program would give a message of zero errors. The cross assembler
also generates a list file that includes memory address, machine codes in HEX, Labels
and Comments. This file is used primarily for documentation.
Call a Link program and use the intermediate binary file (Object Code) to generate either
an Executable file or HEX file.
After the end of the assembly process, we will have the following files on our PC disk.
ASM File: This is the source file written by the user using an Editor. The filename can be
one to eight characters long with an extension of a maximum of three characters. The
filename and the extension are separated by a dot, e.g. Microprocessor.ASM, the
extension ASM suggests that this is an assembly language file.
OBJ File: This is the intermediate binary file generated by the Cross-Assembler.
LST File: This is the list file generated by the Assembler Program for documentation
purposes. It contains memory locations, hex code, mnemonics and comments.
HEX File: This is generated by the Link Program and contains program code in
hexadecimal notations. This file can be used for debugging the program and to transfer
files from one system to another.
COM File: This is the executable file generated by the Link Program, and it contains
binary code. However, this file cannot be executed on the PC. This type of a file can be
executed if it has to write an assembly language program for the microprocessor in the
PC. However, in such a situation cross-assembler will be not in use. We have to use the
assembler for the PC microprocessor.
Resident Assembler
This type of assembler assembles programs for a processor in which it is resident. The
resident assembler may slow down the operation of processor on which it runs.
Meta Assembler
This type of assembler can assemble programs for many different types of processors.
The programmer usually defines the particular processor being used.
…
BLEX
Microprocessor
Macro Assembler
Macro assembler lets the programmer define all instruction sequence using macros. By
using macros, the programmer can assign a name to an instruction sequence that appears
repeatedly in a program. The programmer can thus avoid writing an instruction sequence
that is required many times in a program by using macros. The macro assembler replaces a
macro name with the appropriate instruction sequence each time it encounters a macro
name.
As in subroutine program, there is no need to use CALL and RET instruction to execute
and to resume program. A macro does not cause the program execution to branch out of the
main program. Each time a macro occurs, it is replaced with the appropriate instruction
sequence in the main program. Typical advantages of using macros are shorter source
program and better program documentation.
IN AX, PORT
ADD AX, BX
OUT PORT, AX
If above sequence of instructions are grouped and assigned a specific name ‘Addition’
(called macro name ‘Addition’), the whole macro becomes:
Addition {
IN AX, PORT
ADD AX, BX
OUT PORT, AX
}
…
BLEX
Microprocessor
Assembler Directives
Assembler directives are the instructions to the assembler concerning the program being
assembled. They are also called pseudo instructions or pseudo codes. They are neither translated
into machine code nor assigned any memory location. They just provide the direction to the
assembler.
DB- Define Byte (1 Byte): The DB directive creates storage for a byte or group of bytes in
memory. It is used to declare a byte type variable.
Example: Count DB? (Initialization)
Data 1 DB 10H
List DB 10H, 20H, 30H
DW-Define Word (2 byte): The DW directive creates storage for a word or list of words.
It is used to declare a word type variable.
Example: Data 1 DW 1234H
List DW 1234H, 6678H, 7981H
DD- Define Double Word (4 byte): The DD directive creates storage for 32 bits double
word variable. It is used to declare double word type variable.
Example: Data 1 DD 12345678H
DQ- Define Quad Word (8-byte): DQ directive creates storage for 8 byte or group of 8
bytes. It is use to declare quad word type variable.
Example: Data1 DQ 123456789123456H.
DT-Define Ten Bytes: DT directive creates storage for ten bytes. It is used to declare ten
byte type variable.
Example: List DT 123456789A1234564455H
…
BLEX
Microprocessor
2. DUP-Directive (Duplicate)
The DUP directive can be used to initialize several locations to zero. For example the
statement START DW 4DUP (0) reserves four words starting at the offset START in DS and
initializes them to zero. The DUP directive can also be used to reserve several locations that
need not be initialized. A question mark should used with DUP in this case. For example the
statement BEGIN DB100 DUP (?) reserves 100 bytes of uninitialized data space to an offset
BEGIN in DS.
3. EQU-Directive (Equate)
The EQU directive is used to give a name to some value or symbol. Each time the
assembler finds the given name in the program, it will replace the name with the value or
symbol equated with that name. Example count EQU 10H.
4. ORG-Directive (Origin)
The ORG directive allows setting location counter to desired value. For example ORG
200H tells assembler to set location counter to 2000H.
5. ASSUME-Directive
The ASSUME directive tells the assembler what names have been used for used for the
code, data, extra and stack segment. It identifies the segment name used for code, data and
stack segment. Example: ASSUME CS: CODE, DS: DATA, SS: STACK.
6. MODEL-Directive
The MODEL directive selects standard memory model for the program. It determines the
way segments are linked together as well as maximum size of each segment.
Model Description
Tiny Code and Data segment together may not be greater than 64K
Small Neither Code or data may be greater than 64K
Medium Only the code may be greater than 64K.
Compact Only the data may be greater than 64K.
Large Both code and data may be greater than 64K.
Huge All available memory may be used for code and data.
7. Program Segment-Directive
The program segment directives are:
.STACK: The stack directive sets the size of the program stack which may be any size up
to 64K. The stack segment is addressed by SS and SP registers.
.CODE: The code directive identifies the part of the program that contains the
declaration and initialization of all variables. This segment is addressed by DS and all
other register except IP, SP and BP.
.DATA: The data directive identifies the start of the data segment.
.DOSSEG: The DOSSEG segment tells the assembler to place the segments in order
basically code, data and stack.
…
BLEX
Microprocessor
8. Procedure-Directive
A procedure is the group of related program instructions with common function or task.
PROC Directive: It is used to identify the start of the procedure.
ENDP Directive: It indicates the end of the procedure.
ENDS Directive: It indicates the end of the segment.
END Directive: The end directive terminates the assembly language program and is
placed at the end of the program. Any instruction after this is ignored.
The sample program given below, when assembled and executed, exchanges the contents of
two variables. The following source program is created using a text editor.
Main PROC
MOV AX, @Data ; Initialize DS Register
MOV DS, AX
SWAP;
MOV AL, Value1 ; Load the AL Register
XCHG Value2, AL ; Exchange AL and Value2
MOV Value1, AL ; Move AL back into value1
INT 21h
Main ENDP
.Data
Value1 DB 0Ah
Value2 DB 14h
END Main
…
BLEX
Microprocessor
Program Instruction
The first two instructions in the sample program initialize the data segment (DS) register.
The name @ Data is a standard MASM identifier that stands for the location of the data
segment. By setting DS equal to the start of the data segment, we make it possible for MASM to
locate variables correctly. The next three instructions exchange the contents of value1 and
value2.
…
BLEX
Microprocessor
o Bus Structure
o Memory & Its Types
o Memory Interfacing
o Address Decoding
…
BLEX
Microprocessor
Bus Structures
A microprocessor unit basically performs four operations; memory read, memory write, I\O
read and I\O write. These operations are part of communication between MPU and peripheral
devices.
A communication includes identifying peripheral or memory location, transfer of data and
control functions. These are carried out using address bus, data bus and control bus respectively.
All the buses together are called the system bus.
Data Bus
The data bus provides a path for data flow between system modules. It consists of a
number of a separate line generally 8, 16, 32 or 64. The number of lines is referred as width
of the data bus. A single line can only carry one bit at a time, thus the number of lines
determines how many bits can be transmitted at a time. The width of the data bus is a key
factor in determining the overall systems performance.
Read
Address
MSYNC
Data Bus
SSYNC
…
BLEX
Microprocessor
Clock
Start
Read
Address
Data Bus
Acknowledge Signal
Address Bus
The address bus is used to designate the source and destination of data in data bus. In a
computer system, each peripheral or memory location is identified by a binary number
called address.
The width of the address bus determines the maximum possible memory capacity of the
system. The address bus is used to address I\O ports. Usually higher order bits are used to
select particular modules and lower order bit is used to select a memory location or I\O port
within a module.
…
BLEX
Microprocessor
Control Bus
The control bus is a group of lines used to control the data address bus. Since the bus is
shared by all the components of the microcomputer system there must be some control
mechanism to distinguish between data and address. The timing signals indicate the validity
of data and address information while command signal specify operations to be performed.
Some of the control signals are:
o Memory Write
o Memory Read
o I\O Read
o I\O Write
o ALE
o Interrupt Request
o Interrupt Acknowledge
Processor Memory
Processor memory is a group of register along with processor. They temporarily hold the
data during computation since processor and register are fabricated with same technology
and they have same speed.
Separate memory is kept alongside the processor to keep the most frequently needed
information. This memory is known as cache memory.
Primary Memory
This is the memory the microprocessor uses in executing and storing programs. Usually
the size of the primary memory is larger and speed is slower than the processor memory.
Primary memory can be categorized as:
o Random Access Memory (RAM)
o Read Only Memory (ROM)
…
BLEX
Microprocessor
Properties of RAM
Integrated circuit RAM may be either static or dynamic
Stores binary information in the form of electric charges on capacitors.
Data can be accessed randomly.
Read and write operation can be performed.
Volatile; lose stored information when power is turned off.
Types of RAM
There are two types of RAM
o Static Random Access Memory (SRAM)
o Dynamic Random Access Memory (DRAM)
…
BLEX
Microprocessor
Types of RAM
The different types of ROM are described below:
o The Masked ROM
o Programmable ROM (PROM)
o Erasable PROM (EPROM)
Ultraviolet Erasable PROM
Electrically Erasable PROM
Programmable ROM
These are unprogrammed ROM. A PROM uses some type of fusing process to store
bits, in which a memory link is burn open or left intact to represent a 0 or a 1. The fusing
process is irreversible, once a PROM is programmed, it cannot be changed.
Erasable PROM
An EPROM is an erasable PROM. An EPROM can be reprogrammed if an existing
program in the memory array is erased first.
The basic types of erasable PROM are ultraviolet erasable PROM (UVEPROM) and
the electrically erasable PROM (EEPROM).
Secondary Memory
Secondary memories are storage devices. These device have high data holding capacity
and can hold huge programs such as compilers and data based management system that are
not needed by the processor frequently. They are slow and have larger size. The secondary
memories are also referred to as auxiliary or back up storage.
…
BLEX
Microprocessor
Differences
DRAM SRAM
1. DRAM stores a data bit in a small 1. SRAM uses flip-flops as a storage
capacitor. element.
2. DRAM cannot retain data very long
2. Data can be stored indefinitely as long
without the capacitors being refreshed by a
as dc power is applied.
process called refreshing.
3. Data can be read much faster from
3. Data access time is greater than SRAM.
SRAM’s.
4. DRAM can store much more data for a 4. SRAM can store less data than DRAM
given size and cost. for a give physical size and cost.
5. Data is kept as a charge. 5. Data is kept as a voltage.
6. It has high density. 6. It has low density.
RAM ROM
1. RAM is a type of memory in which all
1. ROM is a type of memory in which
addresses are accessible in an equal amount
data are stored permanently or semi
of time and can be selected in any order for
permanently.
read and write operation.
2. ROM stores data that are repeatedly in
2. A RAM stores currently used data.
used system applications.
3. A RAM has both read and writes 3. Data can be read from a ROM, but there
capability. is no write operation.
4. RAM, lose stored data when power is 4. Non volatile; data is not loosed even if
turned off so they are volatile. power is turned off.
Primary Storage Secondary Storage
1. This is the memory the microprocessor 1. This is the memory which stores all the
uses in executing and storing program. data and programs.
2. Smaller in size so holds the data and 2. Larger in size and hence holds larger
programs currently in use. data files and huge programs.
3. The microprocessor cannot directly
3. The microprocessor can directly
execute or process program stored in this
communicate with primary storage.
memory.
4. It has to communicate with
4. It has low speed and thus it is cheaper
microprocessor that has high speed and is
than primary memory.
expensive.
5. Generally volatile; data cannot be 5. Non volatile; data can be retained even
retained when power is turned off. after power is turned off.
Magnetic disk and tapes are secondary
6. RAM and ROM are primary storage.
storage.
…
BLEX
Microprocessor
Memory Interfacing
o A memory chip requires address lines to identify a memory register. The number of
address lines required is determined by the number of registers in a chip. (2n = Number
of registers where n is the number of address lines.)
o A memory chip requires a Chip Select (CS) signal to enable a chip. The remaining
address lines of the microprocessor can be connected to the CS signal through an
interfacing logic.
o The address lines connected to CS select the chip, and the address lines connected to the
address lines of the memory chip select the register. Thus the memory address of a
register is determined by the logic levels (0/1) of all the address lines (including the
address lines used for CS)
o The control signal Read (RD) enables the output buffer and the data from the selected
register are made available on the output lines. Similarly the control signal Write (WR)
enables the input buffer and data on the input lines are written into memory cells.
A model of a typical memory chip representing the above requirements is shown below.
CS RD WR CS RD
An An
Address Address
R/W M ROM
Lines Lines
A0 A0
Data Data
Lines Lines
Fig: (a) R/W Memory Model (b) ROM Model
…
BLEX
Microprocessor
In an 8-bit microprocessor system like 8085, 16 address lines are available for memory. This
means it is a numbering system of 16 binary bits and is capable of identifying 216 = 65,536
memory registers, each register with a 16-bit address. The entire memory addresses can range
from 0000 to FFFF in HEX, A memory map is a pictorial representation in which memory
devices are located in the entire range of addresses. Memory addresses provide the locations of
various memory devices in the system and the interfacing logic defines the range of memory
addresses for each memory device.
Address range of a memory chip can be easily changed by modifying the hardware of the
chip select line, which is generated by keeping the higher order address lines of the
microprocessor at fixed logic levels. The hardware to generate the chip select address could be
inverters and NAND gates or decoder logic.
The primary function of memory is to store instructions and data and to provide that
information to the MPU whenever the MPU request it. The MPU requests the information by
sending the address of a specific memory register on the address bus and enables the data flow
by sending the control signal as illustrated in the following example.
The instruction code 0100 1111 (4FH) is stored in memory location 2005H. Illustrate the data
flow and list the sequence of events when the instruction code is fetched by the MPU
4F 01001111
8085 Microprocessor Data Bus
Instruction B C
Flag
Accumulator Flip Decoder D E
Flop H L
SP 01001111 2005
Arithmetic/Logic Unit Control
Unit PC
2005
Address Bus |
4F
…
BLEX
Microprocessor
To fetch the instruction located in memory location 2005H, the following steps are performed:
Step 1: The Program Counter (PC) places the 16-bit address 2005H of the memory location
on the address bus.
Step 2: The control unit sends the Memory Read control signal (MEMR, active low) to
enable the output buffer of the memory chip.
Step 3: The instruction 4FH stored in the memory location is placed on the data bus and
transferred (copied) to the instruction decoder of the microprocessor.
Step 4: The instruction is decoded and executed according to the binary pattern of the
instruction.
While executing a program, the microprocessor needs to access memory quite frequently to
read instruction codes and data store in memory; the interfacing circuit enables that access.
Memory has certain signal requirements to write into and read from its registers. Similarly, the
microprocessor initiates a set of signals when it wants to read from and write into memory. The
interfacing process involves designing a circuit that will match the memory requirements with
the microprocessor signals.
Thus Memory Interfacing is the process of designing appropriate circuit arrangement for
enabling the microprocessor to access any register inside any of the many memory chips using
unconflicting appropriate address for fetching instruction codes and data from that memory
location into the microprocessor.
The primary function of memory interfacing is that the microprocessor should be able to
read from and writhe into a given register of a memory chip. To perform these operations, the
microprocessor should
o Be able to select the chip.
o Identify the register.
o Enable the appropriate buffer.
Example 1: Illustrate the memory address range of the chip with 1K (1024×8) bytes of memory,
shown in figure below and explain how the range can be changed by modifying the hardware of
the Chip Select line.
Explanation:
- Given Memory Size: 1 Kilobyte = 1024 Bytes
- Therefore the memory chip has 1024 registers.
- Number of address lines (n) = ln1024/ln2 = 10(i.e. A9-A0), which is required to identify the
registers.
- The remaining six address lines (i.e. A15-A10) of the microprocessor are used for the Chip -
Select (CS) signal. In the given figure below, the memory chip is enabled when the address
lines (i.e. A15-A10) are at logic 0. The address lines A9-A0 can assume any address of the 1024
registers, starting from all 0s to all 1s as shown next.
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000H
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
Chip Select Logic Levels
1 1 1 1 1 1 1 1 1 1 03FFH
…
BLEX
Microprocessor
A15
MEMR
A14
A13 MEMW
A12
A11
A10
CS RD WR
A9
A8
A7
Internal Decoder
A6
A5 1024 Registers
A4
A3
A2
A1
A0
I/O Lines
Example 2: Design an interfacing circuit so that ROM 1 of 8K and ROM 2 of 8K and R/W M 1 of
1K can be interfaced with 8085. The memory address specified by the memory devices are:
…
BLEX
Microprocessor
For ROM 1
- Given Memory Size: 8 Kilobyte = 1024x8 Bytes
- Therefore the memory chip has 8192 registers.
- Number of address lines (n) = ln8192/ln2 = 13(i.e. A12-A0), which is required to identify the
registers.
- The remaining three address lines (i.e. A15-A13) of the microprocessor are used for the Chip -
Select (CS) signal. The memory chip for ROM 1 is enabled when the address lines (i.e. A15-
A13) are at logic 0. The address lines A12-A0 can assume any address of the 8192 registers,
starting from all 0s to all 1s.
For ROM 1
Given Memory Size: 8 Kilobyte = 1024x8 Bytes
- Therefore the memory chip has 8192 registers.
- Number of address lines (n) = ln8192/ln2 = 13(i.e. A12-A0), which is required to identify the
registers.
- The remaining three address lines (i.e. A15-A13) of the microprocessor are used for the Chip -
Select (CS) signal. The memory chip for ROM 2 is enabled when the address lines (i.e. A15-
A13) are at logic 1. The address lines A12-A0 can assume any address of the 8192 registers,
starting from all 0s to all 1s.
For R/W M1
- Given Memory Size: 1 Kilobyte = 1024 Bytes
- Therefore the memory chip has 1024 registers.
- Number of address lines (n) = ln1024/ln2 = 10(i.e. A9-A0), which is required to identify the
registers.
- The remaining three address lines (i.e. A15-A10) of the microprocessor are used for the Chip -
Select (CS) signal. The memory chip for R/W M1 is enabled when the address lines i.e. A15 is
at logic 1 and A14-A10 are at logic 0. The address lines A9-A0 can assume any address of the
1024 registers, starting from all 0s to all 1s.
…
BLEX
Microprocessor
IO/M
+5V
E1 E2 E3
O7
MSB O6
A15 O5
3x8 O4
A14 Decoder O3
Logic O2
A13 O1
O0
RD WR RD RD
+5V
CE OE WE CE OE CE OE
E1 E2 E3
O7
MSB O6 A9 A12 A12
A12 O5 ROM 1 ROM 2
3x8 R/W M1
O4 8Kx8 8Kx8
A11 1Kx8
Decoder O3 A0 A0 A0
Logic O2
A10 O1
O0
…
BLEX
Microprocessor
IO/M
MEMR
8085 RD
MEMW
Control
Signal
WR
IOR
IOW
…
BLEX
Microprocessor
Now, by choosing any logic level either 1 or 0 the combination of input to the NAND
gate can be varied and the Chip Select line can be generated as per our requirement. By the
modification of input bits of NAND gate, memory address range can be defined as per our
need. For above example of 6 inputted NAND gate the memory address range can be varied
from 000H to 11FH.
The decoder is used to decode the address lines. The output of the decoder is connected to
Chip Enable (Chip Select) control signal. The Chip Select line is asserted only when the
address on address lines is equivalent to 0. The control signal can be generated using 3x8
decoder logic as shown below:
A15 +5V
E1 E2 E3
O7
MSB O6
A14
O5
3x8
Decoder O4
A13
Logic O3
74LS138 O2
A12
O1
O0
CS
…
BLEX
Microprocessor
Address Decoding
In address decoding method, all the devices like memory, I/O units etc are assigned with
specific addresses. The address of device is determined from the way in which the address line
(from the processor) are used to enable a special device selection signal known as Chip Select
(CS).
Suppose, if the microprocessor need to communicate with the memory (either to write or
read from), the Chip Select (CS) pin of that particular memory should be enabled. At that time,
the address decoding circuit must ensure that the Chip Select (CS) pins of other devices are not
activated.
Let’s consider 2732 EPROM need to be interface with microprocessor. It is 4K× 8 bit
memory, so its address ranges from 0000H to 0FFFH.
CS CE
A12
Address
2732
Lines EPROM
A0 4096 x 8
O7 O0
Data
Lines
To read the data from this memory, the microprocessor need to perform the following
operations:
o Select the Chip.
o Identify the Register. (Memory Location)
o Enable the OE (Output Enable) Pin.
Since, the memory range from 0000H to 0FFFH; only 12 address line (A0-A12) will be
sufficient to select all the memory location uniquely. Assume the rest address lines (A12-A15)
must be 0000H to enable the Chip Select (CS).
…
BLEX
Microprocessor
E1 E2 E3
O7
MSB O6
A14
O5
3x8
O4
A13 Decoder O3
Logic O2
A12 74LS138 O1
O0 IO/M
RD
CS CE
Internal Decoder
A12
Address
2732
Lines EPROM
A0 4096 x 8
O/P Buffer
Data
Lines
O7 O0
This process of assigning address to a specific device depends on how many address lines
are assigned to access that device. Generally, there are two common methods; for mapping
address of these devices, they are:
o I/O Mapped I/O
o Memory Mapped I/O
In this method of address decoding, the I/O devices are addressed with 8-bit address, which
means that chip select signals for the devices are derived by using 8 address lines. In 8085
microprocessor, generally lower 8-bit address lines are used to derive the chip select signal. The
higher order address lines are unused and consider as don’t care condition. The instruction that
are used in I/O mapped I/O to communicate with the device are IN and OUT.
…
BLEX
Microprocessor
The instruction IN (Code DP) inputs data from an input device into the accumulator and the
instruction OUT (Code D3) send the contents of the accumulator to an output device. These are
two byte instructions, with the second byte specifying the address or the port number of an I/O
device. Typically, to display the contents of the accumulator at an output device with the
address, for example, 01H, the instruction will be written and stored in memory as follows:
If the output port with the address 01H is designed as a LED display, the instruction OUT
will display the contents of the accumulator at the port. The second byte of this OUT instruction
can be any of the 256 combinations of eight bits, from 00H to FFH. Therefore, the 8085 can
communicate with 256 different output ports with device addresses ranging from 00H to FFH.
Similarly, the instruction IN can be used to accept data from 256 different input ports.
In this method of address decoding, the I/O devices are address with 16-bit address. It means
that chip select signals for the devices are derived by using all 16 address lines from the
processor. So, all the I/O devices are treated as one of the memory location of the
microcomputer. All the instruction and signals that are used for memory access can be used for
accessing the I/O devices.
For example, LDA 5000H instruction will load the accumulator from the contents of address
5000H. If an input device, instead of memory location is connected at this address, the data from
that input device will load in accumulator. This is called memory mapped I/O technique.
On the previous example of EPROM interfacing, if A14 and A12 will be high as follow:
Then, some other I/O device connected at output (O5) of 3-to-8 decoder will be selected. In
this case, EPROM will not activate, because EPROM will be selected only when A12-A15 will
0000H.
Usually in microcomputer based on 8085, memory mapping is used for memory devices like
RAM, ROM, EPROM etc and I/O mapping is used for I/O devices like 8255A (Programmable
Peripheral Interface), 8251A (Programmable Communication Interface), input/output latches etc.
In both I/O Mapped I/O and Memory Mapped I/O mode, depending on the number of
address line used to select the device, there are two types of address decoding, they are:
o Unique Address Decoding/Absolute Decoding
o Non-Unique Address Decoding/Partial Decoding
…
BLEX
Microprocessor
If all of the address lines available on the mapping mode (i.e. available to select the chip) are
used for address decoding, then that decoding is called Unique Address Decoding. As the name
implies, in this mode, every devices will have single/unique address. This address decoding
technique is complicated but is best for all cases.
A7 A6 A5 A4 A3 A2 A1 A0
0 0 0 0 0 0 0 1 = 01H
A7
A6
D7 D7
A5
I/O Address Data
A4 Pulse Latch Vcc
G1 Bus
A3
D0 D0
A2
Latch
A1 Enable
A0
G2
(I/O Control Signal) IOW Device Select
Pulse
Here, we have the illustration for Unique Address Decoding. As shown in the figure 1 the
output latch gets enabled for low level logic (0). This will happen if the outputs latch of gate G2
goes low, which is possible only if the signal IOW and the output of gate G1 both go low. When
the signal IOW goes low the processor starts to transfer (write) the data to the address location.
The address decoding circuit uses only the lower order 8-bit address lines A0-A7. Hence the
outputs latch is configured in I/O mapping mode. The output of gate G1 can only become low in
the above case. So if A0 is high and A1 to A7 are low the latch gets enabled if the I/O control
signal IOW from the processor becomes low. The data to the output device can be transferred in
only one case and hence the device has unique address of 01H. This process of assigning the
single address to a device is called Unique Address Decoding.
If all of the address lines available for the mapping are not used in address decoding, then
that address decoding is called non-unique address decoding. The un-used address lines are
considered as don’t care condition. This technique of address decoding is simple to implement
but there may be a chance of address conflict. A single device may have more than one address.
…
BLEX
Microprocessor
A7 A6 A5 A4 A3 A2 A1 A0
0 0 0 0 0 0 1 0 = 02H
D7 D7
Data
Latch Vcc
Bus
D0 D0
Latch
Enable
A0
G2
(I/O Control IOW Device Select
Signal) Pulse
Here, we have the illustration for Non Unique Address Decoding. As shown in the figure 2
the output latch is again the low-level active device. Only one address line A0 is used to
generate the enable signal for the latch. The higher order address lines A1 to A7 are unused and
can be assumed as don’t care conditions.
The enable signal to the latch gets low if A0 goes low and the processor sends low level
output to its control pin IOW. When IOW goes low the latch gets enabled for every even
address because for even addresses A0 should be zeroes. For example if A1 = 1, A2 to A7 are
zeroes, the address of the latch is determined as enumerated in above figure i.e. 02H. The
multiple addresses for the device are 00, 02, 04 … FE etc. This type of address decoding is called
Non Unique Address Decoding.
Note: THE CONCEPT OF ADDRESS DECODING REGARDING PERIPHERAL MAPPED I/O & MEMORY
MAPPED I/O TECHNIQUES WILL BE FURTHER DISCUSSED IN NEXT CHAPTER “INTERFCING
I/O DEVICES”
…
BLEX
Microprocessor
Input/Output Interfaces
Contents:
o Input/Output Devices
o Input/Output Interfaces
o Serial Interface
o 8251 Programmable Communication Interface
o RS 232-C Standard
o Parallel Interface
o 8279 Programmable Keyboard/Display Interface
o IEEE-488 Bus Interface
o 8255A Programmable Peripheral Interface
…
BLEX
Microprocessor
Input/Output Devices
The input and output devices in a microcomputer system establish communication between
the microcomputer and external world. The MPU accepts data as input from devices and sends
data to output devices. There are two different methods by which I/O devices can be identified:
one uses an 8-bit address and the other uses a 16-bit address.
If we use LEDs as output or switches as input, we need to resolve two issues: how to
assign addresses and how to connect these I/O devices to the data bus. In bus architecture,
these devices cannot be connected directly to the data bus or the address bus; all connections
must be made through tri-state interfacing devices so they will be enabled and connected to
the buses only when the MPU chooses to communicate with them. In the case of memory,
we did not have to be concerned with these problems because of the internal address
decoding, Read/Write Buffers and availability of CS and control signals of the memory chip.
In the case of I/O devices, we need to use external interfacing devices.
The steps in communicating with an I/O device are similar to those in communicating
with memory and can be summarized as follows:
o The MPU places an 8-bit address on the address bus, which is decoded by external
decode logic.
o The MPU sends a control signal (I/O Read or I/O Write) and enables the I/O device.
o Data are transferred using the data bus.
…
BLEX
Microprocessor
Input/Output Interface
The link between the I/O devices and the microcomputer is maintained by a circuitry known
as I/O Interface. I/O Interface is a circuitry that connects I/O devices to the microcomputer. For
interfacing microprocessor to common peripherals (also called I/O devices); such as Keyboard,
CRT Terminal, Printer, Floppy Disk etc requires I/O Interface Circuit. In the 8085 based
systems, I/O devices can be interfaced using both techniques as we have discussed earlier i.e.
Peripheral Mapped I/O and Memory Mapped I/O Techniques. The process of data transfer in
both is identical. Each device is assigned a binary address, called device address or port number,
through it interfacing circuit. When the microprocessor executes a data transfer instruction for
an I/O device, it places the appropriate address on the address bus, sends the control signals,
enables the interfacing device, and transfer data. The interfacing device is like a gate for data
bus, which is opened by the MPU whenever it intends to transfer data. The two major types of
I/O interfaces are:
1. Serial Interface
2. Parallel Interface
Serial Interface
Serial communication involves the transmission of data from one place to another using
serial device. It means in serial transmission, only one line is used to transmit the complete
binary data bit by bit. Thus a serial interface exchanges data with the peripheral in serial mode
where the data are transmitted one bit at a time along a single communication link.
For example, to transmit the data 10010001, the data on the channel would be as shown
below:
D7 T
R R
B A E
U N C
F S E
M 1 0 0 1 0 0 0 1
F I
E I V
R T E
T R
D0 E
R
A parallel to serial converter is used to convert the incoming parallel data to a serial form
and then data is sent out with The Least Significant Bit (LSB) first and Most Significant Bit
(MSB) at last. Serial transmission is slow but inexpensive to implement as far as the number of
wire is concerned. Since only one wire is used for data transfer the amount of cross talk
(interference between different lines) decreases. Serial data transmission can be divided into
following two types.
Synchronous Serial Data Transmission
Asynchronous Serial Data Transmission
…
BLEX
Microprocessor
The basic feature of synchronous data transmission is that the data is transmitted or received
based on a clock signal and both the transmitter and receiver are synchronized with the common
clock signal.
It is also called clock oriented transmission because all bytes of block are transmitted
constantly. In this transmission, a block of data byte is transmitted along with the
synchronization information. Usually, one or two SYNC characters are used to indicate the start
of each synchronous data stream as shown below:
Clock
D7 T
R R
B A E
U N C
F S Data Data E
SYNC SYNC
F M Byte Byte I
E I V
R T E
T Block of Data
R
D0 E
R
At the receiver side, as soon as it matches one or two SYNC characters based on the
number of SYNC character used, the receiver starts interpreting the data. In synchronous
transmission, the transmitting device needs to send data continuously to the receiving
device. However, if data is not ready to be transmitting, the transmitter will send SYNC
characters until the data is available.
…
BLEX
Microprocessor
Clock Clock
D7 T
R R
B A E
Start Bit
U N C
F S E
M D7 D6 D5 D4 D3 D2 D1 D0
Stop Bit 1
Stop Bit 2
F I
E I V
R T E
T R
D0 E
R
The asynchronous transmission is generally used in low speed transmission less than 20
Kbps, but synchronous transmission transmits data greater than 20Kbps.
Each asynchronous serial data unit can be divided into equal time intervals called bit
intervals. An 8-bit data will have 8-bit intervals. Thus each data bit will correspond to one of
the 8 intervals. The format for asynchronous serial data contains the following information:
A low START bit that indicates beginning of the data to be transferred.
8 data bits, denoting the actual data being transferred.
An optional parity bit for either odd or even parity.
Baud Rate
The serial data transmission rate is also called the baud rate. The baud rate is defined
as the number of bits of data transmitted per second. Since each bit is transmitted over a
duration of one interval, Baud rate = 1/Bit Interval = Bits/Sec.
In parallel I/O, data bits are transferred when a control signal enables the interfacing
device; the transfer takes place in less than three T-states. However, in serial I/O, one bit
is sent out at a time; therefore, how long the bit stays on or off is determined by the
speed at which the bits are transmitted. Furthermore, the receiver should be set up to
receive the bits at the same rate as the transmission; otherwise, the receiver may not be
able to differentiate between two consecutive 0s and 1s.
0.83 ms
Bit TIme
Marking D0 D1 D 2 D 3 D 4 D 5 D 6 D 7
Start Bit
Stop Bit 1
Stop Bit 2
MSB
LSB
First Bit to be
Transmitted
…
BLEX
Microprocessor
Above figure shows how the ASCII character I (49H) will be transmitted with 1200
baud with the framing information of one Start and two Stop bits. The transmission
begins with an active low Start it, followed by the LSB-bit D0. The bit time-the delay
between any two successive bits is 0.83 ms; this is determined by the baud as follows:
1200 bits = 1 second
For 1 bit = 1/1200 = 0.83ms
Therefore, to transmit one character, a parallel byte (49H) should be converted into a
stream of 11 bits by adding framing bits and each bit must be transmitted at the interval
of 0.83 ms. To receive a character in the serial mode, the process is reversed-one bit at a
time is received and the bits are converted into a parallel word.
ASCII Character
The acronym ASCII stands for the “American Standard Code for Information
Interchange”. It is an 8-bit code commonly used with microprocessors for representing
alphanumeric codes. Out of the 8 bits first 7 bits are used to represent the character while
the 8th bit is used to test for errors and is referred to as parity bit. The parity bit can be set
to 1 or 0 so that the number of 1-bits in the byte either always odd or always even. The
standard ASCII Chart is given below:
STANDARD ASCII
CHART (0 – 127)
…
BLEX
Microprocessor
8 56 38h 9 57 39h
: 58 3Ah ; 59 3Bh
< 60 3Ch = 61 3Dh
> 62 3Eh ? 63 3Fh
B 64 40h A 65 41h
66 42h C 67 43h
D 68 44h E 69 45h
F 70 46h G 71 47h
H 72 48h I 73 49h
J 74 4Ah K 75 4Bh
L 76 4Ch M 77 4Dh
N 78 4Eh O 79 4Fh
P 80 50h Q 81 51h
R 82 52h S 83 53h
T 84 54h U 85 55h
V 86 56h W 87 57h
X 88 58h Y 89 59h
Z 90 5Ah [ 91 5Bh
\ 92 5Ch ] 93 5Dh
^ 94 5Eh _ 95 5Fh
` 96 60h a 97 61h
b 98 62h c 99 63h
d 100 64h e 101 65h
f 102 66h g 103 67h
h 104 68h i 105 69h
j 106 6Ah k 107 6Bh
l 108 6Ch m 109 6Dh
n 110 6Eh o 111 6Fh
p 112 70h q 113 71h
r 114 72h s 115 73h
t 116 74h u 117 75h
v 118 76h w 119 77h
x 120 78h y 121 79h
z 122 7Ah { 123 7Bh
| 124 7Ch } 125 7Dh
~ 126 7Eh DEL 127 7Fh
Notes:
With synchronous transmission, a block of bits is transmitted in a steady stream
without start and stop bit code. The block may be many bits in length. So, to prevent
timing drift between the transmitter and receiver, these blocks must somehow be
synchronized, for which there are two possibilities.
One possibility is to provide a separate clock line between transmitter and
receiver. One side pulses the line regularly and the other side uses it as a clock. This
technique works well over short distance; but over long distances, the clock pulse are
subjected to some impairment as data signal and timing error can occur.
Another efficient possibility is to synchronize the transmitter and receiver and
then send large block of data one after another. To indicate the start of transmission
the transmitter sends out one or more unique character called ‘SYNC’ character or a
unique bit pattern called ‘FLAG’. Receiver uses the ‘SYNC’ character or ‘FLAG’ to
synchronize its internal clock with that of the transmitter, receiver then shifts in the
data following the ‘SYNC’ character and convert them to parallel form to be read by
microprocessor.
…
BLEX
Microprocessor
…
BLEX
Microprocessor
Clock
Clock Clock
D7 T T
D7
R R R R
B A E A
B E
Start Bit
U N C N
U C
F S Data Data E S
SYNC SYNC F E
M Byte Byte M D7 D6 D5 D4 D3 D2 D1 D0
Stop Bit 1
I
Stop Bit 2
F F I
E I V I
E V
R T E T
Block of Data R E
T R T R
D0 E D0 E
R R
…
BLEX
Microprocessor
TRANSMITTER
D7-D0 Data
Bus Output TxD
Buffer Register
Transmitter
C/D=0 Buffer
RD or WR Register
(P-S) TxC
RESET Transmitter
Control TxRDY
C/D=1 Control
Internal Data Bus
Register TxE
CLK WR=0 Logic
(16-Bit)
C/D Read/Write
Control RECEIVER
Logic
WR
C/D=1 Status
Register Input RxD
RD RD=0
(8-Bit) Register
Receiver
CS Buffer
Register
(S-P) RxC
DSR Receiver
DTR Modem Control
Logic RxRDY
CTS Control
RTS
…
BLEX
Microprocessor
Input Signals
WR (Write): When this signal goes low, the MPU writes in the control register or
sends output data to the Data Buffer Register.
RD (Read): When this signal goes low, the MPU either reads a status from Status
Register or accept data from the Data Buffer Register.
CLK (Clock): This is the clock input for 8251A and is connected to the system clock.
The clock is necessary for communication with the microprocessor.
Control Register
The 16-bit control register split into two bytes. The first byte is called Mode Word
Instruction Register and second byte is Command Word Instruction Register.
Status Register
It checks the ready status of a peripheral, status of transmission, transmission error etc.
This is 3-state bidirectional buffer register used to interface 8251A to the system bus.
CS C/D RD WR Function
0 1 1 0 MPU writes instruction in the control register.
0 1 0 1 MPU reads status from status register.
0 0 1 0 MPU outputs data to the data buffer register.
0 0 0 1 MPU accepts data from the data buffer register
1 x x x 8251A is not selected
…
BLEX
Microprocessor
Transmitter Section
The transmitter accepts parallel data from the MPU and converts them into serial data for
the transmission. It has two register: A Buffer Register to hold eight bit data and an Output
Register to convert parallel data into serial data.
Transmitter control logic to controls all the operations related to the data transmission.
The transmission section has three output signals and one input signal.
TxD (Transmit Data): Serial bits are transmitted in this line.
TxC (Transmitter Clock): The transmitter clock controls the rate at which bits are
transmitted. This clock frequency can be 1 times the baud rate in synchronous
transmission mode and can be 1, 16 or 64 times in asynchronous transmission mode.
Suppose, Baud Rate = 110
In Synchronous Transmission Mode, TxC = 110 Hz
In Asynchronous Transmission Mode, TxC = 110 Hz in 1X Mode, TxC = 1.76 KHz in
16X Mode, TxC = 7.04 KHz in 64X Mode
TxRDY (Transmitter Ready): This output signal when goes high, it indicates that the
Buffer Register is empty and is ready to accept a data byte. This signal is reset when
a data byte is loaded into the buffer.
TxE (Transmitter Empty): This is also an output signal and when it goes high, it
indicates that output register is empty or 8251A has no character to send. This signal
is reset, when a data byte is transferred from Buffer Register to the output register.
Receiver Section
The receiver accepts serial data from the peripheral devices and converts them into the
parallel data and transfer to the microprocessor. It has two registers: A Buffer Register to
hold 8-bit data and an Input Register to accept the serial data from the peripheral & convert
them into the parallel data.
Receiver Control Logic controls all the operations related to the receiving data. The
receiver section has two input signals and one output signal.
RxD (Receive Data): Bits are received serially on this line and converted into a
parallel byte in the receiver input register.
RxC (Receiver Clock): The receiver clock controls the rate at which bits are received
by the 8251A. In synchronous mode, this clock can be 1 time the baud rate and in
asynchronous mode, it can be 1, 16, or 64 times the baud rate.
RxRDY (Receiver Ready): This is an output signal and when it goes high, it indicates
that 8251A has character in the receiver buffer register and is ready to transfer it to
the microprocessor.
Modem Control
The Modem Control is used to establish data communication through modems over
telephone lines. However, telephone lines are designed to handle voice; the bandwidth of
telephone lines ranges from 300 Hz to 3300 Hz. The digital signal with rise time in nsec
requires a bandwidth of several MHz. Therefore, data bits should be converted into audio
tones; this is accomplished through modems. A modem is a circuit that translates digital data
into audio tone frequencies for transmission over the telephone lines and converts audio
frequencies into digital data for reception.
…
BLEX
Microprocessor
Serial transmission of data is used as an efficient means for transmitting digital information
across long distances. The obvious advantage is the savings in hardware. Also the existing
communication lines usually the telephone lines can be used to transfer information.
The RS 232-C is an interface convention developed standardizes the interface between Data
Terminal Equipment (DTE) and Data Communication Equipment (DCE) employing serial binary
data exchange. One of the most common uses for RS 232-C is the connection of computer
terminals to computers. This is done both directly and indirectly through modems.
RS 232-C
MC 1488 Cable MC 1489
Data Data
Terminal Receive Transmit Communication
3 3
Equipment Equipment
(DTE) (DCE)
MC 1489 MC 1488
Computer Modem
GND GND
7 7
As we have known that modem and other devices used to send serial data are also called
Data Communication Equipment (DCE). The terminals or computers that are sending or
receiving the data are called Data Terminal Equipment (DTE). RS 232-C is the interface standard
developed by Electronic Industries Association (EIA) in response to the need for signal and
handshake standards between the DTE and DCE.
This standard describes the functions of 25 signal and handshake pins for serial data transfer.
It also describes the voltage levels, impedance levels, rise and fall times, maximum bit rate and
maximum capacitance for these signal lines. It also specifies that the DTE connector should be
male and the DCE connector should be female. Usually the 9-pin and 25-pin connectors are
available. The voltage levels for all RS 232-C are as follow:
The signal levels of RS 232-C are not compatible with that of The DTE and DCE, which are
TTL signals. Hence TTL to RS 232-C and RS 232-C to TTL conversions are required for
establishing the link between DTE and DCE. The line driver such as MC1488 ca n be used
between DTE and RS 232-C cable and MC1489 can be used between the RS 232-C cable and
DCE.
…
BLEX
Microprocessor
1 Protective Ground
Secondary Transmitted Data 14
2 Transmitted Data (TxD) DCE
Transmission Signal Element Timing (DCE Source) 15
3 Received Data (RxD) DTE
Secondary Received Data 16
4 Request to Send (RTS) DCE
Receiver Signal Element Timing (DCE Source) 17
5 Clear to Send (CTS) DTE
Unassigned 18
6 Data Set Ready (DSR) DTE
Secondary Request to Send 19
7 Signal Ground
DCE Data Terminal Ready (DTR) 20
8 Received Line Signal Detector
Signal Quality Detector 21
9 Reserved for Data Set Testing
Ring Indicator 22
10 Reserved for Data Set Testing
Data Signal Rate Selector (DTE/DCE Source) 23
11 Unassigned
Transmit Signal Element Timing (DTE Source) 24
12 Sec. Rec’d. Line Sig. Detector
Unassigned 25
13 Sec. Clear to Send
Among 25 pins of RS 232-C, the important pin numbers, the signal names and their descriptions
are listed in table below:
…
BLEX
Microprocessor
Parallel Interface
A Parallel Interface exchanges data with the peripheral in parallel mode, where all the n-bits
of data are transmitted simultaneously. Each bit in a word is transmitted on a separate line. So to
transmit a word of n-bits, there must be n-lines in parallel data transfer.
For example, to transmit the data 10010001, the data on the channel would be as shown
below:
T 1
R 0 R
A E
N 0 C
S 0 E
M I
I 1 V
T E
T 0
R
E 0
R
1
Parallel interface provides a faster exchange of data but becomes expensive due to the needs
of multiple communication links. So, it is impractical for exchanging data over a long distance.
Data
For example, consider the simple display device such as LED is always there and ready,
so microprocessor can send data to it at any time.
Simple Strobe Input & Output
In many applications, valid data is present on an external device only at a certain time,
so it must be read in at that time.
Data
STB
…
BLEX
Microprocessor
For example, consider the keyboard. When a key is pressed, keyboard sends out the
ASCII Code for the pressed key on eight parallel data lines, and then sends out a strobe
signal (STB) on another line to indicate that valid data is present to transmit.
Data
STB
ACK
STB
ACK
Data
First of the entire data sending device asserts STB signal low to ask, “Are you ready?”
The receiving system raises its ACK line high to indicate that it is ready. The sending device
(Computer/Peripheral) then sends the bytes of data and raises its STB signal high to say,
“Here is some valid data for you”. After receiving the data, the receiving system low its
ACK signal to indicate that it has received the data and waiting for next byte of data.
…
BLEX
Microprocessor
The information exchanged between a microprocessor and peripheral devices consists of I/O
data, control information and status information.
The status information tells the microprocessor about the readiness or status of the
peripheral devices. It may also enable the microprocessor to monitor the devices, to ensure that
it is in good operation condition. As for example, a printer indicates whether it has run out of
paper or the paper is jammed. Another example is about READY signal, while communication
with the memory device.
…
BLEX
Microprocessor
The data input and display are an integral part of many microprocessor based systems. The
system designer needs an interface that can control this operation. With this in mind, Intel
Corporation brought out 8279 Chip to interface with their 8-bit microprocessor. The 8279 is a
hardware approach to interfacing keyboard and display.
The 8279 is a 40-pin device, which functionally consists of four different sections:
DB0-DB7 IRQ
CLK RESET RD WR CS A0
Keyboard
Display 16 x 8 Control and 8x8
Debounce
Address Display Timing FIFO/Sensor
&
Register RAM Registers RAM
Control
Timing
Display &
Registers Control Scan Counter Return
SHIFT
OUT A0-A3 OUT B0-B3 BD SL0-SL3 RL0-RL7 CNTL/STB
…
BLEX
Microprocessor
The IRQ is an output line that becomes active when key data exists in an internal FIFO
(First-In-First-Out) RAM of 8279. This line is usually connected to one of the hardware
interrupt line of the MPU.
The RD and WR are the control signals used to perform read and write operation
respectively. The CS and RESET signal are used to select and reset the 8279 respectively.
The clock signals are used to generate internal timing. A high on the A0 pin indicates that the
signals are command or status signal and a low indicate that they are data.
Keyboard Section
This section includes eight return lines (RL0-RL7) that can be connected to eight columns
of a keyboard, SHIFT and CNTL/STB (Control/Strobe) lines. Basically there are three
modes of operations:
Scanned Keyboard Mode
Sensor Matrix Mode
Strobed Input Mode
MSB LSB
CNTL SHIFT
SCAN RETURN
In the above figure, the three return bits D0, D1 and D2 comprise the column of
keyboard and the three scan line D3, D4 and D5 be the row of the keyboard.
In this scanned keyboard mode, there are two further alternative ways of operations:
2-Key Lockout
N-Key Rollover
…
BLEX
Microprocessor
In 2-Key Lockout Mode, if two keys are pressed almost simultaneously (i.e.
without releasing the first pressed key, a second key is pressed); only the first key is
recognized. The recognized key code is then taken into FIFO RAM and IRQ is
activated. If the FIFO RAM is full, the key code is not entered, rather error flag is set.
In N-Key Rollover Mode, when a key is pressed, the debounce logic is set and the
debounce circuits waits for two keyboard scans and then clocks again whether the
key is till pressed. If it still is, the key code is stored in FIFO RAM. In this mode,
there is no limit to the number of keys that can be pressed for a simultaneous
depression, the key code are entered into FIFO RAM according to the order of the
key pressed. If during single debounce cycle, two keys are pressed, then error flag
will be set.
MSB LSB
In this mode, the debounce logic is inhibited. The IRQ line goes high, if a sensor
value is found to have changed at the end of a sensor matrix scan.
MSB LSB
…
BLEX
Microprocessor
Scan Section
The scan section consists of a scan counter and four scan lines (SL0-SL3). The scan
counter can be operated in either encoded or decoded mode.
In the encoded mode, generally out of four scan lines, 3 scan lines (SL0-SL2) are fed to
the 3-to-8 decoder (external to the 8279), that generates eight decoded scan lines. Combining
these with the eight return lines, one can form as microprocessor to 8x8 keyboard matrix,
which can be used for defining 64 different characters.
In the decoded mode, which uses an internal decoder (present inside the 8279), tow least
significant bits are decoded which is combined with eight return lines (RL0-RL7) and the
SHIFT and CNTL line to permits 4 x 8 x 4 = 128 different character definition.
Display Section
The display section consists of display address registers, 16x8 display RAM, Display
register and eight output lines divided into two groups A0-A3 and B0-B3. It also consist
the single BD (Blank Display) output line, which is used to blank the display during digit
switching.
The display address registers hold the address of the word currently being written or
read by the CPU. These addresses can be set to auto increment after each read or write.
The display RAM can be directly read by the CPU after the correct mode and address is
set.
The A and B nibble, out of 8 output lines can be entered independently or as one
word, according to the mode set. Data entry to the display can be set to either left or
right entry.
Left Entry (Type Writer) Mode: In the left entry mode, the first character typed
appears at the extreme left, then the carriage advances one step (auto-increment),
then second character appears on the right of the first character and so on.
Right Entry (Calculator) Mode: In right entry mode, the first character entered
appears at the right most display position. When a second character enters, the first
character shift one place to the left on the display and the second character appears to
its right. At the third entry, both the first and the second characters move one
position left and the third character appears again at the right most position.
…
BLEX
Microprocessor
The IEEE - 488 standards defines a byte-serial, 8-bit parallel, asynchronous type instrument
interface. It is a document that describes the rules, specifications, timing relationships, physical
characteristics etc of an interfacing technique that allows digital instruments and devices to be
interconnected. It is a hardware (wires, connectors etc) that is used to implement the standard.
Sixteen signals line comprise the complete IEEE – 488 bus structure as shown below.
1 D 1
2 A 2
T
3 A 3
4 4
5 L 5
I
6 N 6
7 E 7
8 S 8
Hand-Shake Lines
1 DAV 1
2 NRFD 2
3 NDAC 3
Bus Management Lines
4 IFC 4
5 ATN 5
6 REN 6
7 SRQ 7
8 EOI 8
Fig: IEEE – 488 Interface
Legend:
Bus Management Lines
EOI – End or Identity
SRQ – Service Request
REN – Remote Enable
ATN – Attention
IFC – Interface Clear
Hand-Shake Lines
NDAC – Not Data Accepted
NRFD – Not Ready For Data
DAV – Data Valid
Since, it is not guaranteed by the standard that instruments will send information coded in
this suggested manner, two IEEE – 488 interconnected instruments may always be able to talk to
each other, but they may not always be able to understand each other.
…
BLEX
Microprocessor
D7 T T 1
R R
R 0 R
A A
B E E
N N 0
U C C
S
F S E 0 E
1 0 0 1 0 0 0 1 M
M I I
F I 1
I V
E V T
T E
R E T 0
T R
R E
0
D0 E R
R 1
…
BLEX
Microprocessor
The 8255A is a widely use, programmable, parallel I/O device. It can be programmed to
transfer data under various conditions, from simple I/O to interrupt I/O. It is flexible, versatile
and economical (when multiple I/O ports are required), but somewhat complex.
The 8255A has 24 I/O pins that can be grouped primarily in two 8-bit parallel ports: A
and B, with the remaining eight bits as port C. The eight bits of port C can be used as individual
bits or be grouped in two 4-bit ports: CUPPER (CU) and CLOWER (CL) as in figure given below. The
functions of these ports are defined by writing a control word in the control register.
Port A
CU
8255A Port C
CL
Port B
The following figure shows all the functions of the 8255A, classified according to two
modes: The Bit Set/Reset (BSR) Mode and The I/O Mode. The BSR Mode is used to set or reset
the bits in Port C. The I/O Mode is further divided into three modes: Mode 0, Mode 1 and
Mode2. In Mode 0, all ports function as simple I/O ports. Mode 1 is a handshake mode whereby
ports A and/or B use bits from port C as handshake signals. In the handshake mode, two types of
I/O data transfer can be implemented: Status Check and Interrupt. In Mode 2, port A can be set
up for bidirectional data transfer using handshake signals from port C and port B can be set up
either in Mode 0 or Mode 1.
Control Word
D7 D6 D5 D4 D3 D2 D1 D0
0/1
…
BLEX
Microprocessor
The block diagram of 8255A is shown below. It has two 8-bit ports (A and B), two 4-bit ports
(CU and CL), and the data bus buffer and control logic. The simplified but expanded version of
the internal structure, including a control register can be shown in the next figure.
Group A
Port I/O
A PA7-PA0
(8)
Group
A
Control
…
BLEX
Microprocessor
RD
WR
WR
Port
A
00
Control
Register RD
WR
EN
Port
CS C
10 EN
11
A1 10 RD
Internal C
01
A0 Decoding B WR
00
A
Port
B
Fig: Expanded Version of the 01 EN
Control Logic and I/O Ports
Control Logic
The control section has six lines. Their functions and connections are as follows:
RD (Read): This control signal enables the read operation. When the signal is low, the
MPU reads data from a selected I/O port of 8255A.
WR (Write): This control signal enables the write operation. When the signal goes low,
the MPU writes into a selected I/O port or the control register.
RESET (Reset): This is an active high signal. It clears the control register and sets all
ports in the input mode.
CS, A0 and A1: These are device select signals. CS is connected to a decoded address.
And A0 and A1 are generally connected to MPU address lines A0 and A1 respectively.
The CS signal is the Master Chip Select, and A0 and A1 specify one of the I/O ports or the
control register as given below:
CS A1 A0 Selected
0 0 0 Port A
0 0 1 Port B
0 1 0 Port C
0 1 1 Control Register
1 x x 8255A is not selected
…
BLEX
Microprocessor
I/O Ports
It has two 8-bit ports (A and B), two 4-bit ports (CU and CL).
Port A
- Can be used as an 8-bit input port.
- Can be used as an 8-bit output port.
Port B
- Can be used as an 8-bit input port.
- Can be used as an 8-bit output port.
Port C
- Can be used as an 8- input or output port.
- Can be used as 4-bit ports.
- Can be used to produce handshake signals for ports A and B.
…
BLEX
Microprocessor
Control Word
The above figure of 8255A Expanded Version of Control Logic & I/O Ports shows a
register called the control register. The contents of this register, called the control word,
which specify an I/O function for each port. This register can be accessed to write a control
word when A0 and A1 are at logic 1, as mentioned in above table. The register is not
accessible for a Read Operation.
Bit D7 of the control register specifies either the I/O function or the Bit Set/Reset
function as classified in fig: 8255 A Operating Modes. If bit D7 = 1, bits D6-D0 determine I/O
functions in various mode as shown in figure below. If bit D7 = 0, port C operates in the Bit
Set/Reset (BSR) mode. The BSR control word does not affect the functions of ports A and B.
To communicate with peripherals through the 8255 A, three steps are necessary.
o Determine the addresses of ports A, B & C and of the control register according to
the Chip Select Logic and Address Lines A0 and A1.
Control Word
D7 D6 D5 D4 D3 D2 D1 D0
Group B
Port C (Lower: PC3-PC0)
1 = Input
0 = Output
Port B
1 = Input
0 = Output
Mode Selection
0 = Mode 0
1 = Mode 1
Group A
Port C (Upper: PC7-PC4)
1 = Input
0 = Output
Port A
1 = Input
0 = Output
Mode Selection
00 = Mode 0
01 = Mode 1
1x = Mode 2
1 = I/O Mode
0 = BSR Mode
…
BLEX
Microprocessor
D7 D6 D5 D4 D3 D2 D1 D0
Input/Output Mode
…
BLEX
Microprocessor
A = 80 H
A7
CS
A6 8
A1 A1 2
A5
A0 A0 5 C = 82 H
A4 5
IOR RD
A3 A
IOW WR
A2
B = 81 H
Reset
Hex
CS Port
Address
A7 A6 A5 A4 A3 A2 A1 A0
1 0 0 0 0 0 0 0 = 80 H A
0 1 = 81 H B
1 0 = 82 H C
1 1 = 83 H Control
Register
…
BLEX
Microprocessor
Solution
1. Port Addresses: This is a memory-mapped I/O; when the address line A15 is high, the Chip
Select line is enabled. Assumming all don’t care lines are at logic 0, the port addresses are as
follows:
Port A = 8000H (A1 = 0, A0 = 0)
Port B = 8001H (A1 = 0, A0 = 1)
Port C = 8002H (A1 = 1, A0 = 0)
Control Register = 8003H (A1 = 1, A0 = 1)
2. Control Word:
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 1 1 = 83 H
3. Program
4. Program Description: The circuit shown below for this problem is designed for memory-
mapped I/O; therefore, the instructions are written as if all the 8255A ports are memory
location. The ports are initialized by the control word 83H in the control register. The
instructions STA and LDA are equivalent to the instructions OUT and IN respectively.
In this example, the low four bits of port C are configured as input and the high four bits
are configured as output; even though port C has one address for both halves CU and CL
(8002H). Reand and Write operations are differentiated by the control signals MEMR and
MEMW. When the MPU reads port C (e.g. LDA 8002H), it receives eight bits in the
accumulatro. However, the high-order its (D7-D4) must be ignored because the input data bits
are in PC3-PC0. To displaythese bits at the upper half of port C, bits (PC3-PC0) must be
shifted to PC7-PC4.
…
BLEX
Microprocessor
LEDs
PA7
BUFFER
PA0
+5V
PC7
BUFFER
A15 CS
PC4
8255 A
PC3
DIP Switches
PC0
A1 A1
PB7
A0 A0
MEMR RD PB0
MEMW WR
RESET OUT
(8085)
+5V
…
BLEX
Microprocessor
Solution
D7 D6 D5 D4 D3 D2 D1 D0
To Set Bit PC7 0 0 0 0 1 1 1 1 = 0FH
To Reset Bit PC7 0 0 0 0 1 1 1 0 = 0E H
To Set Bit PC3 0 0 0 0 0 1 1 1 = 07 H
To Reset Bit PC3 0 0 0 0 0 1 1 0 = 06 H
2. Port Address
Control Register Address = 83 H
3. Subroutine
BSR: MVI A, 0F H ; Load byte in accumulator to set PC7
OUT 83 H ; Set PC7 = 1
MVI A, 07 H ; Load byte in accumulator to set PC3
OUT 83H ; Set PC3 = 1
CALL DELAY ; This is a 10-ms delay
MVI A, 06H ; Load accumulator with the byte to reset PC3
OUT 83 H ; Reset PC7
MVI A, 0E H ; Load accumulator with the byte to reset PC7
OUT 83 H ; Reset PC7
RET
4. Analysis
To set/reset bits in port C, a control word is written in the Control Register and not in port C.
A BSR contrl word affects only one bit in port C.
The BSR control word does not affect the I/O mode.
…
BLEX
Microprocessor
Interrupts
Contents:
o Interrupt: Introduction
o 8085 Interrupts
o Interrupt Service Routine & Its Requirement
o Interrupt Structure
o 8086 Interrupt System
o 8259A Programmable Interrupt Controller
…
BLEX
Microprocessor
An interrupt is process, getting attention of the microprocessor to perform some another task
while it is busy in doing something else.
When microprocessor is busy in executing one program, it can be stop for the execution of
the current program temporarily and can deviates its execution process to another one. After
performing the requested task, it returns to the previous program from where it has deviated.
This process is called interrupt. The interrupt process is asynchronous, that means it can be
initiated at any time without reference to the system clock. However, the response to an
interrupt request is directed or controlled by the microprocessor.
8085 Interrupts
Microcomputers can transfer data to or from an external device using the interrupt I/O. In
order to accomplish this, the microcomputer uses a pin on the microprocessor chip called the
Interrupt Pin (INTR). The external I/O device is connected to this pin.
When the device wants to communicate with the microcomputer, it makes the signal on the
interrupt line high or low, depending on the microcomputer. The microcomputer responds by
sending signal via its pin called Interrupt Acknowledgement (INTA).
Mainly, the interrupts are typically classified into two types, they are:
External Interrupt
Internal Interrupt
External Interrupt
An external interrupt is caused by a device that is external to the processor i.e. these are
usually initiated via the microprocessor’s interrupt pins by external devices such as A/D
converters. External Interrupt can be further divided into two types.
MI (Maskable Interrupt)
NMI (Non Maskable Interrupt)
o EI (Enable Interrupt): This is a one byte instruction. This instruction sets the interrupt
enable flip flop and enables all the interrupts. The interrupt request is disable by system
reset or by interrupt response process.
o DI (Disable Interrupt): This is also one byte instruction. This instruction resets the
interrupt enable flip flop and hence disable all the interrupt except TRAP.
…
BLEX
Microprocessor
When the interrupt is disabled, the interrupt enable flip flop is reset to 0 and no Maskable
Interrupts are recognized by the processor. RST 7.5, RST 6.5, RST 5.5 and INTR are Maskable
Interrupts.
If the interrupt request cannot be disabled and microprocessor must response to it, such
interrupt is called Non Maskable Interrupt. The microprocessor can ignore or delay a Maskable
Interrupt request if it is performing some critical task; however, it has to respond to a Non
Maskable Interrupt request immediately. The 8085 has one Non Maskable Interrupt TRAP
The Non Maskable Interrupt has the higher priority over the Maskable Interrupt and cannot
be enabled or disabled by instructions. This means that if both the Maskable and Non Maskable
Interrupts are activated at the same time the then processor will service the Non Maskable
Interrupt first. This gives the concept of Interrupt Priority which will be discussed in later. So,
the priorities for servicing the interrupt requests among a number of devices depend on the type
of interrupt and the design of the specific microcomputer system (both hardware and software).
Internal Interrupt
Internal interrupts are activated internally by exceptional conditions such as overflow,
division by zero and execution of an illegal Opcode. They are handled in the same way as
external interrupt. Internal Interrupts can also be activated by execution of TRAP.
When TRAP instruction is executed, the processor is interrupted and serviced in the same as
External Interrupts. This interrupt is useful for operating the microprocessor in Single Step Mode
and hence important in Debugging.
The difference between internal and external interrupt is that the internal interrupt is initiated
by some exceptional conditions caused by the program itself rather than by an external events.
Internal interrupts are synchronous with the program, while external interrupts are
asynchronous. If the program is return, the internal interrupt will occur in the same place each
time. External interrupts depend on external conditions that are independent of the program
being executed at the time.
…
BLEX
Microprocessor
In Non-Vectored Interrupt, the device will have to supply the address of the subroutine to
the microprocessor i.e. they require external hardware to supply a call location to restart the
execution. The 8085 has only Non Vectored Interrupt i.e. INTR (Interrupt Request).
INTR
The INTR is different from other four interrupts. This interrupt is not automatically vectored
as other interrupts do. When INTR is requested, an external hardware connected to the data bus
delivers one restart instruction out of eight restart instruction discussed below and according to
which the microprocessor is vectored or transferred to the particular memory location.
Binary Code Call Location in
Mnemonics HEX Code
D7 D6 D5 D4 D3 D2 D1 D0 HEX
RST 0 1 1 0 0 0 1 1 1 C7 0000 H
RST 1 1 1 0 0 1 1 1 1 CF 0008 H
RST 2 1 1 0 1 0 1 1 1 D7 0010 H
RST 3 1 1 0 1 1 1 1 1 DF 0018 H
RST 4 1 1 1 0 0 1 1 1 E7 0020 H
RST 5 1 1 1 0 1 1 1 1 EF 0028 H
RST 6 1 1 1 1 0 1 1 1 F7 0030 H
RST 7 1 1 1 1 1 1 1 1 FF 0038 H
These are 1-byte Call instructions that transfer the program execution to a specific memory
location on page 00H. The RST instructions are executed in a similar way to hat of Call
instructions. The address in the Program Counter (meaning the address of the next instruction to
an RST instruction) is stored on the stack before the program execution is transferred to the RST
call location. When a processor encounters a Return instruction in the subroutine associated
with the RST instruction, the program returns to the address that was stored on the stack.
For example to implement the instruction RST 5, a circuit can be used as shown in below;
where RST 5 is decoded, a 1-byte Call instruction to location 0028H.
…
BLEX
Microprocessor
+5V
Tri-State Buffer
DI7 1
DI6 1
DI5 1
DI4 0
Data
EFH
Bus
DI3 1
DI2 1
DI1 1
DI0 1
INTA from
Enable Microprocessor
TRAP
TRAP, a Non Maskable Interrupt known as NMI. It has the highest priority among the
interrupt signals, it need not be enabled and it cannot be disabled. It is level and edge
sensitive, meaning that the input should go high and stay high to be acknowledged. It cannot
be acknowledged again until it makes a transition from high to low to high. When this
interrupt is triggered, the program control is transferred to location 0024H without any
external hardware or the interrupt enable instruction EI. TRAP is generally used for such
critical events as power failure and emergency shut-off.
…
BLEX
Microprocessor
SIM Instruction
This is a multipurpose 1-byte instruction and used to implement the 8085 interrupts (RST 7.5,
6.5 & 5.5) and Serial Data Output (SOD). SIM Instruction can be used fro three different
functions:
One function is to set mask for RST 7.5, 6.5 & 5.5 interrupts. This instruction reads the
content of the accumulator and enables or disables the interrupts according to the content of
the accumulator. Bit D3 is a control bit and should be equal to logic level 1 for bits D0, D1
and D2 to be effective. Logic 0 on D0, D1 and D2 will enable the corresponding interrupts and
logic 1 will disable the interrupts.
The second function is to reset RST 7.5 flip flop. Bit D4 is additional control for RST 7.5. If
D4 = 1, RST 7.5 is reset. This is used to override or ignore RST 7.5 without servicing it.
The third function is to implement serial I/O. Bits D7 and D6 of the accumulator are used for
serial I/O and do not affect the interrupts. Bit D6 = 1 enables the serial I/O and bit D7 is used
to transmit (output) bits.
D7 D6 D5 D4 D3 D2 D1 D0
SOD SDE XXX R 7.5 MSE M 7.5 M 6.5 M 5.5
Because there are several interrupt lines, when one interrupt request is being served, other
interrupt requests may occur and remain pending. The 8085 has an additional instruction called
RIM (Read Interrupt Mask) to sense these pending interrupts.
…
BLEX
Microprocessor
RIM Instruction
This is also multipurpose 1 byte instruction used to read the status of interrupts RST 7.5, 6.5
& 5.5 and to read serial data input bit. RIM instruction can be used for the following functions:
This instruction loads the accumulator with 8-bits indicating the current status of the
interrupt masks.
The RIM instruction loads eight bits in the accumulator with the following interpretations.
D7 D6 D5 D4 D3 D2 D1 D0
SID I7 I6 I5 IE 7.5 6.5 5.5
Interrupt Priority
Since, the 8085 has five interrupt lines (TRAP, RST 7.5, RST 6.5, RST 5.5 & INTR). We
know all the interrupts can be masked except TRAP. Microprocessor responses to interrupt
instantly when interrupt request appears on one of interrupt line. If two or more than two
interrupts request appears at the same time, there will be confusion for the microprocessor that
which request to serve first. But this problem is solved by assigning priority to each interrupt
lines. The TRAP has highest priority followed by RST 7.5, RST 6.5, RST 5.5 & INTR
respectively.
Data transfer between the CPU and an I/O device is initiated by the CPU. However, the CPU
cannot start the transfer unless the device is ready to communicate with the CPU. The readiness
of the device can be determined from and interrupt signal. The CPU responds to the interrupt
request by storing the return address from PC into a memory stack and then the program
branches to a service routine that process the required transfer.
…
BLEX
Microprocessor
In microcomputer a number of I/O device are attached to the processor, with each device
being able to originate an interrupt request. The first task of the interrupt system is to indemnify
the source of the interrupt. There is also the possibility that several sources will request service
simultaneously. In this case the system must also decide which device to service first.
An interrupt priority is a system that established a priority over the various sources to
determine which condition is to be serviced first when two or more request arrive
simultaneously. The system may also determine which conditions are permitted to interrupt the
computer while another interrupt is being serviced. Higher-priority interrupt levels are assigned
to request which, if delayed or interrupted, could have serious consequences. Device with higher
speed transfers such as magnetic disks are given high priority, and slow devices such as
keyboards receive low priority. When two devices interrupt the processor at the same time, the
processor services the device with the higher priority at first.
There are mainly two ways of servicing multiple interrupts, they are: Polled Interrupt and
Chained (Vectored) Interrupt. The details on these two categories are explained later.
Interrupts Response
An interrupt is considered to be an emergency signal that may be services. The
microprocessor may respond to it as soon as possible. Responding to an interrupt may be
immediate or delayed depending on whether the interrupt is Maskable or Non Maskable and
whether interrupts are being masked or not.
Step 1: The interrupt process should be enabled by writing the instruction EI in the main
program.
Step 2: MPU checks the INTR line during the execution of each instruction.
Step 3: If INTR line is high and interrupt is enabled, MPU completed the current instruction,
disable the interrupt and sent an acknowledge signal INTA.
Step 4: The signal INTA is used to insert a restart (RST) instruction through external hardware.
The RST instruction transfers the program control to specific memory location.
Step 5: When microprocessor receives RST instruction, it saves the memory address of next
instruction on the stack. The program control is transferred to call location.
Step 6: The ISR perform the specific task of the interrupt. The ISR must include EI instruction
to enable the interrupt.
Step 7: At the end of ISR, the RET instruction returns the memory address from where the
program was interrupted and continues the execution.
…
BLEX
Microprocessor
A special program caused to service an interrupt request is called Interrupt Service Routine
(ISR). When interrupt occurs, the CPU reads the ISR address from Interrupt Vector Table and
program ntrol transfers to ISR. The ISR then saves the processor registers on the stack and body
of ISR executes. When it finishes, the registers are restored and the instruction RET at the end of
ISR returns the program control from where it is interrupted.
Interrupt increases the efficiency of a computer system because the external devices require
the attention of the processor as needed. If the system had no interrupt, the processor would
have to poll every device in the system periodically to see if any of then required attention.
Many of the standard I/O devices generate interrupts, when they need the processor to process
data being received by or being sent by these interfaces.
As interrupt is a process of getting attention of microprocessor to perform some task while it
is busy in doing something else. The task or routine that the microprocessor executes in
response to interrupt is termed as Interrupt Service Routine (ISR).
Before executing the ISR, the microprocessor needs to save the required information to
resume the current program after executing the ISR. So the fundamental requirement of the ISR
is that it should begin by saving the contents of all registers and flags. After the completion of
the ISR, it needs to restore all the registers before returning to main program.
Call and Return instructions are associated with the subroutine technique. A ‘Subroutine’ is
a group of instructions that performs a subtask. The subroutine is written as a separate unit,
apart from the main program and the microprocessor transfer the program execution from the
main program to the subroutine, whenever it is called to perform the task. After the completion
of the subroutine task the microprocessor return to the main program. The subroutine technique
eliminates the need to write a subtask repeatedly; thus it uses memory more efficiently. Before
implementing the subroutine technique, the stack must be defined. This stack is used to store the
memory address of the instruction in the main program that follows the subroutine call.
The 8085 microprocessor has two instructions to implement subroutine: CALL (call a
subroutine) and RET (return to main program from subroutine). The CALL instruction is used in
the main program to call a subroutine and RET instruction is used at the end of the subroutine to
return to the main program. When a subroutine is called, the contents of program counter, which
is the address of the instruction following the CALL instruction is stored in the stack and the
program execution is transferred to the subroutine address. When the RET instruction is
executed at the end of the subroutine, the memory address stored in the stack is retrieved and the
sequence of execution is resumed in the main program.
Consider the following assembly language program, which illustrate what happens when the
CALL and RET instructions are used.
…
BLEX
Microprocessor
The main program is loaded within the address of 4000H to 400DH. The subroutine starts
from address 4050H and ends at 4056H. The first instruction LXI SP, 4400 in the main program
initializes the stack pointer register as shown in figure below:
43FC
43FD
43FE
43FF
4400 SP
The stack pointer points to memory location whose address is 4400H, after execution of
instruction LXI SP, 4400H. From address 4008H to 400AH, the 3-byte CALL instructions is
loaded, which specifies the address of the first instruction of the subroutine to be 4050H. The
address of the next instruction following the CALL instruction is 400BH, which is the content of
program counter at the instant when CALL instruction is executed.
At the instant of execution of CALL instruction PC = 400BH. After the execution of CALL
instruction, the contents of PC will be loaded to the top of stack. In this process, the stack
pointer decrements by one and pointes to 43FFH and the higher order address (higher byte) of
program counter which is 40 in this case will be loaded at this address. Then the stack pointer
further decrements by one and the lower order address (lower byte) of program counter which is
0B in this case will be loaded to the address 43FE. So the new address of stack pointer will be
43FE.
43FC
43FD
43FE 0B SP
43FF 40
4400
…
BLEX
Microprocessor
The next thing that will happen after execution of CALL at address 4008 is that the program
counter will be loaded with the address 4050H and the sequence of program transfers to the
address 4050H where the microprocessor executes its first instruction. At the end of the
subroutine there is RET instruction. After execution of RET the following things will happen:
The microprocessor pops off the data, which is actually the address of the next instruction
following the CALL instruction in the main program and loads into the program counter. The
program counter first gets loaded with the data 0B of the memory location 43FE where the stack
pointer is currently pointing. The stack pointer then increments by on and points to memory
location 43FF, whose contents is 40. The program counter is then loaded with this higher order
address so that the 16-bit loaded address of PC will become 4000B and the stack pointer will be
again incremented by one. So execution of RET transfer the sequence of program control to the
main program from the subroutine. So this is the process how the program control switches
between the main program and subroutine when CALL and RET instruction is executed.
Interrupt Structure
The 8085 Interrupt Structure is shown in figure below. In order to enable the interrupt, we
use the instructions EI and SIM. The execution of EI instruction sets the RS flip flop and makes
one of the inputs to the AND gate 1 to 4 HIGH. Hence, in order for all the interrupts (except
TRAP) to work, the interrupt system must be enabled.
1
D Q
2 RST 7.5 003C16
Q
CLR
Reset
003816
RST 7.5 Interrupt Recognized
3 RST 6.5
003416
003016
4 RST 5.5
002C16
002816
1 TRAP 002416
002016
EI S Q 001816
DI
Reset R Interrupt 001016
Any Interrupt Recognized Enable
Get RST
000816
Code from
External
5 INTR 000016
Hardware
…
BLEX
Microprocessor
Consider only the RST 7.5 Interrupt is to be enabled, the interrupt mask bit for RST 7.5 is set
to low, making the two inputs to AND gate 1 HIGH. Now, if there is the interrupt signal to
RST 7.5 pin, it sets the D flip flop, thus making the O/P of AND gate 1 HIGH and enables
RST 7.5.
The 8085 branches to location 003CH to service routine.
RST 6.5 and RST 5.5 can be similarly explained.
Execution of the DI instruction clears RS flip flop and disables all the interrupts except
TRAP.
A microprocessor may be connected to more than one peripheral and most of the peripherals
can originate an interrupt request. But there are only five interrupt input lines in 8085
microprocessor. So, more than one device needs to be connected in the single interrupt line.
When the interrupt request generates in such line, first of all microprocessor needs to identify
the interrupting device, so to handle this problem microprocessor provides two approaches:
Polling
Chaining
Polling
Polling is the software approach used to identify the interrupting device on the priority basis.
In this method, when an interrupt generates, the execution control transfers to one common
branch address and execute one general initial service routine for all devices. All the devices
connected to the single interrupt request lines are polls in sequence. The order in which they are
polled or tested determines the priority of each device.
The highest priority device is polled first and if this device has generates the interrupt, the
execution control branches to the service routine for that device. Otherwise, the next or second
higher priority device is tested and so on.
Polled interrupt is very simple but for a large number of devices, the time required to poll
each device may exceed the time to service the device. In such case, the faster mechanism called
vectored or chained interrupt is used.
PBN
PAN
PB2
PA2
P PB1
PA1
INTR
…
BLEX
Microprocessor
Chaining
Chaining is the hardware approach used to identify the interrupting device on the priority
basis. In this method, there is one common interrupt request line through which all the devices
connected to it request the interrupt. Two or more devices that can originate the interrupt are
connected in series as shown below:
INTR
INTA
P
When a device requests an interrupt, the microprocessor issues the INTA (Interrupt
Acknowledge) signal in response. The INTA signal is first received by highest priority device,
which is device 1 in this case. If the device has generated the interrupt, it will accept the INTA
signal and place the vectored/transferred address on data bus. Otherwise, it will pass the INTA
signal to next device until the INTA signal is accepted by the interrupting device.
The word or address placed on data bus is referred to as vector, which the microprocessor
uses as a pointer to points the appropriate device service routine. This avoids the need to execute
a general initial service routine first as in the case of polling.
Summary
The 8085 interrupts and their requirements are listed in the table below in order of their
priority. TRAP has the highest priority and INTR has the lowest priority. It must be emphasized
that an interrupt can be recognized only if the HOLD signal is inactive.
Interrupts Type Instructions Hardware Trigger Vector
Non No External Level & Edge
TRAP Independent of EI & DI 0024H
Maskable Hardware Sensitive
Controlled by EI & DI No External
RST 7.5 Maskable Edge Sensitive 003CH
Unmasked by SIM Hardware
Controlled by EI & DI No External
RST 6.5 Maskable Level Sensitive 0034H
Unmasked by SIM Hardware
Controlled by EI & DI No External
RST 5.5 Maskable Level Sensitive 002CH
Unmasked by SIM Hardware
RST Code from 0038H
INTR Maskable Controlled by EI & DI Level Sensitive
External Hardware 0000H
Table: Summary of Interrupts in 8085A Microprocessor
…
BLEX
Microprocessor
The 8086 assigns every interrupts a type code so that the 8086 can identify it. Interrupts can
be initiated by:
o External Devices
o Internally]
o By S/W Instructions
o Exceptional Condition such as Divide by 0, Overflow etc.
The user must provide the desired IP and CS values in the interrupt pointer table. The user
may also initiate these interrupt through H/W or S/W.
…
BLEX
Microprocessor
The Interrupt Vector Table is a table which stores the interrupt vectors for 256 interrupts. It
is located in first 1024 bytes of memory at address 000000H-0003FFH. The lowest five types are
dedicated to specific interrupt (Pre-defined Interrupts). Interrupt type 5 to 31 are reserved by the
INTEL. Interrupt type 32 to 255 are available for user interrupt (Hardware & Software
Interrupts).
…
BLEX
Microprocessor
Read/Write Logic
This is a typical Read/Write control logic. When the address line A0 is at logic 0, the
controller is selected to write a command or read a status. The Chip Select Logic and A0
determine the port address of the controller.
Control Logic
This block has two pins: INT (Interrupt) as an output and INTA (Interrupt Acknowledge) as
an input. The INT is connected to the interrupt pin of the MPU. Whenever a valid interrupt is
asserted, this signal goes high. The INTA is the Interrupt Acknowledge signal from the MPU.
Cascade Buffer/Comparator
This block is used to expand the number of interrupt levels by cascading two or more
8259As.
…
BLEX
Microprocessor
INTA INT
D7-D0 Data
Bus Control Logic
Buffer
CAS 0
Cascade Internal Mask Register
CAS 1 Buffer/ (IMR)
CAS 2 Comparator
SP/EN
Interrupt Operation
To implement interrupts, the Interrupt Enable flip flop in the microprocessor should be enabled by
writing the EI instruction and the 8259A should be initialized by writing control words in the control
register. The 8259A requires two types of control words: Initialization Command Words (ICWs) and
Operational Command Words (OCWs). The ICWs are used to set up the proper conditions and specify
RST vector addresses. The OCWs are used to perform functions such as masking interrupt, setting up
status-read operations etc. After the 8259A is initialized, the following sequence of events occurs when
one or more interrupt request lines go high.
The IRR stores the requests.
The Priority Resolver checks three register: the IR for interrupt requests, the IMR for masking bits
and the ISR for the interrupt request being served. It resolves the priority and sets the INT high
when appropriate.
The MPU acknowledges the interrupt by sending INTA.
After the INTA is received, the appropriate priority bit in the ISR is set to indicate which interrupt
level is being served, and the corresponding bit in the IRR is reset to indicate that the request is
accepted. Then the Opcode for the CALL instruction is placed on the data bus.
When the MPU decodes the CALL instruction, it places two more INTA signals on the data bus.
When the 8259A receives the second INTA, it places the low order byte of the CALL address on the
data bus. At the third INTA, if places the high order byte on the data bus. The CALL address is the
vector memory location for the interrupt; this address is placed in the control register during the
initialization.
During the third INTA pulse, the ISR bit is reset either automatically (Automatic-End-of-Interrupt-
AEOI) or by a command word that must be issued at the end of the service routine (End-of-
Interrupt-EOI). This option is determined by the initialization command word (ICW).
The program sequence is transferred to the memory location specified by the CALL instruction.
…
BLEX
Microprocessor
Programming Exercises
Contents:
…
BLEX
Microprocessor
Example: The Most & Frequently Asked Problems & Their Solutions
Que. 1 Add two numbers stored at memory location 2040h and 2041h and store the result
at memory location 2042h.
Que. 3 Sum the given series of numbers. The length is given in memory location 203Fh and
the series itself starts from 2040h. Store the result at 2060h.
…
BLEX
Microprocessor
Que. 5 Find the maximum in a given series of data. The length is given in memory location
203Fh and the series itself starts from 2040h. Store the result at 2060h.
Que. 6 Write a program to copy 16 data from 2040h onwards to 2060 onwards.
Que. 7 Write a program to Ex-or two data without using Ex-or instruction.
…
BLEX
Microprocessor
Que. 9 Find the number of negative, positive and zero elements in a given series of data.
The length is given in memory location 203Fh and the series itself starts from 2040h. Store the
result at 2060 onwards.
…
BLEX
Microprocessor
Que. 11 Sort the given list in ascending order. The length of the series is given memory
location 203Fh and the series itself starts from 2040 onwards.
…
BLEX
Microprocessor
Que. 13 Convert binary number stored at 2040h to 4 digit BCD number. Store the BCD result
at 2041h and 2042h.
Que. 14 Writer a program to load the data byte A8H in register C. Mask the high order bit and
display the low order bits at a output port.
Que. 15 Write instructions to read the input port and continue to read it until both switches
are closed. When both switches are closed, turn on LEDS.
Que. 16 When all of 8 switches are off, the microprocessor reads data FFh and when a switch
is turned on, it goes to logic 0 (for all switches on, the data will be 00h). Write instruction to
read input port and if all switches are open, set zero flag.
…
BLEX
Microprocessor
Example: The Most & Frequently Asked Problems & Their Solutions
Que. 1 Find the largest number from a Que. 2 Find the smallest number from
table of 10 bytes. a table of 10 bytes.
TITLE: Obtaining Smallest Number in a Table TITLE: Obtaining Smallest Number in a Table
Using Bubble Sorting Algorithm Using Bubble Sorting Algorithm
.MODEL SMALL .MODEL SMALL
.STACK 32 .STACK 32
.DATA .DATA
TABLE DB 01, 21, 32, 26, 57, 64, 79, 50, 33, 42 TABLE DB 01, 21, 32, 26, 57, 64, 79, 50, 33, 42
LARGE DB? SMALL DB?
COUNT DW 0010 COUNT DW 0010
.CODE .CODE
MAIN PROC FAR MAIN PROC FAR
MOV AX, @Data MOV AX, @Data
MOV DS, AX MOV DS, AX
MOV SI, 00 MOV SI, 00
MOV CX, COUNT MOV CX, COUNT
MOV DL, 0FFH MOV DL, 0FFH
L1: L1:
MOV AL, TABLE [SI] MOV AL, TABLE [SI]
INC SI INC SI
CMP DL, AL CMP DL, AL
JAE Next JB Next
MOV DL, AL MOV DL, AL
Next: Next:
LOOP L1 LOOP L1
MOV LARGE, DL MOV SMALL, DL
MOV AX, 4C00H MOV AX, 4C00H
INT 21 H INT 21 H
MAIN ENDP MAIN ENDP
END MAIN END MAIN
…
BLEX
Microprocessor
Que. 3 Suppose you have two tables of Que. 4 Arrange the numbers of a table
10 unsigned integers (mad allowed being in ascending order.
255), find the sum of all ten numbers in
each table and store the greatest of the two TITLE: Arranging the Numbers of a Table in
sums in memory. Ascending Order Using Bubble Sorting.
.MODEL SMALL
TITLE: Add Corresponding Bytes of Two Tables .STACK 32
of 10 Bytes And Store the Result in The Third .DATA
Table. TABLE DB 34, 31, 32, 36, 33, 38, 39, 30, 37, 35
.MODEL SMALL COUNT DW 0010
.STACK 32
.DATA .CODE
TABLE1 DB 1,2,3,2,5,6,7,5,3,4 MAIN PROC FAR
TABLE2 DB 3,4,5,2,6,7,8,6,4,2 MOV AX, @Data
SUM1 DB? MOV DS, AX
SUM2 DB? MOV SI, 00 ; SI => int i = 0
LARGE DB? MOV DI, 00 ; DI => int j = 0
COUNT DW 10 ; for(i=o; i<10;i++) // Outer Loop
.CODE ; for(j=i+1; j<10;j++) // Ineer Loop
MAIN PROC FAR ; if(TABLE[j] < TABLE [i])
MOV AX, @DATA swap (TABLE[j],TABLE[i]);
MOV DA, AX ; // End of Inner Loop
MOV BX, 00 ; // End of Outer Loop
MOV CX, COUNT ; Outer Loop Initialization
MOV AH, 00 MOV CX, COUNT
MOV DL, 00 DEC CX
L1: ; Outer Loop Begin
MOV DL, TABLE1 [BX] Outer Loop:
ADD AH, DL ; Inner Loop Initialization
INC BX MOV BX, SI
LOOP L1 INC BX
MOV SUM1, AH MOV DI, BX
MOV BX, 00 ; Inner Loop Begin
MOV CX, COUNT Inner Loop:
MOV AH, 00 MOV DL, TABLE[DI]
MOV DL, 00 MOV DH, TABLE[SI]
L2: CMP DL, DH
MOV DL, TABLE2 [BX] JAE Skip_swap
ADD AH, DL CALL SWAP
INC BX MOV TABLE[DI],DL
LOOP L2 MOV TABLE[SI},DH
MOV SUM2, AH Skip_swap
MOV DL, SUM1 INC DI
MOV DH, SUM2 CMP DI, 1
MOV LARGE, DL JB Inner Loop
CMP DL, DH ; Inner Loop Ends
JAE EXIT INC SI
MOV LARGE, DH Loop Outer Loop
EXIT: ; Outer Loop Ends
MOV AX, 4C00H MOV AX, 4C00H
INT 21H INT 21H
MAIN ENDP
MAIN ENDP
SWAP PROC NEAR
END MAIN
MOV AL, DL
MOV DL, DH
MOV DH, AL
RET
SWAP ENDP
END MAIN