8085 microprocessor programming | 8085 instruction set

This page of 8085 microprocessor tutorial describes 8085 microprocessor programming.It also mentions 8085 instruction set.It covers 8085 addressing modes viz. Immediate addressing,Register addressing,Direct addressing,Indirect addressing. Instructions of various types 1-byte,2-byte and 3-byte are explained.Example assembly programs are also mentioned.

Refer 8085 microprocessor internal architecture➤ before understanding 8085 programming mentioned on this page.

Control Unit: It generates signals within the microprocessor unit to carry out instruction which has been decoded. It takes care of data movement as required so that ALU operations can be performed.

ALU Unit: It takes care of numerical and logical operations such as ADD, Substract, AND, OR etc. It utilizes data stored in memory, registers and Accumulator to perform arithmetic operations. The final result is stored in the Accumulator.

Registers: There are 6 important general purpose registers to store 8 bit of data. These are named as B,C,D,E,H,L. These can be combined into BC, DE and HL to store 16 bits of data. The other important registers are Accumulator, PC (Program Counter), SP(Stack Pointer), one flag register. Assembly programmer can store the data in these registers using data copy instruction types.

8085 programming

Figure-1 depicts these registers. As mentioned Accumulator is a 8 bit register and it is used to store the data and perform mathematical operations and finally result is also stored in the accumulator. It is designated as 'A'.

ALU includes five flipflops dedicated to use as flags. These are set or reset based on certain conditions during mathematical operations. The flags are denoted as S (Sign), Z (Zero), AC(Auxiliary Carry), P(Parity) and CY (Carry) from MSB positions as shown in the figure.
EXAMPLE: After two numbers are added and if the sum is larger than 8 bits to be accomodated in the accumulator then it is indicated by setting the CY flag to value '1'. Like wise each of the flags have significance in 8085 processor.

8085 programming item Description
Registers These are 8 bit general purpose registers such as B,C,D,E,H,L as mentioned.
Accumulator It is a 8 bit register used to store the result as well as intermediate operations of the mathematical operation.
Flags These are five flags , set and reset according to certain arithmetic and logical conditions.
Program Counter(PC) It is 16 bit in size. The microprocessor uses this register to sequence the executions of the instructions. It is also used as memory pointer. It holds memory address from where next byte is to be fetched. It basically points to the assembly codes stored in the form of opcodes. When a byte is fetched , PC is incremented by 1 to point to the next memory location.
Stack Pointer (SP) It is 16 bit in size. It points to the memory location in R/W memory known as stack. The beginning of stack is defined by loading 16 bit address in the SP.

8085 Addressing Modes

• Immediate Addressing: Load the immediate data to the destination. Data is specified in the instruction itself. EXAMPLE: MVI R, Data

• Register Addressing: Data is stored first in the registers and operations are performed by using registers in the instructions. EXAMPLE: MOV Rd, Rs
Here Rd is the destination register and Rs is the source register.

• Direct Addressing: It is used to accept the data from outside devices to store in the Accumulator. (EXAMPLE: IN 00H )
It is also used to send data stored in the Accumulator to the outside device. (EXAMPLE: OUT 01H)

• Indirect Addressing: Here effective address is calculated by the microprocessor. This type os addressing requires several accesses to retrieve the data which is to be loaded into the register.



Instruction Set Classification

Instruction is a binary pattern designated inside microprocessor to perform specific function. The entire group of instructions are known as "Instruction Set".

The 8085 instructions are classified into following categories:
• Data Transfer Operations i.e. copy: This type is used to copy data from one location(source) to the other location(destination). Following are the type of data transfer operations:
Between Registers, specific data byte to a register or a memory location, between a memory location and a register, between an I/O device and the accumulator.

• Arithmetic Operations: These instructions are used to perform addition, substraction, increment and decrement.

• Logical Operations: These instructions are used to perform logical operations with the contents of the accumulator. Typical instructions perform AND, EX-OR, Rotate, Compare, Complement etc.

• Branching Operations: These instructions are used to alter the sequence of program execution either conditionally or unconditionally. EXAMPLES: Jump, Call, Return etc.

• Machine Control Operations: These instructions are used to control machine functions e.g. Halt, Interrupt, Do nothing

8085 Instruction Format

8085 instructions are classified into following three groups of instructions:
• One-word or 1-byte instructions
• Two-word or 2-byte instructions
• Three-word or 3-byte instructions

Instruction: It is a command given to the microprocessor to perform given task on specified data.
Each instruction has two parts viz. task to be performed known as operation code or opcode and second is the data to be operated upon known as operand. The Operand can be used in many different ways e.g. 8 bit data or 16 bit data or internal register or memory location or 8 bit or 16 bit address.


One Byte Instructions
Task Opcode Operand Binary Code Hex code
Add the contents of register B to contents of accumulator ADD B 1000 0000 80H
Copy contents of accumulator in register C MOV C,A 01001111 4FH

Two Byte Instructions
Task Opcode Operand Binary Code Hex code
Load 8 bit data byte in the accumulator MVI A, data 0011 1110, data 3E, data

If the data byte is stored in the 32H which need to be moved in the accumulator then the instruction can be written as follows: MVI A, 32H
Hex code is : 3E 32H


Three Byte Instructions
Task Opcode Operand Binary Code Hex code
Transfer the program sequence to memory location 2085H. JMP 2085H 11000011
10000101
00100000
C3
85
20

Sample 8085 Assembly Programs

Example-1: Write assembly program to add two numbers.


MVI D, 8CH
MVI C, 6EH
MOV A, C
ADD D
OUT PORT1
HLT

Example-2: Write assembly program to multiply a number by 8
Multiply by 2 is equivalent to shifting.


MVI A, 40H
RLC
RLC
RLC
OUT PORT1
HLT

Example-3: Write assembly program to find greatest between the two numbers.


MVI B, 30H
MVI C, 40H
MOV A, B
CMP C
JZ EQU
JC GRT
OUT PORT1
HLT
EQU: MVI A, 01H
OUT PORT1
HLT
GRT: MOV A, C
OUT PORT1
HLT


Similar posts on 8085 Microprocessor

8085 architecture   8085 programming   instructions   8085 vs 8086 

RELATED LINKS

Microcontroller tutorial
What is microcontroller
8051 Microcontroller Architecture
Microcontroller hardware Interfacing
Microcontroller Timers
Microcontroller Interrupts
Microcontroller Serial Communication