Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
52 views

8085 Instruction Set & Writing Assembly ProgramFile

This document provides an introduction to 8085 assembly language programming. It discusses the different types of 8085 instructions including data transfer, arithmetic, logical, branching, and machine control instructions. It also describes the process of writing an assembly language program, including analyzing the problem, developing logic and an algorithm, creating a flowchart, and writing the program instructions. Examples of 8085 programs that add two numbers and perform block data transfers are also provided. The addressing modes and instruction format of the 8085 processor are explained.

Uploaded by

Kaseya Takahashi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
52 views

8085 Instruction Set & Writing Assembly ProgramFile

This document provides an introduction to 8085 assembly language programming. It discusses the different types of 8085 instructions including data transfer, arithmetic, logical, branching, and machine control instructions. It also describes the process of writing an assembly language program, including analyzing the problem, developing logic and an algorithm, creating a flowchart, and writing the program instructions. Examples of 8085 programs that add two numbers and perform block data transfers are also provided. The addressing modes and instruction format of the 8085 processor are explained.

Uploaded by

Kaseya Takahashi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Introduction to 8085 Assembly

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

 74 operation codes, e.g. MOV


 246 Instructions, e.g. MOV A,B
Data Transfer (Copy) Operations / Instructions

MVI B, 2AH Load a 8-bit number 2A in register B

MOV C,B Copy from Register B to Register C

LXI H, 4050H Load a 16-bit number 4050 in Register pair HL

MOV M,B Copy from Register B to Memory Address 2050

OUT 02H Copy between Input/Output Port and Accumulator


IN 0FH
Arithmetic Operations/ Instructions

ADI 82H Add a 8-bit number 82H to Accumulator

ADD C Add contents of Register C to Accumulator

SUI A2H Subtract a 8-bit number A2H from Accumulator

SUB B Subtract contents of Register B from Accumulator

INR D Increment the contents of Register D by 1

DCR E Decrement the contents of Register E by 1


Logical & Bit Manipulation Operations / Instructions

ANA H Logically AND Register H with Accumulator

ORA L Logically OR Register L with Accumulator

XRA B Logically XOR Register B with Accumulator

CMP C
Compare contents of Register C with Accumulator

CMA Complement Accumulator

RAL Rotate Accumulator Left


Branching Operations / Instructions

JC 2080H Jump to a 16-bit Address 2080H if Carry flag is SET

JMP 2050H Unconditional Jump

CALL 3050H Call a subroutine with its 16-bit Address

RET Return back from the Call

CNC 3050H Call a subroutine with its 16-bit Address if Carry flag is RESET

RZ Return if Zero flag is SET


Machine Control Instructions

HLT Stop program execution

NOP Do not perform any operation


Writing Assembly Program
Logic
Flowchart
Assembly Program
Writing a Assembly Language Program

Steps to write a program


1. Analyze the problem
2. Develop program Logic
3. Write an Algorithm
4. Make a Flowchart
5. Write program Instructions using Assembly language of 8085
Program 8085 in Assembly language

Problem Statement:
To add two 8-bit numbers and store 8-bit result in register C

1. Analyze the problem


 Addition of two 8-bit numbers to be done

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

 Add them • Copy register D to A


• Add register E to A
 Store result
• Copy A to register C

 Stop • Stop processing

Translation to 8085 operations


Program 8085 in Assembly language
4. Flowchart
Start
• Load 1st no. in register D
Load Registers D, E • Load 2nd no. in register E

Copy D to A • Copy register D to A


• Add register E to A
Add A and E

Copy A to C • Copy A to register C

• 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

 Copy 8-bit result in A to C

 If CARRY is generated
 Handle it

 Result is in register pair BC


8085 Program (Branch Operation)
Translation to 8085 operations
3. Algorithm  Load 1st no. in register D
 Get two numbers  Load 2nd no. in register E

• Copy register D to A
 Add them • Add register E to A

• Copy A to register C
 Store 8 bit result in C

 Check CARRY flag • Use Conditional Jump instructions


 If CARRY flag is SET • Clear register B
 Store CARRY in register B • Increment B
 Stop • Stop processing
8085 Program (Branch Operation)
Flowchart
Start

Load Registers D, E If False


CARRY Clear B
NOT SET
Copy D to A
Increment B
True
Add A and E

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

• Stop processing END: HLT


