Notes MP unit 2
Notes MP unit 2
UNIT 2
The 8085 microprocessor is an 8-bit processor available as a 40-pin IC package and uses +5 V for
power. It can run at a maximum frequency of 3 MHz. Its data bus width is 8-bit and address bus
width is 16-bit, thus it can address 216 = 64 KB of memory. The internal architecture of 8085 is
shown is Fig. 1.
Fig 1.
1. Arithmetic and Logic Unit The ALU performs the actual numerical and logical operations such
as Addition (ADD), Subtraction (SUB), AND, OR etc. It uses data from memory and from
Accumulator to perform operations. The results of the arithmetic and logical operations are stored
in the accumulator.
2. Registers The 8085 includes six registers, one accumulator and one flag register, as shown in Fig.
2. In addition, it has two 16-bit registers: stack pointer and program counter. They are briefly
described as follows. The 8085 has six general-purpose registers to store 8-bit data; these are
identified as B, C, D, E, H and L. they can be combined as register pairs - BC, DE and HL to
perform some 16- bit operations. The programmer can use these registers to store or copy data
into the register by using data copy instructions.
Fig 2.
2.1 Accumulator The accumulator is an 8-bit register that is a part of ALU. This register is used to
store 8-bit data and to perform arithmetic and logical operations. The result of an operation is stored
in the accumulator. The accumulator is also identified as register A.
2.2 Flag register The ALU includes five flip-flops, which are set or reset after an operation
according to data condition of the result in the accumulator and other registers. They are called Zero
(Z), Carry (CY), Sign (S), Parity (P) and Auxiliary Carry (AC) flags. Their bit positions in the flag
register are shown in Fig. 3. The microprocessor uses these flags to test data conditions.
Fig 3.
For example, after an addition of two numbers, if the result in the accumulator is larger than 8-bit, the
flip-flop uses to indicate a carry by setting CY flag to 1. When an arithmetic operation results in zero,
Z flag is set to 1. The S flag is just a copy of the bit D7 of the accumulator. A negative number has a
1 in bit D7 and a positive number has a 0 in 2’s complement representation. The AC flag is set to 1,
when a carry result from bit D3 and passes to bit D4. The P flag is set to 1, when the result in
accumulator contains even number of 1s.
2.3 Program Counter (PC) This 16-bit register deals with sequencing the execution of instructions.
This register is a memory pointer. The microprocessor uses this register to sequence the execution of
the instructions. The function of the program counter is to point to the memory address from which
the next byte is to be fetched. When a byte is being fetched, the program counter is automatically
incremented by one to point to the next memory location.
2.4 Stack Pointer (SP) The stack pointer is also a 16-bit register, used as a memory pointer. It points
to a memory location in R/W memory, called stack. The beginning of the stack is defined by loading
16-bit address in the stack pointer.
2.5 Instruction Register/Decoder It is an 8-bit register that temporarily stores the current
instruction of a program. Latest instruction sent here from memory prior to execution. Decoder then
takes instruction and decodes or interprets the instruction. Decoded instruction then passed to next
stage.
3. Control Unit
Generates signals on data bus, address bus and control bus within microprocessor to carry out the
instruction, which has been decoded. Typical buses and their timing are described as follows:
3.1 Data Bus: Data bus carries data in binary form between microprocessor and other external units
such as memory. It is used to transmit data i.e. information, results of arithmetic etc between memory
and the microprocessor. Data bus is bidirectional in nature. The data bus width of 8085
microprocessor is 8-bit i.e. 28 combination of binary digits and are typically identified as D0 – D7.
Thus size of the data bus determines what arithmetic can be done. If only 8-bit wide then largest
number is 11111111 (255 in decimal). Therefore, larger numbers have to be broken down into
chunks of 255. This slows microprocessor.
3.2 Address Bus: The address bus carries addresses and is one way bus from microprocessor to the
memory or other devices. 8085 microprocessor contain 16-bit address bus and are generally
identified as A0 - A15. The higher order address lines (A8 – A15) are unidirectional and the lower
order lines (A0 – A7) are multiplexed (timeshared) with the eight data bits (D0 – D7) and hence, they
are bidirectional.
3.3 Control Bus: Control bus are various lines which have specific functions for coordinating and
controlling microprocessor operations. The control bus carries control signals partly unidirectional
and partly bidirectional. The following control and status signals are used by 8085 processor:
I. ALE (output): Address Latch Enable is a pulse that is provided when an address appears on the
AD0 – AD7 lines, after which it becomes 0.
MUX/DEMUX unit
This unit is used to select a register out of all the available registers.
This unit behaves as a MUX when data is going from the register to the internal data bus.
It behaves as a DEMUX when data is coming to a register from the internal data bus of the
microprocessor.
The register select will behave as the function selection lines of the MUX/DEMUX.
Fig 4.
1. Address and Data Buses:
A8 – A15 (output, 3-state): Most significant eight bits of memory addresses and the eight bits of
the I/O addresses. These lines enter into tri-state high impedance state during HOLD and HALT
modes.
AD0 – AD7 (input/output, 3-state): Lower significant bits of memory addresses and the eight bits
of the I/O addresses during first clock cycle. Behaves as data bus during third and fourth clock
cycle. These lines enter into tri-state high impedance state during HOLD and HALT modes.
2. Control & Status Signals:
ALE: Address latch enable
RD : Read control signal.
WR : Write control signal.
IO/M, S1 and S0 : Status signals.
INSTRUCTION SET
Based on the design of the ALU provides instruction set for every machine code and mnemonics. and
decoding unit, the microprocessor manufacturer microprocessor. The instruction set consists of both
An instruction is a binary pattern designed inside a microprocessor to perform a specific function.
The entire group of instructions that a microprocessor supports is called instruction set.
Microprocessor instructions can be classified based on the parameters such functionality, length and
operand addressing.
Classification based on functionality:
1. Data transfer operations: This group of instructions copies data from source to destination. The
content of the source is not altered.
MOV Rd, Rs Copy from This instruction copies the contents of the source
source(Rs) to register into the destination register; the contents
M, Rs destination(Rd) of the source register are not altered. If one of the
operands is a memory location, its location is
Rd, M specified by the contents of the HL registers.
MVI Rd, data Move immediate 8- The 8-bit data is stored in the destination register
bit or memory. If the operand is a memory location, its
M, data location is specified by the contents of the HL
registers.
LDAX B/D Reg. Load accumulator The contents of the designated register pair point to
pair indirect a memory location. This instruction copies the
contents of that memory location into the
accumulator. The contents of either the register
pair or the memory location are not altered.
Example: LDAX B
LXI Reg. Load register pair The instruction loads 16-bit data in the register pair
pair, 16- immediate designated in the operand.
bit data
Example: LXI H, 2034H or LXI H, XYZ
LHLD 16-bit Load H and L The instruction copies the contents of the memory
address registers direct location pointed out by the 16-bit address into
register L and copies the contents of the next
memory location into register H. The contents of
source memory locations are not altered.
STA 16-bit 16-bit address The contents of the accumulator are copied into the
address memory location specified by the operand. This is a
3-byte instruction, the second byte specifies the
low-order address and the third byte specifies the
high-order address.
STAX Reg. Store accumulator The contents of the accumulator are copied into the
pair indirect memory location specified by the contents of the
operand (register pair). The contents of the
accumulator are not altered.
Example: STAX B
SHLD 16-bit Store H and L The contents of register L are stored into the
address registers direct memory location specified by the 16-bit address in
the operand and the contents of H register are
stored into the next memory location by
incrementing the operand. The contents of registers
HL are not altered. This is a 3-byte instruction, the
second byte specifies the low-order address and the
third byte specifies the high-order address.
XCHG none Exchange H and L The contents of register H are exchanged with the
with D and E contents of register D, and the contents of register
L are exchanged with the contents of register E.
Example: XCHG
SPHL none Copy H and L The instruction loads the contents of the H and L
registers to the registers into
stack pointer the stack pointer register, the contents of the H
register provide the high-order address and the
contents of the L register provide the low-order
address. The contents of the H
and L registers are not altered.
Example: SPHL
XTHL none Exchange H and L The contents of the L register are exchanged with
with top of stack the stack location pointed out by the contents of
the stack pointer register. The contents of the H
register are exchanged with the next stack location
(SP+1); however, the contents of the stack pointer
register are not altered.
Example: XTHL
PUSH Reg. Push register pair The contents of the register pair designated in the
pair onto stack operand are copied onto the stack in the following
sequence. The stack pointer register is
decremented and the contents of the highorder
register (B, D, H, A) are copied into that location.
The stack pointer register is decremented again
and the contents of the low-order register (C, E, L,
flags) are copied to that location.
POP Reg. Pop off stack to The contents of the memory location pointed out by
pair register pair the stack pointer register are copied to the low-
order register (C, E, L, status flags) of the operand.
The stack pointer is incremented by 1 and the
contents of that memory location are copied to the
high-order register (B, D, H, A) of the operand. The
stack pointer register is again incremented by 1.
OUT 8-bit Output data from The contents of the accumulator are copied into
port accumulator to a the I/O port specified by the operand.
address port with 8-bit
address Example: OUT F8H
IN 8-bit Input data to The contents of the input port designated in the
port accumulator from a operand are read and loaded into the accumulator.
address port with 8-bit
address Example: IN 8CH
2.Arithmetic Instructions
ADI 8-bit Add The 8-bit data (operand) is added to the contents of
data immediate the accumulator and the result is stored in the
to accumulator. All flags are modified to reflect the
accumulat result of the addition.
or
Example: ADI 45H
ACI 8-bit Add The 8-bit data (operand) and the Carry flag are
data immediate added to the contents of the accumulator and the
to result is stored in the accumulator. All flags are
accumulat modified to reflect the result of the addition.
or with
carry Example: ACI 45H
LXI Reg. Load The instruction loads 16-bit data in the register pair
pair, register designated in the operand.
16-bit pair
data immediate Example: LXI H, 2034H or LXI H, XYZ
DAD Reg. Add The 16-bit contents of the specified register pair are
pair register added to the contents of the HL register and the
pair to H sum is stored in the HL register. The contents of the
and L source register pair are not altered. If the result is
registers larger than 16 bits, the CY flag is set. No other flags
are affected.
Example: DAD H
SUI 8-bit Subtract The 8-bit data (operand) is subtracted from the
data immediate contents of the accumulator and the result is stored
from in the accumulator. All flags are modified to reflect
accumulat the result of the subtraction.
or
Example: SUI 45H
SBI 8-bit Subtract The contents of register H are exchanged with the
data immediate contents of register D, and the contents of register
from L are exchanged with the contents of register E.
accumulat
or with Example: XCHG
borrow
Example: INX H
Example: DCX H
DAA none Decimal The contents of the accumulator are changed from
adjust a binary value to two 4-bit binary coded decimal
accumulat (BCD) digits. This is the only instruction that uses
or the auxiliary flag to perform the binary to BCD
conversion, and the conversion procedure is
described below. S, Z, AC, P, CY flags are altered to
reflect the results of the operation.
Example: DAA
3.LOGICAL INSTRUCTIONS
CPI 8-bit Compare immediate The second byte (8-bit data) is compared
with accumulator with the contents of the accumulator. The
values being compared remain unchanged.
The result of the comparison is shown by
setting the flags of the PSW as follows:
if (A) < data: carry flag is set
if (A) = data: zero flag is set
if (A) > data: carry and zero flags are reset
Example: CPI 89H
ANA Logical AND register The contents of the accumulator are
or memory with logically ANDed with M the contents of the
accumulator operand (register or memory), and the
result is placed in the accumulator. If the
operand is a memory location, its address is
specified by the contents of HL registers. S,
Z, P are modified to reflect the result of the
operation. CY is reset. AC is set.
Example: RLC
Example: RRC
Example: RAL
Example: RAR
Example: CMA
Example: CMC
Example: STC
4.BRANCHING INSTRUCTIONS
d n of
Instruction
Jump on parity
JPE P=1
even
Jump on parity
JPO P=0
odd
Opcode Description Flag Status 16-bit Uncondition The program sequence is
transferred to the memory
address al
CC Call on Carry CY = 1 location specified by the 16-bit
subroutine address given in the operand.
CNC Call on no Carry CY = 0 Before the transfer, the address
call
of the next instruction after CALL
CP Call on positive S=0 (the contents of the program
counter) is pushed onto the
CM Call on minus S=1 stack.
Example: CALL 2034H or CALL
XYZ
CZ Call on zero Z=1
Call on parity
CPO P=0
Example: PCHL
5.Control Instructions
Example: NOP
HLT none Halt and enter wait The CPU finishes executing the current
instruction and halts any further execution. An
state
interrupt or reset is necessary to exit from the
halt state.
Example: HLT
DI none Disable interrupts The interrupt enable flip-flop is reset and all the
interrupts except the TRAP are disabled. No
flags are affected.
Example: DI
EI none Enable interrupts The interrupt enable flip-flop is set and all
interrupts are enabled. No flags are affected.
After a system reset or the acknowledgement of
an interrupt, the interrupt enable flipflop is
reset, thus disabling the interrupts. This
instruction is
necessary to reenable the interrupts (except
TRAP).
Example: EI
RIM none Read interrupt mas This is a multipurpose instruction used to read
the status of interrupts 7.5, 6.5, 5.5 and read
serial data input bit. The instruction loads eight
bits in the accumulator with the following
interpretations.
Example: RIM
SIM none Set interrupt mask This is a multipurpose instruction and used to
implement the 8085 interrupts 7.5, 6.5, 5.5, and
serial data output. The instruction interprets the
accumulator contents as follows.
Example: SIM
A small program or a routine that when executed, services the corresponding interrupting
source is called an ISR.
TRAP
It is a non-maskable interrupt, having the highest priority among all interrupts. Bydefault, it
is enabled until it gets acknowledged. In case of failure, it executes as ISR and sends the
data to backup memory. This interrupt transfers the control to the location 0024H.
RST7.5
It is a maskable interrupt, having the second highest priority among all interrupts. When
this interrupt is executed, the processor saves the content of the PC register into the stack
and branches to 003CH address.
RST 6.5
It is a maskable interrupt, having the third highest priority among all interrupts. When this
interrupt is executed, the processor saves the content of the PC register into the stack and
branches to 0034H address.
RST 5.5
It is a maskable interrupt. When this interrupt is executed, the processor saves the content
of the PC register into the stack and branches to 002CH address.
INTR
It is a maskable interrupt, having the lowest priority among all interrupts. It can be disabled
by resetting the microprocessor.
When INTR signal goes high, the following events can occur −
The microprocessor checks the status of INTR signal during the execution of each
instruction.
When the INTR signal is high, then the microprocessor completes its current
instruction and sends active low interrupt acknowledge signal.
When instructions are received, then the microprocessor saves the address of the
next instruction on stack and executes the received instruction.
TIMING DIAGRAM
Each instruction in 8085 microprocessor consists of two part- operation code (opcode) and
operand. The opcode is a command such as ADD and the operand is an object to be operated on,
such as a byte or the content of a register.
Instruction Cycle: The time taken by the processor to complete the execution of an instruction. An
instruction cycle consists of one to six machine cycles.
Machine Cycle: The time required to complete one operation; accessing either the memory or I/O
device. A machine cycle consists of three to six T-states.
T-State: Time corresponding to one clock period. It is the basic unit to calculate execution of
instructions or programs in a processor.
To execute a program, 8085 performs various operations as:
Opcode fetch
Operand fetch
Memory read/write
I/O read/write
External communication functions are:
Memory read/write
I/O read/write
Interrupt request acknowledge
1. Opcode Fetch Machine Cycle: It is the first step in the execution of any instruction. The timing
diagram of this cycle is given in Fig. 5. The following points explain the various operations that
take place and the signals that are changed during the execution of opcode fetch machine cycle:
T1 clock cycle
i. The content of PC is placed in the address bus; AD0 - AD7 lines contains lower bit address and
A8 – A15 contains higher bit address.
ii. IO/M signal is low indicating that a memory location is being accessed. S1 and S0 also
changed to the levels as indicated in Table 1.
iii.ALE is high, indicates that multiplexed AD0 – AD7 act as lower order bus.
T2 clock cycle
i. Multiplexed address bus is now changed to data bus.
ii. The RD signal is made low by the processor. This signal makes the memory device load the
data bus with the contents of the location addressed by the processor.
T3 clock cycle
i. The opcode available on the data bus is read by the processor and moved to the instruction
register.
ii. The RD signal is deactivated by making it logic 1.
T4 clock cycle
i. The processor decode the instruction in the instruction register and generate the necessary
control signals to execute the instruction. Based on the instruction further operations such as
fetching, writing into memory etc takes place.