CHAPTER 2
8085 Microprocessor Programming & Instruction
Sets
CONTENTS
Introduction
Instruction formats
Addressing modes
Instruction set
Assembler directives
Simple program examples
2
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
3
INTRODUCTION CONT..
For e.g.
0100 1111
Is a valid machine language instruction of
8085
It copies the contents of one of the internal
registers of 8085 to another
4
INTRODUCTION CONT..
A Machine language program to add two
numbers
0011 1110 ; Copy value 2H in register A
0000 0010
0000 0110 ; Copy value 4H in register B
0000 0100
1000 0000 ;A=A+B
5
INTRODUCTION CONT..
Assembly Language of 8085
It uses English like words to convey the
action/meaning called as MNEMONICS
For e.g.
MOV to indicate data transfer
ADD to add two values
SUB to subtract two values
6
INTRODUCTION CONT..
Assembly language program to add two numbers
MVI A, 2H ;Copy value 2H in register A
MVI B, 4H ;Copy value 4H in register B
ADD B ;A = A + B
Note:
Assembly language is specific to a given processor
For e.g. assembly language of 8085 is different
than that of Motorola 6800 microprocessor
7
INTRODUCTION CONT..
Microprocessor understands Machine Language
only!
Microprocessor cannot understand a program
written in Assembly language
A program known as Assembler is used to
convert a Assembly language program to
machine language
Assembly Machine
Assembler
Language Language
Program
Program Code
8
INSTRUCTION FORMATS
8085 Instruction set can be classified according to
size (in bytes) as
1-byte Instructions
2-byte Instructions
3-byte Instructions
9
INSTRUCTION FORMAT CONT..
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
10
INSTRUCTION FORMATS CONT..
Two-byte Instructions
First byte specifies Operation Code
Second byte specifies Operand
Examples
Opcode Operand Binary Hex Code
Code
MVI A, 32H 0011 1110 3EH
0011 0010 32H
MVI B, F2H 0000 0110 06H
1111 0010 F2H
11
INSTRUCTION & DATA FORMATS
Three-byte Instructions
• First byte specifies Operation Code
• Second & Third byte specifies Operand
• Examples
Opcode Operand Binary Hex Code
Code
LXI H, 2050H 0010 0001 21H
0101 0000 50H
0010 0000 20H
LDA 3070H 0011 1010 3AH
0111 0000 70H 12
0011 0000 30H
ADDRESSING MODES
Format of a typical Assembly language
instruction is given below
[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 13
ADDRESSING MODES
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
5. Implied addressing mode 14
ADDRESSING MODES
1. Register Addressing
Operands are one of the internal registers of
8085
A, B, C, D, E, H, L
Examples
MOV A, B
ADD C
15
ADDRESSING MODES
2. Immediate Addressing
Value of the operand is given in the instruction
itself
Example
MVI A, 20H
LXI H, 2050H
ADI 30H
SUI 10H
16
ADDRESSING MODES
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
17
ADDRESSING MODES
3.1 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
18
ADDRESSING MODES
3.2 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
20H 50H 2050H 30H
A 30H
19
ADDRESSING MODES
4. Input / Output Addressing
8-bit address of the port is directly specified in
the instruction
Examples
IN 07H
OUT 21H
20
ADDRESSING MODES
5. Implied addressing mode
This mode doesn’t require any operand;
The data is specified by the opcode itself.
For example:
CMP ; complement content of accumulator
XCHG ; exchange values of HL to DE
21
INSTRUCTION SET
Simple program to compute 2’s complement of a
number
LDA 2345H ; A [2345] =12H
CMA ; A ED
INR A ; AEE
STA 2345H ; 2345HEE
HLT ; terminate program
22
INSTRUCTION SET CONT..
8085 is an 8-bit device
it can have up to 28 =256 instructions.
However, the 8085 only uses
246 combinations that represent a total of 66
instructions.
Most of the instructions have more than one
format.
23
INSTRUCTION SET CONT..
These instructions can be grouped into
Instruction group No of opcodes No of Instruction type
Data Transfer 83 13
Arithmetic Operation 62 14
Logical operation 43 15
Branch operation 36 8
Stack operation 15 9
I/O operation 2 2
Interrupt operation 5 5
Total 246 66
24
INSTRUCTION SET CONT..
Data Transfer Instructions
1. INSTRACTION TYPE MVI r,d8
Move immediate value to register
rd8
d8 any 8 bit value
r register (A,B,C,D,E,H or L) 7 opcode
Immediate addressing mode
2 byte instruction
1 byte for opcode and
1 byte for operand
Example:
MVI B,45H ; B =45H; 25
INSTRUCTION SET CONT..
Data Transfer Instructions con..
2. INSTRACTION TYPE MOV r1,r2
Move value from register r2 to r1
r1,r2 = Register(A,B,C,D,E,H or L)
7*7 49 opcode
One byte Instruction
Example:
MOV B,C ; copy value from register C to B
26
INSTRUCTION SET CONT..
Data Transfer Instructions con..
3. INSTRACTION TYPE MOV r, M
Move value from memory, M to register r
r= Register(A,B,C,D,E,H or L)
7 opcode
Memory address from HL register
One byte Instruction
Example:
MOV B,M ; copy value from memory to B
27
INSTRUCTION SET CONT..
Data Transfer Instructions con..
4. INSTRACTION TYPE MOV M, r
Move value from register, r to memory, M
r= Register(A,B,C,D,E,H or L)
7 opcode
Memory address from HL register
One byte Instruction
Example:
MOV M,B ; copy value from B to memory, M
28
INSTRUCTION SET CONT..
Data Transfer Instructions con..
5. INSTRACTION TYPE LXI rp, d16
Load extended register immediate value of 16
bit
rp= Register pair(BC, DE or HL)
3 opcode
d16 any 16 bit value
three byte Instruction
Example:
LXI B, 1234H ; BC1234H
B 34, C12
29
INSTRUCTION SET CONT..
Data Transfer Instructions con..
6. INSTRACTION TYPE MVI M, d8
Move 8 bit immediate value to memory, M
d8 8 bit value
Memory address from HL register
two byte Instruction
One for opcode
One for value
One opcode only
Example:
MVI M, 12H ; move value, 12H to memory located by 30
HL
INSTRUCTION SET CONT..
Data Transfer Instructions con..
7. INSTRACTION TYPE LDA d16
Load Accumulator with 16 bit value
Three byte Instruction
One byte for opcode
Two byte for operand
One opcode only
Example:
LDA 1234H ; A1234
31
INSTRUCTION SET CONT..
Data Transfer Instructions con..
8. INSTRACTION TYPE STA a16
Store accumulator value to memory address
a16
Three byte Instruction
One byte for opcode
Two byte for operand
One opcode only
Example:
STA 1234H ; [A]1234H
32
INSTRUCTION SET CONT..
Data Transfer Instructions con..
9. INSTRACTION TYPE XCHG
Exchange value of HL and DE
Implied addressing
One byte Instruction
One opcode only
Example:
XCHG ;DE HL and HLDE
33
INSTRUCTION SET CONT..
Data Transfer Instructions con..
10. INSTRACTION TYPE LAX rp
Load accumulator from memory pointed by
extended register pair, rp
rp can be BC or DE
Indirect addressing
One byte Instruction
Two opcodes
Example:
LAX B; A values from memory pointed by BC
LAX C; A values from memory pointed by DE 34
INSTRUCTION SET CONT..
Data Transfer Instructions con..
11. INSTRACTION TYPE STAX rp
Store content of accumulator to memory pointed
by extended register rp
rp can be BC or DE
Indirect addressing
One byte Instruction
Two opcodes
Example:
STAX B; content of A copied to memory pointed by BC
STAX C; content of A copied to memory pointed by DE 35
INSTRUCTION SET CONT..
Data Transfer Instructions con..
12. INSTRACTION TYPE LHLD a16
Load HL register pair from direct memory
address a16
a16 address value
Absolute addressing
Three byte Instruction
One opcodes
Example:
LHLD 1234H; HL content of memory pointed by 1234H
36
INSTRUCTION SET CONT..
Data Transfer Instructions con..
13. INSTRACTION TYPE SHLD a16
Store HL pair directly to memory address
starting at a16
Absolute addressing
Three byte Instruction
One opcodes
Example:
SHLD 1234H; HL to memory pointed by 1234H
37
INSTRUCTION SET CONT..
These instructions can be grouped into
Instruction group No of opcodes No of Instruction type
Data Transfer 83 13
Arithmetic Operation 62 14
Logical operation 43 15
Branch operation 36 8
Stack operation 15 9
I/O operation 2 2
Interrupt operation 5 5
Total 246 66
38
INSTRUCTION SET CONT..
Arithmetic group of instructions
Addition and Subtraction
No multiplication or division
14 instruction type
62 instruction
One of the operand must be Accumulator
Others can be
Content of 8 bit register
Content of memory location pointed by HL pair
8 bit immediate data
39
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
1. INSTRACTION TYPE ADD R
Add content of R to Accumulator
R A,B,C,D,E,H,L or M
8 opcode
Result stored on Accumulator
One byte instruction
Affect flags:
Cy, P, AC, Z, S
Example
ADD E ; AA+E 40
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
2. INSTRACTION TYPE ADI d8
Add immediate value d8 to Accumulator
one opcode
Result stored on Accumulator
two byte instruction
Affect flags:
Cy,P,AC,Z,S
Example
ADI B1H; AA+B1H
41
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
3. INSTRACTION TYPE INR R
Increment R, register
R: A, B, C, D, E, H, L or M
Eight opcode
One byte instruction
Affect flags:
P, AC, Z, S
Example
INR A; AA+01h
42
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
4. INSTRACTION TYPE ADC R
Add content of R with carry to accumulator
R: A, B, C, D, E, H, L or M
Eight opcode
One byte instruction
Affect flags:
Cy, P, AC, Z, S
Example
ADC B; AA+B
43
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
5. INSTRACTION TYPE ACI d8
Add immediate with carry to accumulator
One opcode
Two byte instruction
Affect flags:
Cy, P, AC, Z, S
Example
ADC B; AA+B
44
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
6. INSTRACTION TYPE SUB R
Subtract content of R from Accumulator
R: A,B,C,D,E,H,L or M
Eight opcode
One byte instruction
Affect flags:
Cy, P, AC, Z, S
Example
SUB B; AA-B
45
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
7. INSTRACTION TYPE SUI d8
Subtract d8 from accumulator
One opcode
Two byte instruction
Affect flags:
Cy, P, AC, Z, S
Example
SUI 12H; AA-12H
46
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
8. INSTRACTION TYPE DCR R
Decrement register R
R: A,B,C,D,E,H,L or M
8 opcode
One byte instruction
Affect flags:
P, AC, Z, S not Cy
Example
DCR B; BB-01H
47
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
9. INSTRACTION TYPE SBB R
Subtract R with borrow from accumulator
R: A,B,C,D,E,H,L or M
8 opcode
One byte instruction
Affect flags:
P, AC, Z, S, Cy
Example
SBB B; AA-B
48
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
10. INSTRACTION TYPE SBI d8
Subtract immediate with borrow from
accumulator
One opcode
Two byte instruction
Affect flags:
P, AC, Z, S, Cy
Example
SBI F2h ; AA-d8
49
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
11. INSTRACTION TYPE INX rp
Increment extended register pair rp
rp : BC, DE, HL
Three opcode
One byte instruction
No flag affected
Example
INX B
INX B = INX C???
50
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
12. INSTRACTION TYPE DCX rp
Decrement extended register pair rp
rp : BC, DE, HL
Three opcode
One byte instruction
No flag affected
Example
DCX B
51
INSTRUCTION SET CONT..
Arithmetic group of instructions con..
13. INSTRACTION TYPE DAD rp
Double add
Add content of rp to HL
rp : BC, DE, HL
Three opcode
One byte instruction
No flag affected except Cy
Example
DAD B
52
INSTRUCTION SET CONT..
These instructions can be grouped into
Instruction group No of opcodes No of Instruction type
Data Transfer 83 13
Arithmetic Operation 62 14
Logical operation 43 15
Branch operation 36 8
Stack operation 15 9
I/O operation 2 2
Interrupt operation 5 5
Total 246 66
53
INSTRUCTION SET CONT..
Logical group of instructions
15 instruction type
45 instructions
Includes
AND
OR
Exclusive OR
Complement accumulator
Complement carry flag
Compare and rotate 54
INSTRUCTION SET CONT..
Logical group of instructions cont..
AND operation
Operand
Accumulator and
8 bit immediate data, register or memory pointed by
HL
Bitwise AND operation
Flag
S, P and Z based on result
Cy reset
Ac set
55
INSTRUCTION SET CONT..
Logical group of instructions cont..
1. INSTRACTION TYPE ANA R
AND accumulator with register R
R: A, B, C, D, E, H, L or MEMORY
One byte instruction
8 opcode
Result on Accumulator
Example :
56
ANA B
INSTRUCTION SET CONT..
Logical group of instructions cont..
2. INSTRACTION TYPE ANI d8
AND accumulator with immediate value
Two byte instruction
1 opcode
Result on Accumulator
Example :
ANI 45h 57
INSTRUCTION SET CONT..
Logical group of instructions cont..
OR operation
Operand
Accumulator and
8 bit immediate data, register or memory pointed by HL
Bitwise OR operation
Flag
S, P and Z based on result
58
Cy and Ac reset
INSTRUCTION SET CONT..
Logical group of instructions cont..
3. INSTRACTION TYPE ORA R
OR accumulator with Register R
R: A, B, C, D, E, H, L or MEMORY
One byte instruction
8 opcode
Result on Accumulator
Example :
59
ORA B
INSTRUCTION SET CONT..
Logical group of instructions cont..
4. INSTRACTION TYPE ORI d8
OR accumulator with immediate value
Two byte instruction
1 opcode
Result on Accumulator
Example :
ORI 45h ; A A OR 45h 60
INSTRUCTION SET CONT..
Logical group of instructions cont..
Exclusive OR operation
Operand
Accumulator and
8 bit immediate data, register or memory pointed by HL
Bitwise Ex-OR operation
Flag
S, P and Z based on result
61
Cy and Ac reset
INSTRUCTION SET CONT..
Logical group of instructions cont..
5. INSTRACTION TYPE XRA R
Ex-OR accumulator with Register R
R: A, B, C, D, E, H, L or MEMORY
One byte instruction
8 opcode
Result on Accumulator
Example :
62
XRA B
INSTRUCTION SET CONT..
Logical group of instructions cont..
6. INSTRACTION TYPE XRI d8
Ex-OR accumulator with immediate value
Two byte instruction
1 opcode
Result on Accumulator
Example :
XRI 45h 63
INSTRUCTION SET CONT..
Logical group of instructions cont..
7. INSTRACTION TYPE CMA
Complement Accumulator
One byte instruction
One opcode
Result on Accumulator
Example :
CMA
64
Affects no flag
INSTRUCTION SET CONT..
Logical group of instructions cont..
8. INSTRACTION TYPE CMC
Complement CARRY FLAG
One byte instruction
One opcode
Result on carry flag
Example :
CMC 65
INSTRUCTION SET CONT..
Logical group of instructions cont..
9. INSTRACTION TYPE STC
Set carry flag
One byte instruction
One opcode
Result on carry flag
Example :
STC 66
INSTRUCTION SET CONT..
Logical group of instructions cont..
10 INSTRACTION TYPE CMP R
Compare accumulator with Register R
R: A, B, C, D, E, H, L or MEMORY
One byte instruction
8 opcode
Result on Temp register
Affects all flags
Example :
67
CMP B
INSTRUCTION SET CONT..
Logical group of instructions cont..
11. INSTRACTION TYPE CPI d8
Compare accumulator with immediate value
Two byte instruction
1 opcode
Result on Temp register
Affect all flags
Example :
68
CPI 45h
INSTRUCTION SET CONT..
Logical group of instructions cont..
12. INSTRACTION TYPE RLC
Rotate accumulator left with out carry flag
Affects Cy : MSB
To check MSB
To multiply by 2
Example :
RLC 69
INSTRUCTION SET CONT..
Logical group of instructions cont..
13. INSTRACTION TYPE RAL
Rotate accumulator left with carry flag
Affects Cy : MSB
Application:
To check MSB
To multiply by 2
Example :
70
RAL
INSTRUCTION SET CONT..
Logical group of instructions cont..
14. INSTRACTION TYPE RRC
Rotate accumulator right with out carry flag
Affects Cy : LSB
Application:
To check LSB
To divide by 2
Example :
71
RRC
INSTRUCTION SET CONT..
Logical group of instructions cont..
15. INSTRACTION TYPE RAR
Rotate accumulator right with carry flag
Affects Cy : MSB
Application:
To check MSB
To multiply by 2
Example :
72
RAL
INSTRUCTION SET CONT..
These instructions can be grouped into
Instruction group No of opcodes No of Instruction type
Data Transfer 83 13
Arithmetic Operation 62 14
Logical operation 43 15
Branch operation 36 8
Stack operation 15 9
I/O operation 2 2
Interrupt operation 5 5
Total 246 66
73
INSTRUCTION SET CONT..
Stack group of instructions
Stack
Data structure implemented in a RAM
LIFO (last in first out)
Store data and address
SP (stack pointer)
16-bit special register
Pointes to top of stack
Stack operation instruction
9- instruction type
15 – instruction 74
INSTRUCTION SET CONT..
Stack group of instructions cont..
1. INSTRACTION TYPE POP rp
Load register pair rp 2 byte from top of stack
rp: BC, DE, HL, or PSW (accumulator + flag)
Four opcode
Example:
POP B ; load BC from top of stack
One byte instruction
75
INSTRUCTION SET CONT..
Stack group of instructions cont..
2. INSTRACTION TYPE PUSH rp
Store content of rp to top of stack
rp: BC, DE, HL, or PSW
Four opcode
One byte instruction
Example:
PUSH D ; store content of DE to top of stack
PUSH PSW ; store content of PSW to top of stack 76
INSTRUCTION SET CONT..
Stack group of instructions cont..
3. INSTRACTION TYPE LXI SP, d16
Load extended immediate value to SP
Load SP immediate value of 16-bit
To change stack pointer address from top of stack to
other stack address
One opcode
Three byte instruction
Example:
LXI SP, 1234h; load SP with new address 1234h
77
INSTRUCTION SET CONT..
Stack group of instructions cont..
4. INSTRACTION TYPE SPHL
Load SP with content of HL register pair
One byte instruction
One opcode
Example:
SPHL ; SP HL
78
INSTRUCTION SET CONT..
Stack group of instructions cont..
5. INSTRACTION TYPE XTHL
Exchange top of stack with HL pair
Not SP with HL
One byte
One opcode
Example:
XTHL
79
INSTRUCTION SET CONT..
Stack group of instructions cont..
6. INSTRACTION TYPE INX SP
Increment SP by one
One byte instruction
One opcode only
Example:
INX SP
80
INSTRUCTION SET CONT..
Stack group of instructions cont..
7. INSTRACTION TYPE DCX SP
Decrement SP by one
One byte instruction
One opcode only
Example:
DCX SP
81
INSTRUCTION SET CONT..
Stack group of instructions cont..
8. INSTRACTION TYPE DAD SP
Add content of SP to HL
One byte instruction
One opcode
Example:
DAD SP
Affects carry flag only
82
INSTRUCTION SET CONT..
Stack group of instructions cont..
9. INSTRACTION TYPE NOP
No operation
Do nothing
Application :
To generate small delay
To delete/Insert few instruction in program
One byte instruction
One opcode
83
INSTRUCTION SET CONT..
These instructions can be grouped into
Instruction group No of opcodes No of Instruction type
Data Transfer 83 13
Arithmetic Operation 62 14
Logical operation 43 15
Branch operation 36 8
Stack operation 15 9
I/O operation 2 2
Interrupt operation 5 5
Total 246 66
84
INSTRUCTION SET CONT..
Branch group of instructions
Eight Instruction Type
36 instruction
Unconditional/Conditional Branch instruction
Unconditional / conditional call instruction
Return from call instruction
85
INSTRUCTION SET CONT..
Unconditional Branch Instruction
1. INSTRACTION TYPE JMP a16
Jump to memory address a16
Direct memory addressing
Three byte instruction
Example:
JMP 12EFh; PC 12EFh
86
INSTRUCTION SET CONT..
Unconditional Branch Instruction
2. INSTRACTION TYPE PCHL
Load PC with content of HL
Unconditional indirect jump
One byte instruction
Example:
PCHL ; PC [HL]
87
INSTRUCTION SET CONT..
Conditional Branch instructions
3. INSTRACTION TYPE JNC a16
Jump if not carry, cy =0 to memory address a16
Three byte instruction
Example: JNC 123Ah
4. INSTRACTION TYPE JC a16
Jump if carry, cy =0 to memory address a16
Three byte instruction
Example: JC 123Ah
88
INSTRUCTION SET CONT..
Conditional Branch instructions cont..
5. INSTRACTION TYPE JNZ a16
Jump if not zero, Z=0 to memory a16
Three byte instruction
Example: JNZ 1234h
6. INSTRACTION TYPE JZ a16
Jump if zero, Z=1 to memory a16
Three byte instruction
Example: JZ 1234h 89
INSTRUCTION SET CONT..
Conditional Branch instructions cont..
7. INSTRACTION TYPE JPO a16
Jump if parity odd, P=0
Three Byte
Example: JPO 1234h
8. INSTRACTION TYPE JPE a16
Jump if parity even, P=1
Three Byte
Example: JPE 1234h
90
INSTRUCTION SET CONT..
Conditional Branch instructions cont..
9. INSTRACTION TYPE JP a16
Jump if positive, S=0
Three byte
Example: JP 1234h
10. INSTRACTION TYPE JM a16
Jump if Minus, S=1
Three byte
Example: JM 1234h
91
INSTRUCTION SET CONT..
Branch instructions cont..
11. INSTRACTION TYPE CALL , a16
Call a subroutine at memory address a16
PUSH next instruction on top of stack
Three byte instruction
Example: CALL 1234h ; PUSH (PC+3byte) and PC1234h
12. INSTRACTION TYPE RET
Return from call
New PC POP from stack top
One byte instruction
92
Example: RET; PC POP
INSTRUCTION SET CONT..
Branch instructions cont..
13.INSTRACTION TYPE CNC a16
Call if not carry, cy =0 subroutine at a16
Three byte instruction
PUSH next instruction on top of stack
Example: CNC 1234h ; PUSH [PC+3] and PC1234h
14. INSTRACTION TYPE CC a16
Call if carry, cy =1 subroutine at a16
Three byte instruction
PUSH next instruction on top of stack
93
Example: CC 1234h ; PUSH [PC+3] and PC1234h
INSTRUCTION SET CONT..
Branch instructions cont..
15. INSTRACTION TYPE CNZ a16
Call if not zero, Z =0 subroutine at a16
Three byte instruction
PUSH next instruction on top of stack
Example: CNZ 1234h ; PUSH [PC+3] and PC1234h
16. INSTRACTION TYPE CZ a16
Call if zero, Z =1 subroutine at a16
Three byte instruction
PUSH next instruction on top of stack
94
Example: CZ 1234h ; PUSH [PC+3] and PC1234h
INSTRUCTION SET CONT..
Branch instructions cont..
17. INSTRACTION TYPE CPO a16
Call if parity odd, P =0 to subroutine at a16
Three byte instruction
PUSH next instruction on top of stack
Example: CPO 1234h ; PUSH [PC+3] and PC1234h
18. INSTRACTION TYPE CPE a16
Call if parity even, P =1 to subroutine at a16
Three byte instruction
PUSH next instruction on top of stack
95
Example: CPE 1234h ; PUSH [PC+3] and PC1234h
INSTRUCTION SET CONT..
Branch instructions cont..
19. INSTRACTION TYPE CP a16
Call if positive, S =0 to subroutine at a16
Three byte instruction
PUSH next instruction on top of stack
Example: CP 1234h ; PUSH [PC+3] and PC1234h
20. INSTRACTION TYPE CM a16
Call if minus, S =1 to subroutine at a16
Three byte instruction
PUSH next instruction on top of stack
96
Example: CM 1234h ; PUSH [PC+3] and PC1234h
INSTRUCTION SET CONT..
Branch instructions cont..
21. INSTRACTION TYPE RNC
Return if not carry, CY=0
One byte instruction
POP PC from top of stack
Example: RNC ; POP PC
22. INSTRACTION TYPE RC a16
Return if carry, CY=1
One byte instruction
POP PC from top of stack
97
Example: RC ; POP PC
INSTRUCTION SET CONT..
Branch instructions cont..
23. INSTRACTION TYPE RNZ
Return if not Zero, Z=0
One byte instruction
POP PC from top of stack
Example: RNZ ; POP PC
24 INSTRACTION TYPE RZ a16
Return if Zero, Z=1
One byte instruction
POP PC from top of stack
98
Example: RZ ; POP PC
INSTRUCTION SET CONT..
Branch instructions cont..
25. INSTRACTION TYPE RPO
Return if parity odd, P=0
One byte instruction
POP PC from top of stack
Example: RPO ; POP PC
26. INSTRACTION TYPE RPE a16
Return if parity even, P=1
One byte instruction
POP PC from top of stack
99
Example: RPE ; POP PC
INSTRUCTION SET CONT..
Branch instructions cont..
27. INSTRACTION TYPE RP
Return if positive, S=0
One byte instruction
POP PC from top of stack
Example: RP ; POP PC
28. INSTRACTION TYPE RM a16
Return if minus, S=1
One byte instruction
POP PC from top of stack
100
Example: RM ; POP PC
INSTRUCTION SET CONT..
Branch instructions cont..
29. INSTRACTION TYPE RST n
Restart
n: 0-7
One byte instruction
Example:
RST 0 ; CALL 0*8= CALL 0000h
RST 2; CALL 2*8 = CALL 0010h
101
INSTRUCTION SET CONT..
These instructions can be grouped into
Instruction group No of opcodes No of Instruction type
Data Transfer 83 13
Arithmetic Operation 62 14
Logical operation 43 15
Branch operation 36 8
Stack operation 15 9
I/O operation 2 2
Interrupt operation 5 5
Total 246 66
102
INSTRUCTION SET CONT..
I/O instructions
1. INSTRACTION TYPE IN a8
Input to accumulator from input port
a8 address of the port
Two byte
One opcode
Example:
IN 0Fh ; A InPort[OFh]
103
INSTRUCTION SET CONT..
I/O instructions
2. INSTRACTION TYPE OUT a8
Output content of accumulator to output port
a8 address of output port
Two byte
One opcode
Example:
OUT FFh ; A Output Port[FFh]
104
CONTENTS
Introduction
Instruction formats
Addressing modes
Instruction set
Assembler directives
Simple program examples
105
ASSEMBLER DIRECTIVES
Definition:
Are instructions used by assembler at the time of
assembling source code.
Instruction to control assembler, nothing to do with
the microprocessor
Also known as Pseudo-instructions or pseudo-opcode
106
ASSEMBLER DIRECTIVES CONT..
What they do:
Show beginning and end of source code
Provide storage locations to data
To give value to variables
To define start and end of segments
107
ASSEMBLER DIRECTIVES CONT..
ORG:
Origin
To assign starting/beginning address for module of
segment
ORG 1000H
Following instruction must be stored in memory location
starting at 1000H
END:
End program
For program termination
108
ASSEMBLER DIRECTIVES CONT..
DB:
DATA 21H
Define Byte
20H
To allocate and initialize data byte
DATA DB 20H,21H
Memory named Data has 2 consecutive information 20H
and 21H on it
DATAWORD 40H
DW:
22H
Define Word
ACH
To define and initialize 16-bit word
20H
DATAWORD DW 20ACH, 2240H
Memory named DATAWORD has 4 consecutive
byte with information40H, 22H, ACH and 20H 109
ASSEMBLER DIRECTIVES CONT..
EQU:
Equate
To assign value to variables
X EQU A1H
X A1H
MACRO : beginning of macro
ENDM: end of macro
Exam MACRO
….
….
….
110
Exam ENDM
CONTENTS
Introduction
Instruction formats
Addressing modes
Instruction set
Assembler directives
Simple program examples
111
SIMPLE PROGRAM EXAMPLES
Write an assembly language program to transfer data from
register B to C.
MVI B, 4AH ; BAH
MOV C, B ;CB
HLT ; stop process and wait
112
SIMPLE PROGRAM EXAMPLES
Write an assembly language program to store data from B
register into memory location 1050H.
MVI B, 1020H ; B 1020H
MOV A, B ; A B
STA 1050H ; M[1050H] A
HLT
113
SIMPLE PROGRAM EXAMPLES
Write an assembly language program to exchange 8-bit
data stored in memory locations 2050H and 2051H
LDA 2050H ; A [2050h
MOV B, A ;B A
LDA 2051H ; A[2051H]
STA 2050H ; [2050]A
MOV A , B ;AB
STA 2051H ;[2051]A
HLT 114
SIMPLE PROGRAM EXAMPLES
Write an assembly language program to add two 8-bit numbers
stored in memory location 2050h and 2051h. Store result in location
2052h.
LXI H 2050H ; HL2050
MOV A, M ; AM[2050]
INX H ; HL2051
ADD H ; A A+M[HL=2051]
INX H ; HL2052
MOV M , A ; M[2052]A
HLT ; STOP PROGRAM 115
SIMPLE PROGRAM EXAMPLES
Write an assembly language program to find 1’s complement of the
data stored in memory location 2500 H and the result is to be stored
in memory location 2501 H.
LDA 2500H ; A[2500h]
CMA ; complement [A]
STA 2501H ; 2501[A]
HLT ; end program
116
SIMPLE PROGRAM EXAMPLES
Write an assembly language program of 8085 to find
1’s complement of n (decimal number) bytes of data
stored in memory location starting at 2501 H. The
number n (decimal number) is stored in memory
location 2500 H. Store the result in memory locations
starting at 2601 H.
117
SIMPLE PROGRAM EXAMPLES
LXI D, 2601h ; DE first address 2601h
LXI H, 2500h ; HL second address 2500h
MOV C, M ; C [2500] counter register
INX H ; Increment H-L register pair.
LOOP: MOV A, M ; AM[H-L]
CMA ; complement content of Accumulator
STAX D ; M[DE]A.
INX D ; Increment D-E register pair.
INX H ; Increment H-L register pair.
DCR C ; Decrement the C-register data.
JNZ LOOP ; If data in C-reg. is not zero jump to LOOP
HLT ; Stop processing. 118
SIMPLE PROGRAM EXAMPLES
Write an Assembly program for 8085 to arrange a
series of N-numbers in descending order. The
number N is stored in memory location 2100 H. The
series is stored in memory location starting at 2101
H. The result is to be stored in memory locations
starting at 2201 H.
119
Main Program:
LXI SP, XXXX H ; Initialize stack pointer.
LXI D, 2201 H ; Get D-E pair with 2201 H.
LXI H, 2100 H ; Get H-L pair with 2100 H.
MOV B, M ; Store the count N in B-register.
START LXI H, 2100 H ; Get H-L pair with 2100 H.
MOV C, M ; Store the number N in C-register
INX H ; Increment the H-L pair.
MOV A, M ; AM[HL]
DCR C ; Decrement count.
LOOP INX H ; Increment the H-L pair.
CMP M ; Compare the second number with first number.
JNC NXT ; If the accumulator content is larger
; then jump to NXT.
MOV A, M ; Else move [M −LH ] to accumulator.
120
NXT DCR C ; Decrement count.
JNZ LOOP ; Jump to LOOP if not zero.
STAX D ; Store the largest number in memory location
; addressed by D-E register pair.
CALL SUBR ; Call the subroutine SUBR to put 00 H to the
; memory location where the largest number
; was found.
INX D ; Increment D-E register pair.
DCR B ; Decrement B.
JNZ START ; Jump to START if not zero.
HLT ; Stop processing.
121
Subroutine Program:
SUBR LXI H, 2100 H ; Get H-L pair with 2100 H.
MOV C, M ; Store the number N is C-register
AGAIN INX H ; Increment the H-L pair.
CMP M ; Compare the number with the largest
; number obtained in the main program.
JZ NXT ; If it is largest jump to NXT.
DCR C ; Decrement count.
JNZ AGAIN ; If counts not complete jump to AGAIN.
MVI A, 00 H ; Store 00 H to the accumulator.
MOV M, A ; Put 00 H to the location at which
; the largest number was found.
RET ; Go back to main program.
122