Assembly Language Programming of 8085: Philippine College of Science & Technology
Assembly Language Programming of 8085: Philippine College of Science & Technology
Assembly Language
Programming of 8085
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
Topics
1. Introduction
2. Programming model of 8085
3. Instruction set of 8085
4. Example Programs
5. Addressing modes of 8085
6. Instruction & Data Formats of 8085
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
1. Introduction
• A microprocessor executes instructions given by
the user
• Instructions should be in a language known to
the microprocessor
• Microprocessor understands the language of 0’s
and 1’s only
• This language is called Machine Language
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
• For e.g.
01001111
– Is a valid machine language instruction of
8085
– It copies the contents of one of the internal
registers of 8085 to another
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
Low-level/High-level languages
• Machine language and Assembly language are
both
– Microprocessor specific (Machine dependent)
so they are called
– Low-level languages
• Machine independent languages are called
– High-level languages
– For e.g. BASIC, PASCAL,C++,C,JAVA, etc.
– A software called Compiler is required to
convert a high-level language program to
machine code
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
ALU
Memory Pointer
Registers 8-bit Data
Flags Bus
Instruction
Decoder
Control Bus
Timing and Control Unit
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
B (8-bit) C (8-bit)
D (8-bit) E (8-bit)
H (8-bit) L (8-bit)
Stack Pointer (SP) (16-bit)
Program Counter (PC) (16-bit)
3. Flag
Register
– This is also a part of ALU
– 8085 has five flags named
• Zero flag (Z)
• Carry flag (CY)
• Sign flag (S)
• Parity flag (P)
• Auxiliary Carry flag (AC)
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
5. Stack Pointer
Register
– a 16-bit memory pointer register
– Points to a location in Stack memory
– Beginning of the stack is defined by loading
a 16-bit address in stack pointer register
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
2. Arithmetic Operations
1. Addition of two 8-bit numbers
2. Subtraction of two 8-bit numbers
3. Increment/ Decrement a 8-bit number
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
Example Arithmetic
Operations/Instructions
1. Add a 8-bit number 32H to ADI 32H
Accumulator
2. Add contents of Register B to ADD B
Accumulator
3. Subtract a 8-bit number 32H SUI 32H
from Accumulator
4. Subtract contents of Register SUB C
C from Accumulator
5. Increment the contents of INR D
Register D by 1
6. Decrement the contents of DCR E
Register E by 1
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
4. Branching Operations
These operations are used to control the flow
of program execution
1.Jumps
• Conditional jumps
• Unconditional jumps
2.Call & Return
• Conditional Call & Return
• Unconditional Call & Return
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
Example Branching
Operations/Instructions
1. Jump to a 16-bit Address JC 2080H
2080H if Carry flag is SET
2. Unconditional Jump JMP 2050H
3. Call a subroutine with its 16-bit CALL 3050H
Address
4. Return back from the Call RET
5. Call a subroutine with its 16-bit CNC 3050H
Address if Carry flag is RESET
6. Return if Zero flag is SET RZ
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
Translation to 8085
3. Algorithm operations
1. Get two numbers • Load 1st no. in register D
• Load 2nd no. in register E
2. Add them • Copy register D to A
• Add register E to A
3. Store result • Copy A to register C
4. Make a Flowchart
Start
• Load 1st no. in register D
Load Registers D, E • Load 2nd no. in register E
• Stop processing
Stop
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
1
0 00110010
10011001 32H
99 A
H
CY
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
Register B Register C
Step-1 Copy A to C
Step-2
a) Clear register B
b) Increment B by 1
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
2. Program Logic
1. Add two numbers
2. Copy 8-bit result in A to C
3. If CARRY is generated
– Handle it
4. Result is in register pair BC
3. Algorithm Translation to 8085
operations
1. Load two numbers in • Load registers D, E
registers D, E
• Copy register D to A
2. Add them
• Add register E to A
• Copy A to
to register
registerCC
3. Store 8 bit result in C
4. Check CARRY flag • Use Conditional
5. If CARRY flag is SET Jump instructions
• Store CARRY in • Clear register B
register B • Increment B
6. Stop • Stop processing
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
4. Make a Flowchart
Start
Copy A to C
Stop
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
1. Register Addressing
• Operands are one of the internal registers
of 8085
• Examples-
MOV A, B
ADD C
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
2. Immediate Addressing
• Value of the operand is given in the
instruction itself
• Example-
MVI A, 20H
LXI H, 2050H
ADI 30H
SUI 10H
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
3. 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
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
H L
A 30H 20H 50H 2050H 30H
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
4. Input/Output Addressing
• 8-bit address of the port is directly
specified in the instruction
• Examples-
IN 07H
OUT 21H
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
1. One-byte Instructions
• Includes Opcode and Operand in the same byte
• Examples-
Opcode Operand Binary Code Hex Code
MOV C, A 0100 1111 4FH
ADD B 1000 0000 80H
HLT 0111 0110 76H
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
1. Two-byte Instructions
• First byte specifies Operation Code
• Second byte specifies Operand
• Examples-
Opcode Operand Binary Code Hex Code
MVI A, 32H 0011 1110 3EH
0011 0010 32H
MVI B, F2H 0000 0110 06H
1111 0010 F2H
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
1. Three-byte Instructions
• First byte specifies Operation Code
• Second & Third byte specifies Operand
• Examples-
Opcode Operand Binary Code Hex Code
LXI H, 2050H 0010 0001 21H
0101 0000 50H
0010 0000 20H
LDA 3070H 0011 1010 3AH
0111 0000 70H
0011 0000 30H
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
0100 0000 40
• RRC
• RRC
• RRC ; Adjust higher digit as a lower digit.
• RRC 0000 0100 after 4 rotations
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
Contd.
• 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 0100 05
• STA 2301H ; Store the result
• HLT ; Terminate program execution
PhilCST
PHILIPPINE COLLEGE OF SCIENCE & TECHNOLOGY
OLD NALSIAN ROAD, BRGY. NALSIAN, CALASIAO, PANGASINAN
Contd.
• 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