Beruflich Dokumente
Kultur Dokumente
Introduction
A Microprocessor is a multipurpose programmable logic device which reads the binary
instructions from a storage device called Memory , accepts binary data as input and process
data according to the instructions and gives the results as output. So, you can understand the
Microprocessor as a programmable digital device, which can be used for both data processing
and control applications. In view of a computer student, it is the CPU of a Computer or heart of
the computer. A computer which is built around a microprocessor is called a microcomputer. A
microcomputer system consists of a CPU (microprocessor), memories (primary and secondary)
and I/O devices as shown in the block diagram in Fig 1. The memory and I/O devices are linked
by data and address (control) buses. The CPU communicates with only one peripheral at a time
by enabling the peripheral by the control signal. For example to send data to the output device,
the CPU places the device address on the address bus, data on the data bus and enables the
output device. The other peripherals that are not enabled remain in high impedance state called
tri-state.
Evolution of Microprocessors
The first Microprocessor (4004) was designed by Intel Corporation which was founded by
Moore and Noyce in 1968. In the early years, Intel focused on developing semiconductor
memories (DRAMs and EPROMs) for digital computers. In 1969, a Japanese Calculator
manufacturer, Busicom approached Intel with a design for a small calculator which need 12
custom chips. Ted Hoff, an Intel Engineer thought that a general purpose logic device could
replace the multiple components. This idea led to the development of the first so called
microprocessor. So, Microprocessors started with a modest beginning of drivers for calculators.
Fedrico Faggin and Stanely Mazor implemented the ideas of Ted Hoffs and designed the Intel
4000 family of processors comprising 4001 (2K-ROM), the 4002 (320 bit RAM), the 4003 (10 bit
I/O shift-register) and the 4004, a 4 bit CPU. Intel introduced the 4004 microprocessor to the
world wide market on November 15, 1971. It was a 4-bit PMOS chip with 2300 transistors.
Around the same time Texas Instruments developed a 4-bit microprocessor TMS 1000 and
became the owner of microprocessor patent. Later Intel introduced worlds first 8 bit general
purpose microprocessor 8008 in 1972. This processor was used in the popular computer Mark8 in those days. In 1974, Intel introduced the improved version of 8008, the 8080
microprocessor. This 8080 is the much more highly integrated chip than its predecessors which
is built around N-channel MOS technology. It could execute up to 290,000 operations per second
and could address up to 64K.bytes of memory. The other notable 8 bit microprocessors include
Motorola 6800, Rockwell PPS-8 and Signetics 2650 with powerful architecture and instruction
set.
With developments in integration technology Intel was able to integrate the additional chips like
8224 clock generator and the 8228 system controller along with 8080 microprocessor with in a
single chip and released the 8 bit microprocessor 8085 in the year 1976. The 8085
microprocessor consisted of 6500 MOS transistors and could work at clock frequencies of 3-5
MHz. It works on a single +5 volts supply. The other improved 8 bit microprocessors include
Motorola MC 6809, Zilog Z-80 and RCA COSMAC.
In 1978, Intel introduced the 16 bit microprocessor 8086 and 8088 in 1979. IBM selected
the Intel 8088 for their personal computer (IBM-PC).8086 microprocessor made up of 29,000
MOS transistors and could work at a clock speed of 5-10 MHz. It has a 16-bit ALU with 16-bit
data bus and 20-bit address bus. It can address up to 1MB of address space. The pipelining
concept was used for the first time to improve the speed of the processor. It had a pre-fetch
queue of 6 instructions where in the instructions to be executed were fetched during the
execution of an instruction. It means 8086 architecture supports parallel processing. The 8088
microprocessor is similar to 8086 processor in architecture ,but the basic difference is it has only
8-bit data bus even though the ALU is of 16-bit.It has a pre-fetch queue of 4-instructions only.
In 1982 Intel released another 16-bit processor called 80186 designed by a team under the
leadership of Dave Stamm. This is having higher reliability and faster operational speed but at a
lower cost. It had a pre-fetch queue of 6-instructions and it is suitable for high volume
applications such as computer workstations, word-processor and personal computers. It is made
up of 134,000 MOS transistors and could work at clock rates of 4 and 6 MHz. This is also comes
under first generation of Microprocessors.
Intel released another 16 bit microprocessor 80286 having 1, 34,000 transistors in 1981. It was
used as CPU in PC-ATs in 1982. It is the second generation microprocessor, more advanced to
80186 processor. It could run at clock speeds of 6 to 12.5 MHz .It has a 16-bit data bus and 24bit address bus, so that it can address up to 16MB of address space and 1GB of virtual memory.
It had a pre-fetch queue of 6 instructions .Intel introduced the concept of protected mode and
virtual mode to ensure proper operation. It also had on-chip memory management unit (MMU)
.This was popularly called as Intel 286 in those days.
In 1985, Intel released the first 32 bit processor 80386, with 275,000 transistors. It has 32bit data bus and 32-bit address bus so that it can address up to a total of 4GB memory also a
virtual memory space of 64TB.It could process five million instructions per second and could
work with all popular operating systems including Windows. It has a pre-fetch queue of length 16bytes with extensive memory management capabilities. It is incorporated with a concept called
paging in addition to segmentation technique. It uses a math co-processor called 80387.
Intel introduced 80486 microprocessor with a built-in maths co-processor and with 1.2
million transistors. It could run at the clock speed of 50 MHz This is also a 32 bit processor but it
is twice as fast as 80386.The additional features in 486 processor are the built-in Cache and
built-in math co-processors. The address bus here is bidirectional because of presence of cache
memory.
On 19th October, 1992, Intel released the Pentium-I Processor with 3.1 million transistors. So,
the Pentium began as fifth generation of the Intel x86 architecture. This Pentium was a backward
compatible while offering new features. The revolutionary technology followed is that the CPU is
able to execute two instruction at the same time. This is known as super scalar technology. The
Pentium uses a 32-bit expansion bus, however the data bus is 64 bits.
The 7.5 million transistors based chip, Intel Pentium II processor was released in 1997. It
works at a clock speed of 300M.Hz. Pentium II uses the Dynamic Execution Technology which
consists of three different facilities namely, Multiple branch prediction, Data flow analysis, and
Speculative execution unit. Another important feature is a thermal sensor located on the mother
board can monitor the die temperature of the processor. For thermal management applications.
Intel Celeron Processors were introduced in the year 1999. Pentium-III processor with 9.5 million
transistors was introduced in 1999. It also uses dynamic execution micro-architecture, a unique
combination of multiple branch prediction, dataflow analysis and speculative execution. The
Pentium III has improved MMX and processor serial number feature. The improved MMX
enables advanced imaging, 3D streaming audio and video, and speech recognition for enhanced
Internet facility.
Pentium-IV with 42 million transistors and 1.5 GHz clock speed was released by Intel in
November 2000. The Pentium 4 processor has a system bus with 3.2 G-bytes per second of
bandwidth. This high bandwidth is a key reason for applications that stream data from memory.
This bandwidth is achieved with 64 bit wide bus capable of transferring data at a rate of 400
MHz. The Pentium 4 processor enables real-time MPEG2 video encoding and near real-time
MPEG4 encoding, allowing efficient video editing and video conferencing.
Intel with partner Hewlett-Packard developed the next generation 64-bit processor architecture
called IA-64 .This first implementation was named Itanium. Itanium processor which is the first in
a family of 64 bit products was introduced in the year 2001.The Itanium processor was specially
designed to provide a very high level of parallel processing ,to enable high performance without
requiring very high clock frequencies .Key strengths of the Itanium architecture include ,up to 6
instructions/cycle. The Itanium processor can handle up to 6 simultaneous 64 bit instructions
per clock cycle.
The Itanium II is an IA-64 microprocessor developed jointly by Hewlett-Packard (HP)
and Intel and released on July 8,2002..It is theoretically capable of performing nearly 8 times
more work per clock cycle than other CISC and RISC architectures due to its parallel computing
micro-architecture. The recent Itanium processor features a split L2 cache, adding a dedicated
1MB L2 cache for instructions and thereby effectively growing the original 256KBL2 cache, which
becomes a dedicated data cache. The first Itanium 2 processor (code named McKinley) was
more powerful than the original Itanium processor, with approximately two times performance.
Pentium 4EE was released by Intel in the year 2003 and Pentium 4E was released in the
year 2004.
The Pentium Dual-Core brand was used for mainstream X86-architecture
microprocessors from Intel from 2006 to 2009 The 64 bit Intel Core2 was released on July
27,2006. In terms of features, price and performance at a given clock frequency, Pentium DualCore processors were positioned above Celeron but below Core and Core 2 microprocessors in
Intel's product range. The Pentium Dual-Core was also a very popular choice for over clocking,
as it can deliver optimal performance (when over clocked) at a low price.
The Pentium Dual Core, which consists of 167 million transistors was released on January 21,
2007. Intel Core Duo consists of two cores on one die, a 2 MB L2 cache shared by both cores,
and an arbiter bus that controls both L2 cache and FSB access.
Core 2 Quad processors are multi-chip modules consisting of two dies similar to those used in
Core 2 Duo, forming a quad-core processor. While this allows twice the performance to a dualcore processors at the same clock frequency in ideal conditions, this is highly workload specific
and requires applications to take advantage of the extra cores.
In September.2009, new Core i7 models based on the Lynnfield desktop quad-core processor
and the Clarksfield quad-core mobile were added, and models based on the Arrandale dual-core
mobile processor have been announced. The first six-core processor in the Core lineup is the
Gulftown, which was launched on March 16, 2010. Both the regular Core i7 and the Extreme
Edition are advertised as five stars in the Intel Processor Rating.
The Intel 8085 Microprocessor:
Intel 8085A is a single chip 8-bit N-channel microprocessor which works at +5V DC power
supply. It is a 40 pin IC available as a DIP (Dual Inline Package) chip. 8085A can operate with a
3MHZ single phase clock and 8085A-2 version can operate at a maximum frequency of 5MHZ.
This 8085 is an enhanced version of its predecessor the 8080A. Its instruction set is upward
compatible with that of the 8080A. 8085A has an on-chip clock generator with external crystal,
LC or RC network. This 8085 microprocessor is built with nearly 6200 transistors. The enhanced
version of 8080 is the Intel 8085AH. It is an N channel depletion load, silicon gate (HMOS) 8-bit
processor. Here 3MHZ, 5MHZ and 6MHZ selections are available. It has 20% lower power
consumption than 8085A for 3MHZ and 5MHZ. Its instruction set is 100% software compatible
with the 8085A. It is also 100% compatible with 8085A.
operation. For example when MVI M, 17H instruction is fetched, IR register will receive the
opcode for MVI M and the Temporary register will receive 17H.
In arithmetic and logical operations, that involves two operands ,the accumulator provides one
operand. The other is provided by the temporary register. For example in ADD C instruction C
register contents are moved to the Temp. Register and the addition of A and Temp. Register
contents is performed by the ALU.
(c).Flag register: The flag register is an 8- bit register which generally reflect data conditions in
the accumulator with certain exceptions. Hence this flag register is also known as Status register.
Though this flag register is an eight bit register, it contains only 5 flag bits and the remaining
three bits are undefined as shown in Fig.3.3 In the Flag register each flag bit is a Flip-Flop. i.e.,
the bit may be either in the flip state or flop state
D7
D0
11011001
11101101
11 1 0 0 0 1 1 0
In the result, the sum is not zero, So Z-Flag is reset (Z=0).
There is a carry from the third bit to fourth bit. So AC Flag is set (AC=1).
The D7 bit=1, so, the sign Flag is set (S=1).
In the result, the no. of 1s is even. So, parity is even (P=1).
After addition, there is a carry. So carry Flag is set (CY=1).
The Flag register contents after addition are shown below:
D7
D0
Register Organization
The 8085 microprocessor has different types of registers. It includes six , 8 bit registers
(B, C, D. E, H and L), one 8-bit Accumulator and two 16-bit registers (SP and PC). Also there
are two 8-bit temporary registers W and Z. Among these registers W and Z are not accessible to
the user, They are used by the processor for internal, intermediate operations. The remaining
registers are accessible to the user. The organization of 8085 registers is shown in Fig. 3.4
The various registers of 8085 are classified into three types. They are
(i).Temporary registers.
(ii).General purpose registers
(iii).Special purpose registers.
(i) Temporary registers :
The Temporary registers are temporary data registers, W register and Z register. All are 8bit registers. The temporary data register is associated with the ALU operations. One of the
operand is stored in this register. This is not accessible to user.
Similarly W and Z are also temporary registers used to hold 8-bit data during execution of certain
instructions.As these registers are internally used by the CPU, they are not accessible to the
user.
The W and Z registers are used by the processor during CALL instruction. When a CALL
instruction is encountered in any program, the current Program counter (PC) contents are
pushed on to the stack and the given address is loaded on to PC. The given address is
temporarily stored in W and Z registers and placed on the bus for the fetch cycle. Thus the
program control is transferred to the address given in the instruction.
Another example is, during the execution of XCHG instruction, the contents of H-L pair are
exchanged with D-E pair. At the time of exchange W and Z registers are used for temporary
storage of data.
(ii) General purpose registers :
B, C, D, E, H and L are six, 8-bit general purpose registers to store data. These registers
can be used as separate 8-bit registers and also can be paired as 16-bit registers to store the
address of a memory location. But they must be paired as B-C; D-E and H-L register pairs only
as shown below.
Auxiliary carry Flag: This flag is set if there is a carry from 3rd bit to 4th bit during BCD
operations (carry from lower nibble to higher nibble). This flag is not accessible to the user.
Parity Flag: Parity is defined by the number of 1s present in a binary number stored in A
register. After any arithmetic or logical operation, if the result has an even number of 1s it is
called even parity and the Parity Flag is set to 1. Otherwise. i.e. If there is odd number of 1s in
the result, it is called Odd Parity and the Parity flag is set 0.
Program Counter (PC):
It is a 16-bit special purpose register, which stores the address of the next instruction to be
fetched or executed. The execution of a program is initiated by loading the PC by the address of
the first instruction of the program. Once the first instruction is executed, the PC is automatically
incremented to point to the next instruction unless a jump to some specific address occurs. This
process is repeated till the last instruction of the program.
In case of JUMP or CALL instructions, current address is stored in the Program Counter.
The processor then fetches the next instruction from the new address specified by the JUMP or
CALL instruction. In conditional JUMP and conditional CALL instructions, if the condition is not
satisfied, the processor increments the Program Counter by three so that it points the instruction
followed by the conditional JUMP or CALL instruction. Otherwise the processor fetches the next
instruction from the new address specified by JUMP or CALL instruction.
Stack Pointer (SP):
It is a 16-bit special purpose register which always stores the address of top of the Stack.
i.e. it always points to top of the Stack. Stack is a part of the memory location used to store the
data temporarily. A stack works on Last in First out (LIFO) basis. As the Stack pointer always
points to the top of the Stack, only top of the Stack of the memory can be accessed. When a
Write operation (PUSH) takes place, the contents of the stack pointer is decremented by two so
that the SP points to the new location. Similarly when the Read operation (POP) occurs, the
Stack pointer is incremented by two to point to the next data on top of the Stack.
The Stack Pointer is initialized by load register pair immediate instruction.
Ex: LXI SP, 8530 H
Here 8530 H is the 16 bit address of the top of Stack location.
Address Buffer: This is an 8-bit unidirectional buffer. It is used to drive external higher order
address bus. It is also used to tri-state the higher order address (A8-A15) bus under certain
conditions like reset, hold, and halt and also when address lines are not in use.
Address/Data Buffer: This is an 8-bit bi-directional buffer. It is used to drive multiplexed
address/data bus. It means low order address bus (A7-A0) and data bus (D7-D0). It is also used
to tri-state the multiplexed address/data bus under certain conditions like reset, hold, and halt
and also when A/D bus lines are not in use.
The address and data bus buffers are used to drive external address and data buses
respectively. Due to these buffers the address and data buffers can be tri-stated when they are
not in use. In actual practice, in a microprocessor the driving capacity of the address pins after
the internal buffering may not be adequate. So, there will be external buffer chips also available.
Serial I/O control:
This control provides two lines SOD (Serial Out Data) and SID (serial In Data) for serial
communication. These lines are used during serial data transmission over long distance where
data is transmitted and received bit by bit. The Serial Output Data (SOD) pin is used to send
data out serially and serial Input Data (SID) pin is used to receive data serially by the 8085
microprocessor.
Interrupt control:
This is an important block related to interrupts. This block is linked to the CPU through the
8-bit internal data bus. This interrupt control has five interrupt signals. They are TRAP, RST 7.5,
RST 6.5, RST 5.5 and INTR. The control block will take care of enabling and disabling of these
interrupts etc
8085 Interrupts:
The 8085 microprocessor has five interrupts. They are TRAP, RST 7.5, RST 6.5, RST5.5 and
INTR. Among all these interrupts TRAP has the highest priority and INTR (Interrupt Request) has
the lowest priority. The TRAP is also a non maskable interrupt. The numbers succeeding the
RST (7.5, 6.5, and 5.5) are related to the call locations. The various interrupts, their locations in
the order of highest to lowest priority are given in Table 3.1. Here RST means RESTART. Among
these interrupts INTR is the only non-vector interrupt whereas the other interrupts are vectored
interrupts.
TRAP: It is a non maskable interrupt with highest priority. It means that whenever the pin is
activated, the 8085 will always get interrupted even if the 8085 is in DI (Disable Interrupt) state.
Trap input is both edge and level sensitive. So, the microprocessor is interrupted when the input
is both edge and level sensitive. So, the microprocessor is interrupted when the input pulse goes
from low to high or when it remains high .When interrupted, the microprocessor loads the
program counter with 0024H.
RST 7.5: It is an edge sensitive pin. Internal to 8085 there is a flip-flop connected to RST 7.5
interrupt pin . This flip flop is set 1, when a positive going edge occurs on RST 7.5 input. RST
7.5 interrupt has a higher priority than RST 6.5, RST 5.5 and INTR. This RST 7.5 is a maskable
interrupt known as MI. This interrupt is enabled under program control with two instructions EI
(Enable Interrupt) and SIM (Set Interrupt Mask)
RST 6.5and RST 5.5: These interrupts are level sensitive, it means the triggering level should
be on until the microprocessor completes the execution of the current instruction. If the
microprocessor is not able to respond to the requests immediately, they should be stored or held
by external hardware. These two interrupts are also maskable interrupts. RST 6.5 and RST 5.5
have higher priority than INTR interrupt. The condition of these interrupts can be known using
10
RIM (Read Interrupt Mask) instruction and the condition of the masking interrupt can be set and
reset using SIM instruction (Set Interrupt Mask).
INTR: It is only non-vectored interrupt in 8085 microprocessor. This interrupt has the lowest
priority among all the interrupts. This is also a maskable interrupt and can be disabled using the
instruction DI (Disable Interrupt). The mask on INTR can be removed by executing EI (Enable
Interrupt) instruction. When EI instruction is executed, the flip flop associated with this is set and
the mask is removed. This is a non-vectored interrupt because when the remaining interrupts are
initialized, they are automatically transferred (vectored) to specific locations on memory page
00H without any external hardware. They do not require the
signal. The necessary
hardware is already implemented inside the 8085. But coming to INTR, interrupt, it executes
interrupt acknowledge machine cycle. During this cycle, the device that has interrupted this
microprocessor will provide the operation code. The
signal works as a
signal during
acknowledge machine cycle. During this time, the microprocessor loads the code into instruction
register from I/O device. Based on the code, the remaining operation is executed by the
processor
S.N o
Interrupts
Call locations
0024H
RST 7.5
RST 6.5
RST 5.5
No location
S. No
S1
IO/
S0
Status
Memory Write
Memory Read
11
I/O Write
I/O Read
1/0
Opcode fetch
Interrupt
Acknowledge
Halt
Hold
RESET
IO/ : This is a status signal used to differentiate between I/O and memory operations. When
this signal is high, it indicates an I/O operation, when it is low it denotes a memory operation.
This signal is combined with Read ( ) and Write
to generate necessary I/O and memory
control signals.
S1 and S0: These signals are also status signals like IO/ , used to identify various operations.
The complete operation of the microprocessor can be understood by these three signals. The
various operations and the associated status signals are shown in Table 3.2 .
ALE (Address Latch Enable): This is a positive going pulse generated every time the 8085
begins an operation, It indicates that the bits on AD7 - AD0 are address bits. This signal is used
primarily to latch the low-order address from the multiplexed bus and generate a set of eight
address lines A7 A0.
12
the first T state (T1) of the machine cycle. To demultiplexe the A/D bus the pin ALE is used.
When ALE=1 (high) the A/D bus acts as a lower order address bus else it acts as Data bus.
The Data bus is a bidirectional bus which is used to send data to and from the microprocessor.
This is also a parallel bus. The size of the data bus determines the size of the microprocessor.
The 8085 microprocessor has 8-bit data bus and hence it is called an 8-bit microprocessor. This
refers to the width of the data bus but not the address bus. Similarly8086 is a 16-bit
microprocessor and its data bus width is 16 bits
INTEL 8085 has Address/ Data bus namely AD7-AD0. i.e. at some instances it acts as a
8- bit address bus and at other instances it works as a 8-bit data bus. INTEL used this time
multiplexing technique to save the pins. Generally the size of the internal general purpose
registers matches the size of the data bus. Thus, the INTELs 8-bit general purpose registers
matches with its 8-bit data bus. The size of the data bus matches the size of the internal
registers, so that all the bits on the bus can at one time come into or go out of any of the
registers.
The control bus of 8085 is a uni-directional bus because the microprocessor alone sends
control signals to memories or peripheral devices. The size of the control bus depends upon the
specific microprocessor. Typical control signals are Read or Write signals. It means whether the
microprocessor operation is a read or writes and whether it is memory or I/O operation. In
addition to this it includes state signals, and address latch enables. A microprocessor may also
have certain additional control signals and such as interrupt signals, acknowledgement signals
and hold signals. But they are not considered as part of control bus even through they take part
in control of microprocessor based systems.
The above three buses that interface the CPU to the system components are combinedly
known as the System bus.
Pin configuration
The pin diagram of 8085 microprocessor is shown in Fig 5. From the figure it is clear that it is
40 pin DIP chip. The various pins of 8085 microprocessor can be grouped in the following
categories
Power Supply and Clock pins
Data bus and Address bus
Control and Status signals
Interrupt signals
DMA signals
Serial I/O signals
The description of various pins is given below.
Power supply and clock pins:
Vcc: +5V power supply
X1 and X2: A Crystal (or RC, LC Network) is connected at these two pins. The internal
clock generator divides oscillator frequency by 2, therefore to operate a system at 3MHZ,
the crystal of the tuned circuit should have a frequency of 6MHZ.
CLK (OUT): This signal is used as a system clock for other devices. Its frequency is half
the oscillator frequency
13
AD0-AD7: These lines are Address/Data lines, which are bidirectional with dual purpose.
They are used as the low-order address bus as well as the data bus. During the first part
of the machine cycle (T1), lower 8 bits of memory address or I/O address appear on the
bus. During the remaining part of the machine cycle (T2,T3) these lines are used as a bidirectional data bus
(Read): This is an active low read control pin. This signal indicates that the selected
I/O or memory device is to be read and data are available on data bus.
(Write): This is an active low write control pin. It indicates that the data on the data
on the data bus are to be are to be written into a selected memory or I/O location
IO/ : This is a status signal used to differentiate between IO and memory operations.
When it is high, it indicates an I/O operation and when it is low, it indicates a memory
operation. This signal is combined with
and
signals to generate I/O and memory
control signals.
14
S1 and S0: These are status signals and they indicate the type of machine cycle in
progress during execution of an instruction.
READY (Input): Through this pin, the microprocessor will know whether peripheral device
is ready or not for data transfer. If the device is not ready the processor waits. So, this pin
helps to synchronize slow devices to the microprocessor.
Interrupt signals:
TRAP, RST 7.5, RST 6.5, RST5.5 and INTR: These are the interrupt signals which are externally
initiated.
INTR (Interrupt Request): This is used as a general purpose interrupt. It has a lowest
priority and it is the only non-vectored interrupt.
RST 7.5: It is a restart interrupt pin. It has higher priority than RST 6.5, RST5.5 and INTR.
It is a maskable vectored interrupt.
RST 6.5 and RST5.5: These two are maskable vectored interrupt with higher priority than
INTR.
(Output): It is an active low interrupt acknowledge pin. This will acknowledge the
receival of interrupt request to the peripheral device.
DMA Signals:
Hold: This pin is used during the Direct Memory Access. A high on this pin indicates that,
a peripheral like DMA controller is requesting the use of address and data buses.
HLDA (Output): A high on this p in acknowledges the hold request from peripheral.
: It is an active low signal. When the signal on this pin goes low, the system is in
reset i.e. the program counter is set to zero, the address & data buses are tristated.
SOD: Serial output Data pin is used by the microprocessor to output data serially to the
external devices. Serial data is sent out of the microprocessor by executing SIM
instruction. The most significant bit of accumulator should have the serial bit and D6 bit of
the accumulator must be made high to enable the serial data transfer.
Timing Diagram :
The graphical representation of the time taken for the execution of each instruction by a
microprocessor is known as timing diagram. The execution time is denoted by T-states. One Tstate is equal to the time period of the internal clock signal of the microprocessor
For Ex: If the internal clock frequency of 8085 microprocessor is 3 MHZ, One T-state is equal to
15
16
17
18
19
20
21
22
Twobyte instructions: At wo byte instruction is one which contains an 8-bit op-code and 8-bit
operand (Data).
Ex: 1. MVI A, 09
2. ADD B, 07
3. SUB A, 05
Threebyte instructions: A three byte instruction contains an opcode plus a 16 bit address.
Ex: 1.LXI H, 8509
2 .LDA 8509
3. JMP 9567
4. STA 3525
DATA FORMATS: The 8085 is an 8-bit microprocessor which process only binary numbers. But
it is very difficult to understand these binary numbers by a common user. So, we have to code
these binary numbers into different data formats. The commonly known data formats are ASCII,
BCD, signed integers and unsigned integers. The ASCII code is a 7-bit alpha-numeric code that
represents decimal numbers, English alphabets and certain special characters. The ASCII
stands for American Standard code for Information Interchange
The term BCD stands for binary coded decimal, used for decimal numbers from 0-9.An 8bit register can store two BCD numbers. A signed integer is either a positive or a negative
number. In 8085 microprocessor the most significant bit D7 is used for the sign. Here 0 denotes
positive sign and 1 denotes the negative sign. An integer without a sign can be represented by all
the 8-bits in a microprocessor register. So, the largest number that can be processed at one time
is FFH. The numbers larger than 8-bits like 16, 24, 32 bits can be processed by dividing them in
groups of 8-bits.
CLASSIFICATION OF INSTRUCTIONS
An instruction is a binary pattern designed inside a microprocessor to perform a specific
function. The entire group of instructions, called the instruction set, determines what functions the
microprocessor can perform. The 8085 microprocessor instruction set has 74 operation codes
that result in 246 instructions. This instruction set includes all the 8080A instructions plus two
additional instructions namely SIM and RIM.
23
The instruction set of 8085 microprocessor is classified into five groups. They are:
1. Data transfer (copy) group.
2. Arithmetic group
3. Logic group
4. Branch control group
5. Machine control and I/O group.
Data transfer (copy) instructions
The data transfer instructions are used to transfer data from one register to another
register, from memory to register or register to memory but not from one memory location to
another memory location. Actually this data transfer instruction copies the data from source to
destination and the contents of the source are not altered. So, the data transfer instruction
performs basically copy operation.
Examples of data transfer instructions are MOV, MVI (Move Immediate), LXI (Load Immediate HL Pair), LDA (Load Accumulator), STA (Store Accumulator), LHLD (Load H-L pair direct), SHLD
(Store H-L pair direct), XCHG (Exchange the contents of H-L pair with D-E pair) etc
Ex: MVI A, 55H ; Move the data 55H into Accumulator
MOV B, C ; Copies the contents of C register into B register
IN 00H
; Read the Input port(00H is the port address)
OUT 01H ; write data to an output port(01H is the port address)
LXIH 8570H ; Load H-L pair by address 8570H.
In the 8085 microprocessor, data transfer instructions do not affect any flags.
Arithmetic Instructions
The arithmetic operations like addition, subtraction, increment and decrement are
performed by the 8085 microprocessor using the following arithmetic instructions.
ADD, ADI (Add Immediate), SUB (Subtract), SUI (Subtract Immediate), INR (Increment), DCR
(Decrement) etc
The arithmetic operations Add and subtract are performed in relation to the
contents of the accumulator. But, the increment or the decrement operations can be performed in
any register.
Ex:ADD B, C
ADI 08
SUB A, B
SUI 05
INR B
DCR C
Arithmetic instructions modify all the flags according to the data conditions of the result. The INR
and DCR instructions affect all flags except the carry flag.
Logical Group of Instructions:
Since the microprocessor is a programmable logic chip, it can be perform all the logic
functions of the hard-wired logic through its instruction set. The 8085 processor can perform the
logic instructions like, AND, OR, NOT (Complement) and X-OR (Exclusive OR) etc The
mnemonics of these instructions are given below.
ANA :
ANI :
24
ORA :
OR :
XRA :
XRI :
CMA :
All the logic operations are performed in relation to the contents of the accumulator. The CMA
instruction does not affect any flags. The executions of the logical instruction do not affect the
contents of the operand register.
Branch Instructions
These instructions are very important because they allow the microprocessor to change
the sequence of a program either conditionally or unconditionally. The conditional branch
instructions transfer the program to the specified label when certain condition is satisfied. The
unconditional branch instructions transfer the program to the specified location unconditionally.
We know that the microprocessor is a sequential machine. So, it executes machine codes from
one memory location to the next. Branch instructions instruct the microprocessor to go to a
different memory location and the processor continues executing machine codes from the new
location. The address of the new locations either specified explicitly or provided by the
microprocessor or some times by additional hardware. The Branch instructions are classified into
three categories. They are
(a). Jump instructions
(b). Call and return instructions
(c). Restart instructions.
Jump instructions specify memory locations explicitly and they are 3-byte instructions. These
Jump instructions are of two types. They are , Unconditional Jump and Conditional Jump.
Unconditional Jump:
This is similar to Unconditional Go to statement in BASIC. When this instruction is
executed the 16-bit address available immediately in the instruction is loaded into the program
counter , so that the next sequence of instruction execution starts from this location. This
Unconditional Jump instruction enables the programmer to create continuous loops.
JMP (16 bit address). So, this is a 3-byte instruction where the first byte is opcode and the second, third bytes specify memory address.
For example, the instruction JMP 8500H, instructs the microprocessor to go to the memory
location8500H unconditionally. Sometimes, the jump location is specified using a label also.
Conditional Jump:
This instruction allows the microprocessor to make decision depending on certain
conditions indicated by flags. The 8085 processor Jump instruction is associated with four flags.
Namely Carry flag (CY), Zero flag (Z), Sign flag (S) and Parity flag (P). The following instructions
shown in Table 3.3 transfer the program sequence to the memory location specified under the
given conditions.
25
S. No
Instruction
Description
Mnemonics
Hex code
RST 0
C7
Call location
In Hex
0000
RST1
CF
0008
RST2
D7
0010
RST3
DF
0018
RST4
E7
0020
RST5
EF
0028
RST6
F7
0030
RST7
FF
0038
26
HLT (Halt): After execution of this instruction the microprocessor goes into the halt state. The
processor can be restarted by a valid interrupt or by applying a RESET signal. The
microprocessor takes 5T states to implement the halt instruction.
I/O instructions:
There are two important instructions to input the data into the microprocessors accumulator
through the input port and output the data from the accumulator to the output port. They are
IN (port address)
OUT (port address)
This port address is an 8-bit address. In both these instructions the default register is
Accumulator.
Ex: (i) IN 01H. This instruction will copy the contents into the Accumulator through the port
whose address is 01H. It takes three machine cycles and takes 10 states. The op-code is DBH.
(ii)OUT 02H. This instruction sends the contents of Accumulator to the outport whose
address is 02H. It is a two byte instruction which requires 10 states. The op-code for this
instruction is D3H.
27
28
29
ARITHMATIC INSTRUCTIONS
30
31
32
33
34
35
36
37
38
39
SOD Serial output Data .Bit D7 of accumulator is latched in to the SOD output line made
available to serial peripheral if bit D6 =1 .
SOE Serial output enable.If this bit =1 ,it enables the serial output.
XXX Dont care condition
R7.5 Reset RST7.5.If this bit = 1 ,RST7.5 flip-flop is reset .This is an additional control to reset
RST7.5
MSE Mask set Enable.If this bit is high ,it enables the function of bits D2,D1 and D0.This is a
master control over all the interrupt masking bits.
M7.5 D2=0 ,RST 7.5 is enabled
D2=1 RST7.5 is masked or disabled
M6.5 D1=0 RST6.5 is enabled
D1=1 RST 6.5 masked or disabled.
M5.5 D0=0 RST5.5 is enabled
D0=1 RST 5.5 is disabled or masked.
ADDRESSING MODES
Majority of the instructions of 8085 microprocessor requires an operand (either data or
address) on which the intended operation can be performed. Some instructions may require only
one operand and some other instructions require two operands for its instruction execution. The
speed of execution mainly depends on the position of the operand in the instruction. The scheme
involved in identifying the position of operands in an instruction is known as addressing mode.
There are five addressing modes 8085 processor.They are
(i). Immediate addressing mode
(ii). Direct addressing mode
(iii). Register addressing mode.
(iv). Register indirect addressing mode.
(v). Implicit addressing mode.
(i). Immediate Addressing mode: The mode of addressing in which the operand is a part of the
instruction itself is known as Immediate Addressing mode. If the immediate data is 8-bit, the
instruction will be of two bytes. If the immediate data is 16 bit, the instruction is of 3 bytes.
Ex: (1). ADI DATA ; Add immediate the data to the contents of the accumulator.
(2).LXIH 8500H : Load immediate the H-L pair with the operand 8500H
(3). MVI 08H
; Move the data 08 H immediately to the accumulator
(4). SUI 05H
; Subtract immediately the data 05H from the accumulator
(ii) Direct Addressing mode: The mode of addressing in which the 16-bit address of the
operand is directly available in the instruction itself is called Direct Addressing mode. i.e., the
address of the operand (data) is available in the instruction itself. This is a 3-byte instruction.
Ex: (1). LDA 9525H ; Load the contents of memory location into Accumulator.
(2). STA 8000H ; Store the contents of the Accumulator in the location 8000H
(3). IN 01H ; Read the data from port whose address is 01H.
(iii). Register addressing modes: The mode, in which the operand is in one of the general
purpose registers, is known as the register addressing mode.
Ex: (1). MOV A, B;
Move the contents of B register to A register.
(2). SUB D;
Subtract the contents of D register from Accumulator.
(3). ADD B, C; Add the contents of C register to the contents of B register.
40
(iv). Register indirect addressing modes: The 16-bit address location of the operand stored in
a register pair (H-L) is given in the instruction. The address of the operand is given in an indirect
way with the help of a register pair. Hence it is called Register indirect addressing mode
Ex: (1). LXIH 9570H ; Load immediate the H-L pair with the address of the location 9570H
MOV A, M
; Move the contents of the memory location pointed by the H-L pair to
accumulator
(v). Implicit Addressing mode: The mode of instruction which do not specify the operand in the
instruction but it is implicated, is known as implicit addressing mode. i.e., the operand is
automatically considered to be in the Accumulator.
Ex: (1).CMA; complement the contents of Accumulator
(2).CMC; Complement carry
(3). RLC; Rotate Accumulator left by one bit
(4). RRC; Rotate Accumulator right by one bit
(5). STC; Set carry.
Hex
cod
e
Label
Mnemonics
OpOperand
code
Comments
LXI
H, 9000
8003
8004
8005
21,0
0,90
3E
00
86
MVI
A, 00
ADD
A, M
8006
23
INX
8007
86
ADD
A, M
8008
8009
800A
800B
32
02
90
76
STA
9002
HLT
Ex :(ii) 9000 49 H
9001 32 H
Ex :( ii) 9002 7B
Flow Chart
Start
Initialise H-L Pair
with XX00
Clear Accumulator
(00) A
Add contents of M to
Accumulator
Stop
Fig 3.18
42
Flow Chart
Start
Clear Accumulator
(00) A
Add contents of M
to Accumulator
# Increment memory
pointer(XX01) &
# Add contents of M to A
Is
Carry
exists ?
Yes
No
Stop
Fig 3.19
43
PROGRAM:
Address
Hex
of
the code
memory
location
8000
21,00
,85
8003
3E
8004
00
8005
86
Lab
el
Mnemonics
OpOperand
code
Comments
LXI
H, 8500 H
MVI
A,00
ADD
A, M
8006
8007
8008
0E
00
23
MVI
C,00
INX
8009
86
ADD
A, M
800A
32
JNC
FWD
800B
800C
800D
800E
0E
80
0C
32
INR
STA
C
8502 H
800F
8010
8011
8012
8013
8014
8015
02
85
79
32
03
85
76
MOV
STA
A,C
8503 H
Ex: Input:
Ex :
FW
D
HLT
8500 97 H
8501 98H
Make carry =1
The sum is stored in memory
location 8502.
8502 32 H
8503 -- 01 H
Flow Chart
Start
Add contents of M to
Accumulator
# Increment memory
pointer(XX01) &
# Add contents of M to A
Is
Carry
Exists?
Yes
No
Store Zero in the
XX03 location
Stop
Fig .20
45
PROGRAM
Address of
the
memory
location
8000
Hex
code
Label Mnemonics
OpOperand
code
LXI
8003
8004
8005
21,
00,85
0E
00
7E
8006
Comments
MVI
MOV
A, M
23
INX
8007
86
ADD
A, M
8008
8009
27
D2
DAA
JNC
FWD
800C
800D
800E
800F
8010
8011
0D
80
0C
32
02
85
79
32
INR
STA
C
8502 H
Make carry =1
The contents of accumulator are
stored in memory location 8502.
MOV
STA
A, C
8503 H
8012
8013
8014
03
85
76
Ex: Input:
Ex :
FWD
HLT
8500 67 D
8501 85 D
8502 52 D
8503 01 (Carry)
46
Flow Chart
Start
Exchange this
number in to D-E
pair
Is
Carry
Set?
Yes
No
Stop
Fig 21
47
PROGRAM:
ADDRESS
HEX
CODE
8000
8001
8002
8003
2A,00,85
00
85
EB
8004
8005
8006
8007
8008
8009
800A
800B
800C
800D
800E
800F
8010
8011
2A
02
85
0E
00
19
D2
0E
80
OC
22
04
85
79
8012
8013
8014
8015
32
06
85
76
Ex: INPUT:
LABEL
MNEMONIC
OPCO
DE
LHLD
COMMENTS
OPERAND
8500 H
XCHG
FWD
LHLD
8502 H
MVI
00
DAD
JNC
D
FWD
INR
SHLD
C
8504 H
Increment carry
Store the LSB of the Sum in 8504
& MSB in 8505 locations
MOV
A,C
STA
8506 H
HLT
Stop execution
RESULT : 8504 - 25H LSB of the Sum
8505 25H MSB of the Sum
8506 -- 00 Carry .
Subtraction Programs:
Example 5: Subtraction of two 8-bit numbers without borrows.
Explanation: Its a simple program similar to addition of two 8- bit numbers, except that we use the
instruction SUB instead of ADD. The first 8-bit number is stored in XX00 memory location and the second
8-bit number is stored in the XX01 location .Use the SUB instruction and store the result in the XX02
location.
ALGORITHM:
Step1. : Initialise H-L pair with the address of minuend.
Step2. : Move the minuend into accumulator
Step3. : Increment H-L pair
Step4. : Subtract the subtrahend in memory location M from the minuend.
Step5. : Store the result in XX02.
Step6. : Stop the execution
48
Flow Chart
Start
Increment memory
pointer(XX01)
Stop
Figure 22
PROGRAM:
ADDRESS
HEX
CODE
8000
LABEL
COMMENTS
21
MNEMONIC
OPCOD OPERAN
E
D
LXI
H, 8500
8001
8002
8003
8004
8005
8006
8007
00
85
7E
23
96
23
77
MOV
INX
SUB
INX
MOV
8008
76
HLT
[A] [M]
[M+1] [M]
A [A] [M]
Next memory location
Store the result in the location
8502
Stop the execution
A,M
H
M
H
M,A
49
INPUT: Ex :
8500- 59H
8501- 30H
ALGORITHM:
Step1. : Initialise H-L pair with the address of second number (XX01).
Step2. : Find its tens complement
Step3. : Decrement the H-L pair for the first number (XX00)
Step4. : Add the first number to the 10s complement of second number.
Step5. : Store the result in XX02.
Step6. : Stop the execution
Flow Chart
Start
Stop
Figure 23
50
PROGRAM:
ADDRESS
8000
HEX
CODE
21
8001
8002
8003
8004
8005
00
85
3E
99
96
MVI
A,99
[A] 99
SUB
8006
3C
INR
8007
8008
2B
86
DCX
ADD
H
M
9s complement of second
number
10s complement of second
number
Address of the first number
Add first number to 10s
complement of second number
8009
800A
27
32
DAA
STA
8502
800B
800C
800D
02
85
76
HLT
LAB
EL
MNEMONIC
COMMENTS
OPCODE OPERAND
LXI
H,8500
Initialise H-L pair and get
theSecond number in to 8501
location
8501- 35 D
51
Flow Chart
Start
Exchange this
number in to D-E
pair
Is
borrow
Set ?
Yes
No
Store 0 in the location XX06
Store 1 in the
XX06 location
No
Stop
Fig 24
52
PROGRAM:
ADDRESS
HEX
CODE
8000
8003
8004
8005
8006
8007
2A,
00,85
EB
2A
02
85
7B
8008
LABE
L
MNEMONIC
OPCOD
OPERAN
E
D
LHLD
8500 H
COMMENTS
XCHG
LHLD
8502 H
MOV
A, E
95
SUB
8009
800A
800A
6F
9C
MOV
MOV
SBB
L, A
A, D
H
800B
800C
67
22
MOV
SHLD
H, A
8504
800D
80OE
80OF
04
85
76
HLT
Stop execution
53
Ex: INPUT :
Multiplication Programs
Example 7: Multiplication of two 8-bit numbers. Product is 16-bits.
Explanation: The multiplication of two binary numbers is done by successive addition. When
multiplicand is multiplied by 1 the product is equal to the multiplicand, but when it is multiplied by
zero, the product is zero. So, each bit of the multiplier is taken one by one and checked whether
it is 1 or 0 .If the bit of the multiplier is 1 the multiplicand is added to the product and the product
is shifted to left by one bit. If the bit of the multiplier is 0 , the product is simply shifted left by one
bit. This process is done for all the 8-bits of the multiplier.
ALGORITHM:
Step 1 : Initialise H-L pair with the address of multiplicand.(say 8500)
Step 2 : Exchange the H-L pair by D-E pair. so that multiplicand is in D-E pair.
Step 3 : Load the multiplier in Accumulator.
Step 4 : Shift the multiplier left by one bit.
Step 5 : If there is carry add multiplicand to product.
Step 6 : Decrement the count.
Step 7 : If count 0; Go to step 4
Step 8 : Store the product i.e. result in memory location.
Step 9 : Stop the execution
Flow Chart
Start
Is carry
exists from
multiplier ?
No
Yes
Product = Product + Multiplicand
54
Count = count -1
No
Is count
=0?
Yes
Store result
Stop
Figure 25
PROGRAM:
ADDRESS
8000
8003
8004
8005
8006
8007
8008
8009
800A
800B
800C
800D
800E
800F
8010
8011
HEX
COD
E
LABE
L
2A,0
0,85
EB
3A
02
85
21
00
00
0E
08
29
LOO
P
17
D2
12
80
19
MNEMONIC
COMMENTS
OPCOD
E
OPERAND
LHLD
H, 8500
XCHG
LDA
8502
LXI
H.0000
MVI
C,08
Count =08
DAD
RAL
JNC
FWD
DAD
55
8012
8013
8014
8015
8016
0D
C2
0C
80
22
8017
8018
8019
03
85
76
FWD
DCR
JNZ
C
LOOP
COUNT=COUNT-1
SHLD
8503
HLT
INPUT :
Result:
Address
8500
8501
8502
Data
8AH LSB of Multiplicand
00 H MSB of Multiplicand
52 H - Multiplier
8503
8504
34 H LSB of Product
2C H MSB of Product
Division Programs
Example 7:
Explanation: The division of a 16/8-bit number by a 8-bit number follows the successive
subtraction method. The divisor is subtracted from the MSBs of the dividend .If a borrow occurs,
the bit of the quotient is set to 1 else 0.For correct subtraction process the dividend is shifted left
by one bit before each subtraction. The dividend and quotient are in a pair of register H-L.The
vacancy arised due to shifting is occupied by the quotient .In the present example the dividend is
a 16-bit number and the divisor is a 8-bit number. The dividend is in locations 8500
&8501.Similarly the divisor is in the location 8502.The quotient is stored at 8503 and the
remainder is stored at 8504 locations.
ALGORTHM:
STEP1. : Initialise H-L pair with address of dividend.
STEP2. : Get the divisor from 8502 to register A & then to Reg.B
STEP3. : Make count C=08
STEP4. : Shift dividend and divisor left by one bit
STEP 5: Subtract divisor from dividend.
STEP6. : If carry = 1 : goto step 8 else step7.
STEP7. : Increment quotient register.
STEP8. : Decrement count in C
STEP9. : If count not equal to zero go to step 4
STEP10: Store the quotient in 8503
STEP11: Store the remainder in 8504
STEP12: Stop execution.
56
57
Flowchart
START
bit+
Is MSBs of
Dividend >
Divisor ?
No
Yes
Quotient = Quotient +1
8 MSBs of dividend =
8 MSBs of dividend -divisor
Count = Count-1
No
Is
Count
=0?
Yes
Stop
Fig.26
58
PROGRAM:
ADD
RESS
8000
8001
8002
8003
8004
8005
8006
HEX LABEL
CODE
8007
8008
8009
0E
08
29
800A
MNEMONIC
OPCOD OPERAN
E
D
LHLD
H, 8500
COMMENTS
LDA
8502 H
Load
the
divisor
from
location 8502 to accumulator
MOV
B,A
MVI
C,08
DAD
7C
MOV
A,H
800B
90
SUB
800C
800D
800E
800F
DA
11
80
67
JC
FWD
MOV
H,A
8010
8011
8012
8013
8014
8015
8016
8017
8018
2C
0D
C2
09
80
22
03
85
76
INR
DCR
JNZ
L
C
BACK
SHLD
8503H
Ex:
21
00
85
3A
02
85
47
BACK
FWD
HLT
Address
8500
8501
8502
8503
8504
Data
64 LSB of Dividend
00 MSB of Dividend
07 Divisor
0E Quotient
02 Remainder
59
Explanation: To find the largest number in a data array of N numbers (say)first the count is
placed in memory location (8500H) and the data are stored in consecutive
locations.(8501.onwards).The first number is copied to Accumulator and it is compared with
the second number in the memory location. The larger of the two is stored in Accumulator. Now
the third number in the memory location is again compared with the accumulator. And the largest
number is kept in the accumulator. Using the count, this process is completed , until all the
numbers are compared .Finally the accumulator stores the smallest number and this number is
stored in the memory location.85XX.
ALGORTHM:
Step1: Store the count in the Memory location pointed by H-L register.
Step2: Move the I st number of the data array in to accumulator
Step3: Compare this with the second number in Memory location.
Step4: The larger in the two is placed in Accumulator
Step5: The number in Accumulator is compared with the next number in memory .
Step 6: The larger number is stored in Accumulator.
Step 7; The process is repeated until the count is zero.
Step 8: Final result is stored in memory location.
Step 9: Stop the execution
60
Flow Chart
START
Yes
No
Is
Number in
Accumulator>
Next number ?
No
Decrement Count
No
Is count = 0
?
Yes
store the result in the
location 85XX
STOP
Fig 27
61
PROGRAM
ADD
RESS
8000
HEX LABEL
CODE
MNEMONIC
OPCOD OPERAN
E
D
LXI
H, 8500
COMMENTS
MOV
INX
MOV
C,M
H
A,M
DCR
INX
CMP
C
H
M
8003
8004
8005
21,00,8
5
7E
23
4E
8006
8007
8008
0D
91
BE
8009
D2
JNC
LOOP2
800A
800B
800C
0D
80
7E
MOV
A,M
800D
800E
0D
C2
DCR
JNZ
C
LOOP1
800F
8011
8012
8013
07
80
78
32
STA
85XX
8014
8015
8016
XX
85
76
HLT
Ex : Input :
LOOP1
LOOP2
If,yes move
the large
number in to Accumulator
Decrement the count
If count not equal to
zero,repeat
Result : 8508 - 7F
62
Example 9 :
Explanation: To find the smallest number in a data array of N numbers (say)first the count is
placed in memory location (8500H) and the data are stored in consecutive
locations.(8501.onwards).The first number is copied to Accumulator and it is compared with
the second number in the memory location.The smaller of the two is stored in Accumulator.Now
the third number in the memory location is again compared with the accumulator.and the
smallest number is kept in the accumulator.Using the count,this process is completed until all
the numbers are compared .Finally the accumulator stores the smallest number and this number
is stored in the memory location.85XX.
ALGORTHM :
Step1: Store the count in the Memory location pointed by H-L register.
Step2: Move the I st number of the data array in to accumulator
Step3: Compare this with the second number in Memory location.
Step4: The smaller in the two is placed in Accumulator
Step5: The number in Accumulator is compared with the next number in memory .
Step 6: The smaller number is stored in Accumulator.
Step 7; The process is repeated until the count is zero.
Step 8: Final result is stored in memory location.
Step 9: Stop the execution
63
Flow Chart
START
Yes
Is
Number in
Accumulator<
Next number ?
No
Get smaller number in
Accumulator
Decrement Count
Is count =
0 ?
No
Yes
store the result at 85xx
STOP
Fig.28
64
PROGRAM
ADD
RESS
8000
8001
8002
8003
8004
8005
HEX LABEL
CODE
8006
8007
8008
0D
91
BE
8009
MNEMONIC
OPCOD OPERAN
E
D
LXI
H, 8500
COMMENTS
MOV
INX
MOV
C,M
H
A,M
DCR
INX
CMP
C
H
M
D2
JC
LOOP2
800A
800B
800C
0D
80
7E
MOV
A,M
800D
800E
0D
C2
DCR
JNZ
C
LOOP1
800F
8011
8012
8013
07
80
78
32
STA
85XX
8014
8015
8016
XX
85
76
HLT
21
00
85
7E
23
4E
Ex: Input :
LOOP1
LOOP2
No,move
the smaller
number in to Accumulator
Decrement the count
If count not equal to
zero,repeat
65
Stack is implemented in two ways. In the first case, a set of registers is arranged in a
shift register organization. One can PUSH or POP data from the top register. The whole block of
data moves up or down as a result of push and pop operations respectively. In the second case,
a block of RAM area is allocated to the stack. A special purpose register known as stack pointer
(SP) points to the top of the stack. Whenever the stack is empty, it points to the bottom address.
If a PUSH operation is performed, the data are stored at the location pointed to by SP and it is
decremented by one. Similarly if the POP operation is performed, the data are taken out of the
location pointed at by SP and SP is incremented by one. In this case the data do not move but
SP is incremented or decremented as a result of push or pop operations respectively.
3.14.1 Application of Stack: Stack provides a powerful data structure which has applications in
many situations. The main advantage of the stack is that,
We can store data (PUSH) in it with out destroying previously stored data. This is not true in the
case of other registers and memory locations.
stack operations are also very fast
The stack may also be used for storing local variables of subroutine and for the transfer of
parameter addresses to a subroutine. This facilitates the implementation of re-entrant
subroutines which is a very important software property.
The disadvantage is, as the stack has no fixed address, it is difficult to debug and document a
program that uses stack.
3.14.2 Stack operation: Operations on stack are performed using the two instructions namely
PUSH and POP. The contents of the stack are moved to certain memory locations after PUSH
instruction. Similarly, the contents of the memory are transferred back to registers by POP
instruction.
For example let us consider a Stack whose stack top is 4506 H. This is stored in the 16bit Stack pointer register as shown in Fig.3.29
25
62
66
After PUSH operation the status of the Stack is as shown in Fig 3.30
67
Label
Mnemonics
Operand
Comments
LXI
SP, 4506 H
Initialize
Stack pointer
8003
LXI
H,2565 H
8006
8007
.
.
.
.
8.00A
PUSH
DELAY
CALL
.
.
.
.
.
.
POP
Push
the
contents.
68
Subroutine: It is a set of instructions written separately from the main program to execute a
function that occurs repeatedly in the main program.
For example, let us assume that a delay is needed three times in a program. Writing delay
programs for three times in a main program is nothing but repetition. So, we can write a
subroutine program called delay and can be called any number of times we need
Similarly, in 8085 microprocessor we do not find the instructions for multiplication and
division. For this purpose we write separate programs. So, in any main program if these
operations are needed more than once, the entire program will become lengthy and complex. So,
we write subroutine programs MUL & DIV separately from main program and use the instruction
CALL MUL (or) CALL DIV in the main program. This can be done any number of times. At the
end of every subroutine program there must be an instruction called RET. This will take the
control back to main program.
The 8085 microprocessor has two instructions to implement the subroutines. They are CALL
and RET. 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 the program counter, which is the address of the instruction following
the CALL instruction is stored on 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 on the stack is retrieved and the sequence of execution is resumed in
the main program.
Diagrammatic representation
Let us assume that the execution of the main program started at 8000 H. It continues until a
CALL subroutine instruction at 8020 H is encountered. Then the program execution transfers to
8070 H. At the end of the subroutine 807B H. The RET instruction is present. After executing this
RET, it comes back to main program at 8021 H as shown in the following Fig. 3.34
69
Mnemonics
Operand
Comments
8000
|
|
|
8020
8021
8022
8023
|
|
|
802F
LXI
SP, 8400 H
CALL
8070 H
Next instruction
|
|
|
HLT
Subroutine Program:
Memory
Address
8070
|
|
|
|
807B
Mnemonics
807C
Next Subroutine
Instructions
RET
807F
RET
Operand
Comments
Beginning of the Subroutine.
Delay programs:
In many situations it may be desired to provide some delay between the execution of two
instructions by a microprocessor. The delay can be produced by either hardware chip like 8253
or by writing a software program using registers of the processor. Here we will discuss the
software delay program. This delay program is not a part of the main program. Hence it is called
delay sub-routine program. For small delays we can use only one register. But for longer delays
one has to use two or three registers. The technique involved here is, a register is loaded with a
number and then decremented by using the instruction DCR until it becomes zero. The time of
execution of the microprocessor is equal to the delay time produced.
For example, we have constructed a display system where the LEDs receive the input from a
microprocessor. Since the microprocessor is a very fast device it sends the signal at very high
70
speeds there by our eye cannot recognize the display pattern. So, if you provide some delay
between two input signals, the display can be visualized clearly. Similarly to observe the rotations
of a stepper motor, a delay is needed between every two excitation signals applied to the motor.
Delay Subroutine with one register:
Program
Address Label
Machine
code
Mnemonics
Operand
Comments
MVI
A, FF
Get FF in register A
DCR
Decrement register A.
9003
JNZ
LOOP
9006
RET
9000
9002
LOOP
We should know the number of times each instruction of the above program is being
executed. The number of states required for the execution of each instruction is as follows:
Instructions
MVI A, FFH
(loop) DCR A
JNZ loop
RET
States
7
4
7/10
10
Total T States=3584
71
The time required for one T-state in INTEL 8085 microprocessor is nearly 330n.sec
Address Label
8400
MVI
B, 10H
8402
LOOP1
MVI
C, 56H
8404
LOOP2
DCR
Decrement C.
8405
JNZ
LOOP2
8408
DCR
Decrement register B
8409
JNZ
LOOP1
840C
RET
Addres
s
Label
8000
LOOP
Machin
e
Code
Mnemonic Operand
Comments
LXI
D, FFFF
DCX
Decrement count
MOV
A, D
ORA
JNZ
LOOP
RET
72
Addres
s
Label
Machin
e
Code
Mnemonic
Operand
Comments
8400
MVI
A, 98H
8402
OUT
03
8404
MVI
B, 50H
8406
MVI
C, FFH
8408
MVI
D, FFH
840A
DCR
840B
JNZ
LOOP3
840E
DCR
840F
JNZ
LOOP2
8412
DCR
8413
JNZ
LOOP1
8416
MVI
A, 01
8418
OUT
01
8419
HLT
Delay Subroutine
registers
with
three
From the above discussion it is clear that with increase of T-states required for a delay
subroutine ,the delay time also increases.
-----------------x------------------
73
74
75