Example: Block data transfer
 MVI C, 0AH ; Initialize counter i.e no. of bytes
Store the count in Register C, ie ten
 LXI H, 2200H ; Initialize source memory pointer
Data Starts from 2200 location
 LXI D, 2300H ; Initialize destination memory pointer

 BK: MOV A, M ; Get byte from source memory block


i.e 2200 to accumulator.

 STAX D ; Store byte in the destination memory block


i.e 2300 as stored in D-E pair
Example: Block data transfer

 INX H ; Increment source memory pointer

 INX D ; Increment destination memory pointer

 DCR C ; Decrement counter to keep track of bytes moved

 JNZ BK ; If counter 0 repeat steps

 HLT ; Terminate program


8085 Instruction Format
Format of a typical Assembly language instruction
[Label:] Mnemonic [Operands] [;comments]
HLT
MVI A, 20H
MOV M, A ;Copy A to memory location whose address is
stored in register pair HL
LOAD: LDA 2050H ;Load A with contents of memory location with
address 2050H
READ: IN 07H ;Read data from Input port with address 07H
Addressing Modes of 8085
 The various formats of specifying operands are called
addressing modes
 Addressing modes of 8085
1. Register Addressing
2. Immediate Addressing
3. Memory Addressing
4. Input/Output Addressing
Addressing Modes

Register Addressing Immediate Addressing


 Value of the operand is given in
Operands are one of the internal the instruction itself
registers of 8085
Example-
Examples- MVI A, 20H
MOV A, B LXI H, 2050H
ADD C ADI 30H
SUI 10H
Addressing Modes
Memory Addressing

 One of the operands is a memory location


 Depending on how address of memory location is specified,
memory addressing is of two types

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

 LDA 2200H ; Get the packed BCD number


 ANI F0H ; Mask lower nibble
0100 0101 45
1111 0000 F0
---------------
0100 0000 40
 RRC
 RRC
 RRC ; Adjust higher digit as a lower digit.
 RRC 0000 0100 after 4 rotations
Example: 8085 Program

 STA 2300H ; Store the partial result


 LDA 2200H ; Get the original BCD no.
 ANI 0FH ; Mask higher nibble
0100 0100 45
0000 1111 0F
---------------
0000 0101 05
 STA 2301H ; Store the result
 HLT ; Terminate program execution
Problem -1
Hexadecimal addition of two numbers
Problem -1
Hexadecimal addition of two numbers
02H+03H=? Address opcode
3FFF xx
Address Opcode Instruction
4000 3E 01
4000 3E 01 MVI A,01
4002 06 02 MVI B,02
4002 06 02
4004 80 ADD B 4004 80
4005 32 00 21 STA 2100H 4005 32 00 21
4008 EF RST5 4008 EF
…….
4100 03
Example Address opcode
2000 21 09 20
Address Opcode Instruction
2003 7E
2000 21 09 20 LXI H,2009
2004 23
2003 7E MOV A,M
2005 86
2004 23 INX H 2006 23
2005 86 ADD M 2007 77
2006 23 INX H
2008 EF
2007 77 MOV M,A
2009 01
2008 EF RST 5 200A 02
200B --
Problem -2 DAA-Decimal adjust accumulator
Decimal addition of two decimal numbers 23D+32D=?

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

Description:-The contents of register H are exchanged with the


contents of register D, and the contents of register L are
exchanged with the contents of register 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

Description:-The 16-bit contents of the specified register pair


are added to the contents of the HL register and the sum is
saved in the HL register and the sum is saved in the HL register.

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

Description:- The contents of register L are stored in the memory


location specified by the 16-bit address in the operand and the
contents of H register are stored in the next memory location by
location by incrementing the operand.

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.

ANI- and immediate with 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

Description:- Each binary bit of the accumulator is rotated left by


one position. Bit D7 is placed in the position of D0 as well as in
the Carry flag.

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=?

LDA 210AH Address Data


STC 210A 1A
CMC 210B 34
RAL
STA 210BH
RST 5 Address Data
2100 30 - 00

0 0 1 1 0 0 0 0
Problem -8
STC - Set carry

Description:- The carry flag is set to 1.


Cy=1

CMC – Complement carry


 Description:- The carry flag is complemented.

Cy=0 Cy=01

Cy=1 Cy=0

You might also like