Module 2
Module 2
8085 Instructions
An instruction of computer is a command given to the computer to perform a
specified operation on given data.
Some instructions of Intel 8085 microprocessor are: MOV, MVI, LDA, STA, ADD,
SUB, RAL, INR, MVI, etc.
Instruction and Data Formats
The various techniques to specify data for instructions are:
1. 8-bit or 16-bit data may be directly given in the instruction itself.
2. The address of the memory location, I/O port or I/O device, where data
resides, may be given in the instruction itself.
3. In some instructions, only one register is specified. The content of the
specified register is one of the operands.
4. Some instructions specify two registers. The contents of the registers are the
required data.
5. In some instructions, data is implied. The most instructions of this type
operate on the content of the accumulator.
Due to different ways of specifying data for instructions, the machine codes of all
instructions are not of the same length. It may 1-byte, 2-byte or 3-byte instruction.
Opcode and Operands
Each instruction contains two parts: Opcode (Operation code) and Operand.
The 1st part of an instruction which specifies the task to be performed by the
computer is called Opcode.
The 2nd part of the instruction is the data to be operated on, and it is called
Operand. The Operand (or data) given in the instruction may be in various forms
such as 8-bit or 16-bit data, 8-bit or 16-bit address, internal registers or a
register or memory location.
Example:
MOV B, C
Opcode: MOV
Operand: B and C
Given instruction copies the contents of the source register into the destination
register and the contents of the source register are not altered. B is the
destination register and C is the source register whose contents need to be
transferred to the destination register.
Mnemonics
A mnemonic in the microprocessor is a symbol, a name or a term that defines a
computer function or operation.
A mnemonic is always used to give users quick access to computer functions,
processes or services.
Through mnemonics, a user will bypass the actual and long ways or path to
perform a task.
An assembly language makes use of mnemonics to describe an opcode.
An example of a mnemonic is MOV which means moving data from one memory
location or register to another.
There are many other mnemonics in the microprocessor that makes achieving a
computer task easier and faster.
The mnemonic in the microprocessor is acronym/abbreviation, for operation.
It is used in instruction code to make easy and suitable coding.
The mnemonics are R used for the register, A for the accumulator, Z for zero
flags, etc.
SHLD 16-bit address directly stores from H & L registers SHLD 2050
LXI r.p., 16-bit Load Register pair immediate (loads LXI H, 3050
data the specified register pair with data)
STAX 16-bit address indirectly stores from the accumulator STAX 2050
A
In the table,
R stands for register
M stands for memory
Mc stands for memory contents
r.p. stands for register pair
Arithmetic Instructions
The instructions of this group perform arithmetic operations such as addition,
subtraction, increment or decrement of the content of a register or a memory.
In 8085 microprocessor, the destination operand is generally the accumulator.
Opcod Operand Explanation Example
e
Logical Instructions
The instructions in this group perform logical operation such as AND, OR,
compare, etc.
In 8085 microprocessor, the destination operand is always the accumulator.
Here logical operation works on a bitwise level.
A = A AND R
ANA R AND register with accumulator ANA B
OPCODE OPERAND DESTINATION EXAMPLE
A = A AND Mc
ANA M AND memory with accumulator ANA 2050
A = A OR R
ORA R OR-register with accumulator ORA B
A = A OR Mc
ORA M OR-memory with accumulator ORA 2050
A = A OR 8-bit data
ORI 8-bit data OR -immediate data with accumulator ORI 50
A = A XOR R
XRA R XOR register with accumulator XRA B
A = A XOR Mc
XRA M XOR memory with accumulator XRA 2050
A = 1’s compliment of A
CMA none Complement the accumulator CMA
2. Call Instructions – The call instruction transfers the program sequence to the
memory address given in the operand. Before transferring, the address of the
next instruction after CALL is pushed onto the stack. Call instructions are 2 types:
a. Unconditional Call Instructions
b. Conditional Call Instructions
(b) Conditional Call Instructions: Only if the condition is satisfied, the instructions
execute.
HLT None Halt and enter wait state (The CPU finishes
executing the current instruction and stops
further execution. An interrupt or reset is
necessary to exit from the halt state.)
Subroutine in 8085
RET is the instruction used to mark the end of sub-routine. It has no parameter. After
execution of this instruction program control is transferred back to main program from
where it had stopped. Value of PC (Program Counter) is retrieved from the memory
stack and value of SP (Stack Pointer) is incremented by 2.
o Conditional Return instruction
By these instructions program control is transferred back to main program and value of
PC is popped from stack only if condition is satisfied. There is no parameter for return
instruction.
INSTRUCTION COMMENT
Advantages of Subroutine –
1. Decomposing a complex programming task into simpler steps.
2. Reducing duplicate code within a program.
3. Enabling reuse of code across multiple programs.
4. Improving tractability or makes debugging of a program easy.
Each instruction requires some data on which it has to operate. There are
different techniques to specify data for instructions. These techniques are
called addressing modes.
These are the instructions used to transfer the data from one register to another
register, from the memory to the register, and from the register to the memory
without any alteration in the content.
Addressing modes in 8085 is classified into 5 groups –
Immediate addressing mode
Register addressing mode
Direct addressing mode
Register Indirect addressing mode
Implied addressing mode
1. Immediate addressing mode
In this addressing mode, the operand is specified within the instruction itself.
The 8/16-bit data is specified in the instruction itself as one of its operand.
For example:
o MVI B, 20F - means 20F is copied into register B.
o LXI H, 2500 - 2500 is 16-bit data which is given in the instruction
itself. It is to be loaded into H-L pair.
2. Register addressing mode
In this addressing mode, the data is copied from one register to another.
The operand is in one of the general purpose registers. The opcode specifies the
address of the register(s) in addition to the operation to be performed.
For example:
o MOV A, B - means data in register B is copied to register A.
3. Direct addressing mode
In this addressing mode, the address of the operand (data) is given in the
instruction itself.
The data is directly copied from the given address to the register.
For example:
o STA 2400H - It stores the content of the accumulator in the memory
location 2400H.
4. Register Indirect addressing mode
In Register Indirect mode of addressing, the data is transferred from one register
to another by using the address pointed by the register.
The address of the operand is specified by a register pair.
For example:
o MOV C, B - means data is transferred from the memory address
pointed by the register B to the register C.
5. Implied addressing mode
This mode doesn’t require any operand; the data is specified by the opcode itself.
There are certain instructions which operate on the content of the accumulator.
Such instructions do not require the address of the operand.
For example:
o CMP, RAL, RAR, etc.
Interrupts in 8085
Interrupts are the signals generated by the external devices to request the
microprocessor to perform a task. There are 5 interrupt signals, i.e. TRAP, RST 7.5, RST
6.5, RST 5.5, and INTR.
Software interrupt − In this type of interrupt, the programmer has to add the
instructions into the program to execute the interrupt. There are 8 software
interrupts in 8085, i.e. RST0, RST1, RST2, RST3, RST4, RST5, RST6, and RST7.
TRAP: It is a non-maskable interrupt, having the highest priority among all interrupts.
By default, it is enabled until it gets acknowledged. In case of failure, it executes as ISR
and sends the data to backup memory.
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.
I/O Interfacing
Interface is the path for communication between two components. Interfacing is
of two types:
Memory interfacing and
I/O interfacing
Several memory chips and I/O devices are connected to a microprocessor. The
following figure shows a schematic diagram to interface memory chips and I/O devices
to a microprocessor.
Memory Interfacing
When we are executing any instruction, we need the microprocessor to access
the memory for reading instruction codes and the data stored in the memory.
For this, both the memory and the microprocessor require some signals to read
from and write to registers.
The interfacing process includes matching the memory requirements with the
microprocessor signals.
Therefore, the interfacing circuit should be designed in such a way that it
matches the memory signal requirements with the microprocessor's signals.
I/O Interfacing
Any application of a microprocessor based system requires the transfer of data
between external circuitry to the microprocessor and microprocessor to the
external circuitry.
There are various communication devices like the keyboard, mouse, printer, etc.
User can give information to the microprocessor using keyboard and user can
see the result or output information from the microprocessor with the help of
display device.
So, we need to interface the keyboard and other devices with the
microprocessor. This type of interfacing is known as I/O interfacing.
In other words, the transfer of data between keyboard and microprocessor, and
microprocessor and display device is called Input Output Interfacing 8085
Microprocessor or I/O data transfer.
For this type of interfacing, we use latches and buffers for interfacing the
keyboards and displays with the microprocessor or we can say, the data transfer
is done with the help of I/O ports.
Input Port:
o It is used to read data from the input device such as keyboard.
o The simplest form of input port is a buffer.
o The input device is connected to the microprocessor through buffer as shown in
the figure. This buffer is a tri-state buffer and its output is available only when
enable signal is active.
When microprocessor wants to read data from the input device (keyboard), the
control signals from the microprocessor activates the buffer by asserting enable input of
the buffer. Once the buffer is enabled, data from the input device is available on the data
bus. Microprocessor reads this data by initiating read command.
Output Port:
o It is used to send data to the output device such as display from the
microprocessor.
o The simplest form of output port is a latch.
o The output device is connected to the microprocessor through latch as shown in
the figure.
When microprocessor wants to send data to the output device, it puts the data on
the data bus and activates the clock signal of the latch, latching the data from the data
bus at the output of latch. It is then available at the output of latch for the output device.
In 8085 Instruction set, there are two instructions in 8085 for communication
with I/O ports. They are the IN and OUT instructions. The IN or OUT instruction
mnemonic should be followed by an 8-bit port address. Thus we can have 2 8 = 256 input
ports and 256 output ports are possible in 8085-based microcomputer. IN and OUT
both are 2-Bytes instructions.
There are two ways of communication in which the microprocessor can connect with
the outside world.
Serial Communication Interface
Parallel Communication interface
Serial Communication Interface − In this type of communication, the interface gets a
single byte of data from the microprocessor and sends it bit by bit to the other system
serially and vice-a-versa.
Parallel Communication Interface − In this type of communication, the interface gets
a byte of data from the microprocessor and sends it bit by bit to the other systems in
simultaneous (or) parallel fashion and vice-a-versa.
Instruction Cycle
The time required to fetch an instruction and necessary data from memory and
to execute it, is called an instruction cycle. Or the total time required to execute
an instruction is given by:
IC = FC + EC
Where,
IC = Instruction Cycle
FC = Fetch Cycle
EC = Execute Cycle
Timing Diagram for Instruction Cycle