UNIT 2 8085 - Instructions
UNIT 2 8085 - Instructions
COURSE HANDLED BY
opcode operand
Addressing Modes in Instructions
The process of specifying the data to be operated on by the instruction is called
addressing. The various formats for specifying operands are called addressing modes.
The 8085 has the following five types of addressing:
Immediate addressing
Indirect addressing
Implicit addressing
Addressing Modes
• The microprocessor has different ways of specifying the data for
the instruction. These are called “addressing modes”.
4 Indirect LDAX B
5 Implied CMA
Addressing Modes Contd.
Immediate Addressing:
In this mode, the operand given in the instruction - a byte or word – transfers to the destination
register or memory location.
Ex: MVI A, 9A H
The immediate data is part of the instruction.
The operand is stored in the register mentioned in the instruction.
Direct Addressing:
Memory direct addressing moves a byte or word between a memory location and register. The
memory address is given in the instruction.
This instruction is used to load the content of memory address 850FH in the accumulator.
Addressing Modes Contd.
Register Addressing:
Register direct addressing transfer a copy of a byte or word from source register to
destination register.
Ex: MOV B, C
Indirect Addressing:
Indirect addressing transfers a byte or word between a register and a memory location.
Ex: MOV A, M
Here the data is in the memory location pointed to by the contents of HL pair. The data is
Implicit Addressing
In this addressing mode the data itself specifies the data to be operated upon.
Ex: CMA
The instruction complements the content of the accumulator. No specific data or operand is
mentioned in the instruction.
Instruction Classification
Data Transfer
Arithmetic
Logical
Branching
MOV
MVI
LXI
LDA
LDAX
LHLD
STA
STAX
SHLD
XCHG
MOV
Memory
Memory
2050 2050
Memory Memory
2050 2050
MVI
Move immediate 8-bit into
R, Data a register
[R] <- Data
MVI
Move immediate 8-bit data
into the memory location
M, Data
pointed by the HL pair (M)
[[HL]] <- Data
Here, an 8-bit immediate data is stored in the destination register or a memory location,
which is pointed by the HL register pair.
Size of instruction
2 bytes
Addressing mode
Immediate
Flags affected
None
Example
MVI A, 57H
MVI M, 57H
LXI
Load the register pair with an immediate
value
LXI Rp, Data [rp] <- 16-bit data
8 MSBs in the upper register
8 LSBs in the lower register
This instruction loads a 16-bit immediate data in the memory location pointed
by the HL pair (M).
Size of instruction
3 bytes
Addressing mode
Immediate
LDA
Load Accumulator with contents stored at
LDA 16-bit address an address
[A] <- [[address]]
The contents from the address (addresses in 8085 are 16-bit) are copied to the
accumulator register. The contents of the source location remain unaltered.
Size of instruction
3 bytes
Addressing mode
Direct
Flags affected
None
Example
LDA 2034H //Contents stored at memory location 2034H are copied into the
accumulator.
STA
Store from the accumulator into a memory
16-bit address
STA location
value
[address] <- [A]
The contents of the accumulator register are copied into a memory location, which is
specified by the operand.
Size of instruction
3 bytes
Addressing mode
Direct
Flags affected
None
Example
STA 1000H
LDAX
Load accumulator with data at the memory
Either B/D location pointed by the contents of the
LDAX
Register Pair register pair.
[A] <- [[rp]]
The contents of the mentioned register pair point to a memory location. LDAX instruction
copies the contents of that particular memory location into the accumulator register.
Neither the contents of the register pair nor that of the memory location is altered.
Size of instruction
3 bytes
Addressing mode
Register Indirect
Flags affected
None
Example
LDAX B
LDAX D
STAX
Store contents of the accumulator into
STAX Register pair other register pair
[[RP]] <- [A]
The contents of the accumulator register are copied into the memory specified by the
register pair in the operand.
Size of instruction
1 byte
Addressing mode
Indirect
Flags affected
None
Example
STAX B
STAX D
LHLD
Load the H-L registers with contents
location at memory locations given by the
LHLD 16-bit address address value
[L] <- [[address]]
[H] <- [[address+1]]
The LHLD instruction copies the contents of a specified memory location pointed out by a
16-bit address into register L. The contents of the next memory location are copied into
register H.
Size of instruction
3 bytes
Addressing mode
LHLD Memory
Flags affected
None
Example
LHLD 2100H
SHLD
Stores from the H-L registers into the
specified location
SHLD 16-bit address
[address] <- [L]
[address+1] <- [H]
The first 8-bit contents of the register L is stored into the memory location specified by the
16-bit address. The next 8-bit contents of the register H are stored into the subsequent
memory location.
Size of instruction
3 bytes
Addressing mode
Direct
Flags affected
None
Example
SHLD 1200H
• LXI B,2105
• LHLD 9206
• MOV B,C
• MOV A,M
• STA 9206
• STAX D
• XCHG
XCHG
Exchange H-L with D-E
XCHG None
[HL] <-> [DE]
The contents of register pair H-L are exchanged with the contents of the register-pair D-E.
The information stored in register H is exchanged with that of D; similarly, that in register L
is exchanged with the contents of the register E.
Size of instruction
1 byte
Addressing mode
Implicit
Flags affected
None
Example
XCHG
.
ARITHMATIC INSTRUCTIONS
• These instructions perform the
operations like:
◦ Addition
◦ Subtract
◦ Increment
◦ Decrement
• These instructions perform arithmetic operations such as addition, subtraction,
increment, and decrement.
• Addition - Any 8-bit number, or the contents of a register or the contents of a
memory location can be added to the contents of the accumulator and the sum
is stored in the accumulator. No two other 8-bit registers can be added directly
(e.g., the contents of register B cannot be added directly to the contents of the
register C). The instruction DAD is an exception; it adds 16-bit data directly in
register pairs.
• Subtraction - Any 8-bit number, or the contents of a register, or the contents of a
memory location can be subtracted from the contents of the accumulator and
the results stored in the accumulator. The subtraction is performed in 2's
compliment, and the results if negative, are expressed in 2's complement. No
two other registers can be subtracted directly.
• Increment/Decrement - The 8-bit contents of a register or a memory location can
be incremented or decrement by 1. Similarly, the 16-bit contents of a register
pair (such as BC) can be incremented or decrement by 1.
ADD
Opcode Operand Description
ADD R M Add register or memory to
accumulator
The contents of register or memory are added to the
contents of accumulator.
2050
2050
ADC
ADC M
ADI
Opcode Operand Description
ADI 8-bit data Add immediate to
accumulator
Example: ADI 45 H
ADI DATA
ACI
Opcode Operand Description
ACI 8-bit data Add immediate to
accumulator with carry
The 8-bit data and the Carry Flag (CY) are added to
the contents of accumulator.
AND
OR
XOR
Rotate
Compare
Complement
AND, OR, XOR
CY is reset, AC is set.
Greater Than
Less Than
Example: RLC.
Opcod Operan Description
e d
RRC None Rotate accumulator right
Example: RRC.
Opcod Operan Description
e d
RAL None Rotate accumulator left
through carry
Example: RAL.
Opcod Operan Description
e d
RAR None Rotate accumulator right
through carry
Each binary bit of the accumulator is rotated right by one
position through the Carry flag.
Bit D0 is placed in the Carry flag, and the Carry flag is placed
in the most significant position D7.
Example: RAR.
Opcode Operand Description
• Example: JZ 2034 H.
Jump Conditionally
JC Jump if Carry CY = 1
CC Call if Carry CY = 1
CNC Call if No Carry CY = 0
CP Call if Positive S=0
CM Call if Minus S=1
CZ Call if Zero Z=1
CNZ Call if No Zero Z=0
CPE Call if Parity Even P=1
CPO Call if Parity Odd P=0
Opcod Operan Description
e d
RET None Return unconditionally
• The two bytes from the top of the stack are copied into the
program counter, and program execution begins at the new
address.
• Example: RET.
Return Conditionally
SPHL Non
e
Example: SPHL
BEFORE
EXECUTION
SP
H 25 L 00
SPHL
AFTER EXECUTION
SP 2500
H 25 00
L
XTHL-Exchange H and L with top of
stack
Opcode Operand
XTHL None
Example: XTHL
L=(SP
)
H=(SP
BEFORE +1) AFTER
EXECUTION EXECUTION
SP 2700
270 50 SP 2700
40
270
H 30 L 40 0H H 60 L 50
0H
270 60 30
270
1H
1H
XT
270
2H HL 270
2H
Opcod Operan Description
e d
PCHL None Load program counter
with H- L contents
The contents of registers H and L are copied into the
program counter (PC).
Example: PCHL
PUSH-Push register pair onto stack
Opcode Operand
PUSH Reg. pair
Example: PUSH B
PUSH H
POP- Pop stack to register pair
Opcode Operand
POP Reg. pair
Example: IN 8C H
BEFORE
EXECUTION
POR 10 A
T
80H
IN
80H
AFTER
EXECUTION
POR 10 A
T
10
OUT- Copy data from accumulator to a
port with 8-bit address
Opcode
OUTOperand 8-bit port address
OUT
50H
AFTER
EXECUTION
POR 40 A 40
T
Opcod Operan Description
e d
NOP None No operation
Example: NOP
Opcod Operan Description
e d
HLT None Halt
Example: DI
Opcod Operan Description
e d
EI None Enable interrupt
Example: SIM
SIM
Instruction
Multi Byte Addition Algorithm
1. Clear the carry flag
2. Initialize one register (Reg C) with the length of the data
3. Initialize one register pair (HL) with the starting address of the first
data
4. Initialize one register pair (DE) with the starting address of the
second data
5. Move the content of DE to accumulator
6. Add the contents of DE and memory with carry
7. Move the accumulator content to memory
8. Increment HL and DE pairs
9. Decrement the counter register (Reg C)
10. Check for zero, if not zero, go to step 5
11. Stop
Multi byte Addition
STC cy=1
CMC cy=0
LDA 9100 9100= length of the data =4
MOV C, A c=4
LXI H, 9200 HL=9200
LXI D, 9300 DE=9300
L1: LDAX D A=(9301)
ADC M A= A+(M)+CY
MOV M, A
INX D DE=9304
INX H HL= 9204
DCR C C=0 02030805
JNZ L1 0104121A
HLT
Largest value in an array
1. Initialize one register pair (HL) with the starting address of the array
2. Initialize one register (Reg B) with one count less than the length of
the array
3. Move the memory content to accumulator
4. Increment HL pair
5. Compare the contents of accumulator and memory
6. Check for carry, if no carry, go to step 8
7. Move the memory content to accumulator
8. Decrement Reg B
9. Check for zero, if not zero, go to step 4
10. Store the accumulator content in a memory location
11. Stop
Largest value in an array
LXIH, 9100
MVI B, 07
MOV A, M
L2 :INX H
CMP M
JNC L1
MOV A, M
L1 :DCR B
JNZ L2
STA 9200
RST 1