8085 Instruction Set & Writing Assembly ProgramFile
8085 Instruction Set & Writing Assembly ProgramFile
Language Programming
ECE 3010 Microprocessor & Interfacing
Dr. Nu War
Professor
Faculty of Computer Systems and Technologies
Myanmar Institute of Information Technology
8085 Instruction Set
Instruction Types
Assembly Program
Instruction Set of 8085
8085 instructions can be classified as
1. Data Transfer (Copy)
2. Arithmetic
3. Logical and Bit manipulation
4. Branch
5. Machine Control
CMP C
Compare contents of Register C with Accumulator
CNC 3050H Call a subroutine with its 16-bit Address if Carry flag is RESET
Problem Statement:
To add two 8-bit numbers and store 8-bit result in register C
2. Program Logic
Add two numbers
Store result in register C
Example
10011001 (99H) A
+00111001 (39H) D
11010010 (D2H) C
Program 8085 in Assembly language
3. Algorithm
Load 1st no. in register D
Get two numbers
Load 2nd no. in register E
• Stop processing
Stop
5. Assembly Language Program
5. Assembly Language Program
Get two numbers
MVI D, 2H
1st
• Load no. in register D
• Load 2nd no. in register E
MVI E, 3H
Add them
• Copy register D to A MOV A, D
• Add register E to A ADD E
Store result
• Copy A to register C MOV C, A
Stop
• Stop processing HLT
8085 Program (Branch Operation)
Problem Statement:
To add two 8-bit numbers (store the whole resulting sum). Result can be
more than 8-bits.
1. Analyze the problem
Result of addition of two 8-bit numbers can be 9-bit
Example
10011001 (99H) A
+10011001 (99H) B
100110010 (132H)
The 9th bit in the result is called CARRY bit.
8085 Program (Branch Operation)
How 8085 does it?
Adds register A and B Store the result in register B & C
Stores 8-bit result in A Copy A to C
SETS carry flag (CY) to indicate carry bit
a) Clear register B
b) Increment B by 1
10011001 99H A
+ CY A
1 10011001 32H
10011001 99H B
0
1 10011001
00110010 32H
99H A Register B Register C
CY
8085 Program (Branch Operation)
2. Program Logic
Add two numbers
If CARRY is generated
Handle it
• Copy register D to A
Add them • Add register E to A
• Copy A to register C
Store 8 bit result in C
Copy A to C
Stop
8085 Program (Branch Operation)
Assembly Program
Load 1st no. in register D MVI D, 2H
Load 2nd no. in register E MVI E, 3H
• Copy register D to A MOV A, D
• Add register E to A ADD E
• Copy A to register C MOV C, A
JNC END
• Use Conditional Jump instructions
MVI B, 0H
• Clear register B
INR B
• Increment B
Direct addressing
Indirect addressing
Memory Addressing
Direct Addressing
16-bit Address of the memory location is specified in the
instruction directly
Examples-
LDA 2050H ;load A with contents of memory location with
address 2050H
STA 3050H ;store A with contents of memory location with
address 3050H
Memory Addressing
Indirect Addressing
A memory pointer register is used to store the address of the
memory location
Example-
MOV M, A ;copy register A to memory location whose
address is stored in register pair HL
H L
A 8AH 32H 45H 3245H 8AH
Addressing Mode
Input/Output Addressing
8-bit address of the port is directly specified in the
instruction
Examples-
IN 07H
OUT 21H
Example: 8085 Program
Problem Statement: Separate the digits of a hexadecimal numbers and
store it in two different locations
LXI H,200A
Address Data
MOV A,M
200A 23
INX H
200B 32
ADD M
200C 55
DAA
INX H
MOV M,A
RST 5
DAA-Decimal adjust accumulator
Problem -3 (16 bit numbers) A7CAH
Addition of two 16 bit numbers. +B96BH
(carry is neglected) 61 35H
A7CAH+B96BH=?
Address Data
LHLD 200CH
200C CA
XCHG
200D A7
LHLD 200EH
200E 6B
DAD D 200F B9
SHLD 2010H 2010 35
RST 5 2011 61
Problem -3 (16 bit numbers)
LHLD- Load H and L registers direct
Description:-
The instruction copies the contents of the memory
location pointed out by the 16bit address in register Land copie
s the contents of next memory location in register H.
LHLD 200C Address Data
200C CA
L=CA, H=A7
200D A7
LHLD 200E 200E 6B
L=6B, H=B9 200F B9
2010 35
2011 61
Problem -3 (16 bit numbers)
XCHG- Exchange H and L with D and E
L=CA, H=A7 H D
XCHG L E
E=CA, D=A7
Problem -3 (16 bit numbers)
DAD- Add register pair to H and L registers
HL
L=6B, H=B9 +DE
E=CA, D=A7 HL
DAD D
L=35, H=61
Problem -3 (16 bit numbers)
SHLD- Store H and L registers direct
Address Data
L=35, H=61
2010 35
SHLD 2010
2011 61
Problem -4
Addition of a 8 bit number series. 10H+02H+08H+04H=?
(neglecting carry generated)
LXI H,2100H
MOV B,M Address Data
XRA A 2100 04
LOOP: INX H 2101 10
ADD M 2102 02
DCR B 2103 08
JNZ LOOP 2104 04
STA 2110 …
RST 5 2110 1E
Problem -4
XRA - Exclusive or with accumulator
Description:-
The contents of the operand(register or memory) are
Exclusive ORed with the contents of the accumulator, and the
results are placed in the accumulator.
JNZ- Jump Conditionally
(Jump on No Zero Z =0)
B=4 non zero
Flag Register (8-bit)
B=0 zero
S Z AC P CY
Problem -5
Separation of hexadecimal number into two digits
LDA 2100
Address Data
ANI 0F
2100 AF
STA 2101
2101 0F
LDA 2100
2102 A0
ANI F0
STA 2102
RST 5
Problem -5
LDA - Load accumulator direct
Description:-
The contents of a memory location, specified by a
16- bit address in the operand, are copied to the
accumulator.
Description:-
The contents of the accumulator are logically ANDed
with the 8-bit data(operand) and the results are
placed in the accumulator.
Problem -6
Combination of two hex nibble to form one byte number
LXI H,2100
MOV A,M Address Data
RLC 2100 04
RLC
2101 05
RLC
RLC 2102 45
INX H
ORA M
INX H
MOV M,A
RST 5
Problem -6
RLC - Rotate accumulator left
Cy
D7 D6 D5 D4 D3 D2 D1 D0
Problem -7
Hex number stored in location for odd or even parity
LXI H,2100
MOV A,M
Address Data
ORA A 2100 10 - 01
JPO ODD
INR L 0 0 0 1 0 0 0 0
MVI M,00
RST 5
ODD: INR L Address Data
MVI M,01
2100 30 - 00
RST 5
0 0 1 1 0 0 0 0
Problem -8
Multiplication by two, employing bit rotation 1AH*2=?
0 0 1 1 0 0 0 0
Problem -8
STC - Set carry
Cy=1 Cy=0