8085 Microcontroller Addressing Modes
8085 Microcontroller Addressing Modes
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Topics Covered
Addressing Modes
• Implied Addressing
• Immediate Addressing
• Direct Addressing
• Register Indirect Addressing
• Register Addressing
Instruction Set of 8085
• Data Transfer Instructions
• Arithmetic Instructions
• Logical Instructions
• Branch Instructions
• Machine Control Instructions
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
1
1/29/2025
Addressing Modes
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Addressing Modes
The microprocessor has different ways of specifying the data
for the instruction. These are called “addressing modes”.
Addressing modes of 8085:
• Implied Addressing
• Immediate Addressing
• Direct Addressing
• Register Indirect Addressing
• Register Addressing
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
2
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
3
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
4
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
5
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
The Operand M
What is M in the following instructions?
• MOV A, M
• ADD M
• INR M
The location stored in H-L pair is represented by M.
Registers Memory
A 65 F …..
B C 2020 33
D E 2021 65
H 20 L 21 …..
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
6
1/29/2025
Size of an Instruction
How to identify the size of an instruction?
• MOV B, C • What will be size of this instruction?
• MVI B, 20H • An opcode MOVE B, C1-Byte
• LXI B, 3050H
• What will be size of this instruction?
• 2-Byte, how?
• 1st byte MVI B an opcode
• 2nd byte 8-bit immediate data
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Size of an Instruction
How to identify the size of an instruction?
• MOV B, C • What will be size of this instruction?
• MVI B, 20H • 3-Byte, how?
• LXI B, 3050H • 1st byte LXI B an opcode
• 2nd byte 30H
• 3rd byte 50H
• Can we make an opcode for
immediate value or address?
• No all opcode will be utilized by
a single instruction.
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
7
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
8
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Whatever LXI is doing can be done by writing MVI two times i.e.
MVI B, 30H; MVI C 50H. Why it is not a good choice?
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
9
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
10
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
11
The contents of the memory address specified by the 16-bit address are
loaded into the H register.
The contents of the next consecutive memory address (address + 1) are
loaded into the L register. it is for LHLD 1/29/2025
SHLD 16-bit-Addr : Store the content of H-L pair to the given 16-
bit address and its consecutive address.
: SHLD 2050
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
12
1/29/2025
Registers
A F
B C
D E
W 12 H 12 L 34 Z 34
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Arithmetic Instructions
ADD Rs : Add the value of Rs to accumulator and store
the result in accumulator.
: ADD B; A A+B
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
13
1/29/2025
Arithmetic Instructions
SUB Rs : Subtract the value of Rs from A.
: SUB B; A A-B
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Arithmetic Instructions
ADC Rs : ADD with carry.
: ADC B; A A+B+CF
12 FF ADD
00 01
13 00 ADC
ADC M : A A+[M]+CF
ACI 20H : A A+25H+C
SBB Rs : SBB B; A A-B-CF
SBB M : A A-[M]-CF
SBI 30H : A A-30H-CF
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
14
1/29/2025
Arithmetic Instructions
INR Rd : Increment Rd.
: B B+1
: What if B = FF?
INR M : Increment M.
DCR Rd : Decrement register Rd.
DCX Rp : Decrement register pair.
DCR M : Decrement M.
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Arithmetic Instructions
• DAD Rp : double addition, (operand register pair)
: As it is a 16-bit addition, HL pair is used.
: HL HL + DE
: Multiply a 16 bit number by DAD H
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
15
1/29/2025
Arithmetic Instructions
DAA : Decimal adjust after addition.
: Important for the applications like calculator.
: The only instruction which works same for all
processors (even in modern processors).
24 H 20 H 25 H
25 H 30 H 25 H
49 H 50 H 4A H
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Arithmetic Instructions
How to Adjust : Lower Nibble (LN) and Higher Nibble (HN)
of Accumulator.
: If LN>9 or AC = 1; A A + 06
25 H 26 H 28 H
25 H 26 H 28 H
25 H 26 H 28 H
25 H 26 H 28 H
4A H 4C H 50 H
4A H 4C H 50 H
06 H 06 H 06 H
Adjustment 50 H Adjustmen 52 H Adjustment 56 H
Required t Required Required
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
16
1/29/2025
Arithmetic Instructions
How to Adjust : If HN>9 or C = 1; A A + 60 {equivalent
to adding 6 in higher nibble}
50 H 60 H 99 H
50 H 60 H 99 H
50 H 60 H 99 H
50 H 60 H 99 H
A0 H C0 H 32 H
A0 H C0 H 132 H
60 H 60 H 06 H
100 120 H Adjustment 38 H
Adjustmen Adjustment
t Required Required Required
99 H
99 H
32 H
06 H
38 H
60 H
198
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Logic Instructions
ANA Rs : ANA B; A A∧B
ANA M : A A ∧ [M]
ANI 8-bit-data : ANI 25H; A A∧25H
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
17
1/29/2025
Logic Instructions
AND (∧) : AND anything with 0 0 00 0
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Logic Instructions
00 0
OR (∨) : OR anything with 0 No Change
01 1
: OR anything with 1 1
10 1
11 1
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
18
1/29/2025
Logic Instructions
XOR (∨) : XOR anything with 0 No Change 00 0
: XOR anything with 1 Complement 01 1
10 1
11 0
Complement LN?
A(35) 0 0 1 1 0 1 0 1
XRI 0FH 00001111
00111010
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Logic Instructions
CMP Rs : Comparison is done by subtraction
: CMP B; calculate A-B, but do not store the result
check the carry flag.
[A-B]
CF ZF
A>B 0 0
A=B 0 1
A<B 1 0
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
19
1/29/2025
Logic Instructions
We have AND, OR, EXOR, NOT
What if we are asked to implement functionality of, NOR and
XNOR?
• NAND = AND NOT
• NOR = OR NOT
• XNOR = XOR NOT
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Logic Instructions
RLC : Rotate Left with carry
CF MSB LSB
MSB LSB CF
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
20
1/29/2025
Logic Instructions
RAL : Rotate Arithmetic Left
CF MSB LSB
MSB LSB CF
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Logic Instructions
O/P of these operation?
• RLC, RRC:
• Value of LSB and MSB, we will lose carry with this instructions
• RAL, RAR:
• Value of LSB and MSB, without loosing value of CF.
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
21
1/29/2025
Logic Instructions
Applications of RLC, RRC, RAL, RAR:
• In the series of numbers find out the even and odd numbers
• LSB 0, Even
• LSB 1, Odd
• Find out if the number is positive or negative?
• MSB 0, Positive
• MSB 1, Negative
• Count number of 1’s in the value stored in a register?
• Rotate Left 8 time, and check for the value of CF.
• Swap nibbles
• Rotate 4 times
• Check value of specific bit?
• Rotate required number of times
• Multiply and divide a number by 2?
• Rotate Left Multiply by 2.
• Rotate Right Divide by 2.
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Branch Instructions
Set of instructions that changes the order in which a
microprocessor executes instructions.
• Conditional: Continually taken
• Unconditional: Conditional branch instructions are dependent on flags.
• Sub-Routine: used for function call.
All Applications conditional loop, unconditional loop, infinite
loop, call, etc.
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
22
1/29/2025
Branch Instructions
JMP 16-bit-Addr : Jump to the given address unconditionally.
Memory
Microprocessor
…… …….
PC 1000 MVI B 05
1001 JMP 2000
….. ……
2000 ABC
2001 XYZ
….. …..
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Branch Instructions
JMP 16-bit-Addr : Jump to the given address unconditionally.
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
23
1/29/2025
Branch Instructions
How actually PC gets new address?
• Can we jump to location 2000 just after fetching JMP?
• Assume PC 1000, and the next instruction of the program is JMP 2000H.
• As JMP 2000H is a 3-byte instruction it will be stored at locations 1000,
1001 and 1002.
Memory
…… …….
PC 1000 JMP
1001 00
1002 20
1003 …..
….. …..
2000 ABC
2001 XYZ
….. …..
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Branch Instructions
How actually PC gets new address?
• Assume PC 1000, and the next instruction of the program is JMP 2000H.
• As JMP 2000H is a 3-byte instruction it will be stored at locations 1000,
1001 and 1002.
• Can we jump to location 2000 just after fetching JMP?
24
1/29/2025
Branch Instructions
How actually PC gets new address?
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Branch Instructions
JC : Jump if CF = 1
JNC : Jump if CF = 0
JZ : Jump if ZF = 1
JNZ : Jump if ZF = 0
JPE : Jump if P = 1
JPO : Jump if P = 0
JM : Jump if SF = 1
JP : Jump if SF = 0
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
25
1/29/2025
Branch Instructions
Infinite Loops
• Digital Watch, Internet Routers, Embedded Systems,
BACK 1000
Loop Loop
Body Body
….. …..
….. ….
JMP 1000
JMP BACK
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Branch Instructions
Finite Loop
• Execute loop for specific # of times.
• Sorting, searching, simulations
MVI C 05H
1000 1000
Loop Loop
Body Body
. …..
Exitcond DCR C
JUMP BACK JNZ 1000
Next Instr. Next Instr.
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
26
1/29/2025
Branch Instructions
Finite Loops: Important Points
• Instr. JZN will check value of register C or flag?
• It will check Zero flag.
• Max value which can be assigned to any register?
• We can assign 00H to FF H Max value 255 in decimal.
• What if we want to run code for 256 iterations?
• Assign C 00
• DCR will make it FF (1 iteration)
• Now FF to 00 (255 iterations)
• Can we have some Instr. between DCR C and JNZ 1000?
• No, because each instruction can impact flag values.
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Branch Operations
Call & Return : For execution of sub-routine (function).
: PC should get its old value after completion
of sub-routine.
: i.e. Camera WhatsApp, Instagram.
FUN-01
Sub-
Call FUN-01 Routine
Next Instr.
RETURN
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
27
1/29/2025
Branch Operations
Call 2000 1 CALL is also a 3-byte instruction, thus
3 PC will fetch 3-byte data byte by byte,
temporary registers Z and Z will get
Memory
00H and 20H. The PC is pointing at
location 1003. As we have to return to
…… …….
location 1003 we cannot update PC
PC 1000 CALL value at this moment otherwise we will
1 1001 00 Z 00 lost the location hold by PC.
1002 20 W 20
2 And thus, PC value will be pushed to
1003 ….
stack. To PUSH the PC value in stack
….. ….. we have to decrement the SP value two
times, SP-1 10, and SP-203
2 Stack
…… ……. 3 After pushing the PC value to stack PC
SP-2 03 will be updated with the value hold by
temporary registers Z and W and the
SP-1 10
microprocessor will start execution of
SP XYZ the instructions written in sub-routine.
…. ….
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Branch Operations
Call 2000
Memory 4 Once the execution of sub-routine is
…… …….
finished the stack will be popped and
the popped value will be assigned to
PC 1000 CALL
PC such that PC can point to its old
1001 00 location 1003 again.
1002 20
1003 ….
….. …..
4 Stack
…… …….
SP-2 03
SP-1 10
SP XYZ
…. ….
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
28
1/29/2025
Branch Instructions
Call & Return: Important Points
• Can we assign an address to RETURN?
• Code for pushing PC Stack (PUSH)
• Code for storing Stack value to PC (POP)
PUSH POP
SP SP – 1 PCL [SP]
[SP] PCH SP SP+1
SP SP – 1 PCH [SP]
[SP] PCL SP SP+1
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Branch Operations
Least used instructions
CALL RETURN
CC : Call if CF = 1 RC : Return if CF = 1
CNC : Call if CF = 0 RNC : Return if CF = 0
CZ : Call if ZF = 1 RZ : Return if ZF = 1
CNZ : Call if ZF = 0 RNZ : Return if ZF = 0
CPE : Call if P = 1 RPE : Return if P = 1
CPO : Call if P = 0 RPO : Return if P = 0
CM : Call if SF = 1 RM : Return if SF = 1
CP : Call if SF = 0 RP : Return if SF = 0
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
29
1/29/2025
Branch Operations
RSTn : Used to call standard sub-routines.
: Call (nx8; where n=0, 1, 2,…,7)
: 1-byte instruction
: RST0 is equivalent to CALL 0000H
: RST 1 0008
: RST 2 0010
: RST 3 0018
: RST 4 0020
: RST 5 0028
: RST 6 0030
: RST 7 0038
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
30
1/29/2025
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
Dr. Dev Narayan Yadav Department of CSE, National Institute of Technology Rourkela
31