Assembly Language Programming
Assembly Language Programming
Assembly Language Programming
Programming
Instruction
set
5
Instruction Set of 8085
Arithmetic Instructions
Logical Instructions
Branching Instructions
Control Instructions
7
1.Data Transfer Instructions
8
2.Arithmetic
Instructions
These instructions perform the
operations like:
Addition
Subtract
Increment
Decrement
9
3.Logical Instructions
11
5. Control Instructions
12
Writing a Assembly Language Program
• Stop processing
Stop
5. Assembly Language Program
1. Get two numbers
a) Load 1st no. in register D MVI D, 2H
b) Load 2nd no. in register E MVI E, 3H
2. Add them
a) Copy register D to A MOV A, D
b) Add register E to A ADD E
3. Store result
a) Copy A to register C MOV C, A
4. Stop
a) Stop processing HLT
MANUAL ASSEMBLING
18
1.Data Transfer Instructions
A 20 B MOV B,A A 20 B 20
A F A F
B 30 C B 30 C
MOV M,B
D E D E
H 20 L 50 H 20 L 50 30
A F A F
B C B C 40
MOV C,M
D E D E
H 20 L 50 40 H 20 L 50 40
MVI-Move immediate 8-bit
Opcode Operand
Rd, Data
MVI M, Data
A F A F
B C MVI B,60H B 60 C
D E D E
H L H L
204FH 204F
HL=2050 HL=2050 40
MVI M,40H
2051H 2051H
LDA-Load accumulator
Opcode Operand
A A 30
LDA
2000H 30 2000H 30
2000H
LDAX-Load accumulator indirect
Opcode Operand
LDAX B/D Register Pair
The contents of either the register pair or the memory location are
not altered.
Example: LDAX D
BEFORE EXECUTION AFTER EXECUTION
A F A 80 F
B C B C 80
2030H 80 2030H
LDAX D
D 20 E 30 D 20 E 30
LXI-Load register pair immediate
Opcode Operand
LXI Reg. pair, 16-bit data
A F A 80 F
B C B C
2030H 00 8500H 60
LHLD
H L 2030 H 85 L 00
85
M=6
0
STA-Store accumulator direct
Opcode Operand
STA 16-bit address
A 50 A
50
STA 50
2000H 2000H
2000H
STAX-Store accumulator indirect
Opcode Operand
Example: STAX B
B 85 C 00
8500H 1A
A=1AH STAX B
SHLD-Store H and L registers direct
Opcode Operand
SHLD 16-bit address
D E
8500H 80
H 70 L 80 SHLD
8501H 70
8500
XCHG-Exchange H and L with D and E
Opcode Operand
XCHG None
Example: XCHG
BEFORE EXECUTION AFTER EXECUTION
D 20 E 40 D 70 E 80
XCHG
H 70 L 80 H 20 L 40
SPHL-Copy H and L registers to the
stack pointer
Opcode Operand
SPHL None
Example: SPHL
BEFORE EXECUTION
SP
H 25 L 00
SPHL
AFTER EXECUTION
SP 2500
H 25 L 00
XTHL-Exchange H and L with top of
stack
Opcode Operand
XTHL None
Example: XTHL
L=SP
H=(SP+1)
SP 2700
2700H 50 SP 2700
40
2700H
H 30 L 40 H L
2701H 60 60 50
30
2701H
XTHL
2702H 2702H
PUSH-Push register pair onto stack
Opcode Operand
PUSH Reg. pair
Example: PUSH H
Opcode Operand Description
PCHL None Load program counter with H-L
contents
Example: PCHL
PUSH H
POP- Pop stack to register pair
Opcode Operand
POP Reg. pair
Example: POP H
POP H
IN- Copy data to accumulator from a
port with 8-bit address
Opcode Operand
IN 8-bit port address
The contents of I/O port are copied into
accumulator.
Example: IN 8C H
BEFORE EXECUTION
PORT 10 A
80H
IN 80H
AFTER EXECUTION
PORT 10 A
80H
10
OUT- Copy data from accumulator to a
port with 8-bit address
Opcode Operand
OUT 8-bit port address
The contents of accumulator are copied into the I/O
port.
PORT 10 A 40
50H
OUT 50H
AFTER EXECUTION
PORT 40 A 40
50H
2.Arithmetic Instructions
• These instructions perform the operations
like:
– Addition
– Subtract
– Increment
– Decrement
53
54
Addition
Any 8-bit number, or the contents of register,
or the contents of memory location can be
added to the contents of Accumulator.
The result (sum) is stored in the
Accumulator.
NB: No two other 8-bit registers can be added
directly.
Example: The contents of register B cannot
be added directly to the contents of register C.
ADD
Opcode Operand Description
ADD R Add register or memory to
M accumulator
A 09
A
0
B C 05
B
4 C
0 ADD C D E
5 A=A+C H L
D E
04+05=09
H L
BEFORE EXECUTION
AFTER EXECUTION
A0 ADD M A1
B
D
4 C
E
A=A+M B
D 4
C
E
H 20 L 50 10
10 H 20 L 50
The contents of register or memory and Carry Flag (CY) are added to the
contents of accumulator.
C
050
Y
A
A5
B 1 C
0 ADC C
B C 20
5
A=A+C+CY
D
H6 E
L
D E 50+05+01=56
H L
BEFORE EXECUTION AFTER EXECUTION
CY 1
2050H 30 ADC M 2050H 30
A 06 A 37
H 20 L 50
A=A+M+CY
H 20 L 50
06+1+30=37
ADI
Example: ADI 45 H
BEFORE EXECUTION AFTER EXECUTION
A 0 ADI 05H A 0
A=A+DATA(8)
3 8
03+05=08
Example: ACI 45 H
BEFORE EXECUTION AFTER EXECUTION
CY 1 ACI 20H
A=A+DATA
A0 A 26
(8)+CY
5 05+20+1=26
DAD
Opcode Operand Description
DAD Reg. pair Add register pair to H-L pair
D 12 E 34 D 12 E 34
DAD H 35 L 79
H 23 L 45
D
1234
2345 +
------- DAD D HL=HL+DE
3579 DAD B HL=HL+BC
Subtraction
Any 8-bit number, or the contents of register, or the
contents of memory location can be subtracted
from the contents of accumulator.
The result is stored in the accumulator.
A 05
A
0
B C 04
B
9 C
0 SUB C D E
4 A=A-C H L
D E
09-04=05
H L
BEFORE EXECUTION
AFTER EXECUTION
A1 SUB M A0
B
D
4 C
E
A=A-M B
D 4
C
E
H 20 L 50 10
10 H 20 L 50
C
008
Y
A
A0
B 1 C
0 SBB C
B C 05
5 A=A-C-CY
D
H2 E
L
D E 08-05-01=02
H L
BEFORE EXECUTION AFTER EXECUTION
CY 1
A 06
2050H 02 SBB M A 03 2050H 02
H 20 L 50 A=A-M-CY H 20 L 50
06-02-1=03
SUI
Opcode Operand Description
A 0 SUI 05H A 0
A=A-DATA(8)
8 3
08-05=03
SBI
Opcode Operand Description
SBI 8-bit data Subtract immediate from
accumulator with borrow
The 8-bit data and the Borrow Flag (i.e. CY) is subtracted
from the contents of the accumulator.
Example: SBI 45 H
collected by C.Gokul AP/EEE,VCET
BEFORE EXECUTION AFTER EXECUTION
CY 1 SBI 20H
A 25 A=A-DATA A 04
(8)-CY
25-20-01=04
Increment / Decrement
• The 8-bit contents of a register or a memory
location can be incremented or decremented
by 1.
• The 16-bit contents of a register pair can be
incremented or decremented by 1.
• Increment or decrement can be performed on
any register or a memory location.
INR
Opcode Operand Description
INR R Increment register or
M memory by 1
A A
B 10 C INR B B 11 C
D
H
E
L
R=R+1 D
H
E
L
10+1=11
BEFORE EXECUTION AFTER EXECUTION
H
20
L
50 2050H 10
INR M
H
20
L
50 1 2050H
M=M+1 1
10+1=11
INX
SP SP
B C B C
D E
INX H D E
H 10 L 20 RP=RP+1 H 10 L 21
1020+1=1021
DCR
A A
B C B C
D E 20
DCR E D E 19
H L R=R-1 H L
20-1=19
BEFORE EXECUTION AFTER EXECUTION
H L
H
20
L
50
2050H
21 DCR M
20 50 2050H 20
M=M-1 21-1=20
DCX
SP SP
B C B C
D E
DCX H D E
H 10 L 21 RP=RP-1 H 10 L 20
3.Logical Instructions
These instructions perform logical operations on data
stored in registers, memory and status flags.
The contents of the accumulator are logically ANDed with the contents of
register or memory.
The result is placed in the accumulator.
If the operand is a memory location, its address is specified by the contents
of H-L pair.
S, Z, P are modified to reflect the result of the operation.
CY is reset and AC is set.
Example: ANA B or ANA M.
0101 0101=55H
CY AC 1011 0011=B3H CY 0 AC 1
B3 0001 0001=11H B3
A 55 2050H A 11 2050H
H 20 L 50 ANA M H 20 L 50
A=A and M
Opcode Operand Description
ANI 8-bit data Logical AND immediate with
accumulator
1011 0011=B3H
0011 1111=3FH
0011 0011=33H
CY AC CY 0 AC 1
ANI 3FH
A B3 A=A and DATA(8) A 33
Opcode Operand Description
ORA R Logical OR register or memory with
M accumulator
CY AC CY 0 AC 0
ORA B
A=A or R
A AA A BA
B 12 C B 12 C
D E D E
H L H L
0101 0101=55H
1011 0011=B3H
BEFORE EXECUTION AFTER EXECUTION
1111 0111=F7H
CY AC CY 0 AC 0
ORA M
A=A or M
B3 B3
A 55 2050H A F7 2050H
H 20 L 50 H 20 L 50
Opcode Operand Description
CY AC CY 0 AC 0
ORI 08H
A B3 A=A or DATA(8) A BB
Opcode Operand Description
The contents of the accumulator are XORed with the contents of the
register or memory.
The result is placed in the accumulator.
If the operand is a memory location, its address is specified by the
contents of H-L pair.
S, Z, P are modified to reflect the result of the operation.
CY and AC are reset.
Example: XRA B or XRA M.
1010 1010=AAH
BEFORE EXECUTION 0010 1101=2DH AFTER EXECUTION
1000 0111=87H
CY AC CY 0 AC 0
A AA A 87
B 10 C 2D B C 2D
D E
XRA C D E
H L A=A xor R H L
0101 0101=55H
BEFORE EXECUTION 1011 0011=B3H AFTER EXECUTION
1110 0110=E6H
CY AC CY 0 AC 0
B3 XRA M B3
2050H A E6 2050H
A 55
A=A xor M
H 20 L 50 H 20 L 50
Opcode Operand Description
CY AC CY 0 AC 0
XRI 39H
A B3 A=A xor DATA(8) A 8A
Compare
Any 8-bit data, or the contents of register, or
memory location can be compares for:
◦ Equality
◦ Greater Than
◦ Less Than
10<20:CY=01
BEFORE EXECUTION AFTER EXECUTION
A>M: CY=0
A=M: ZF=1
A<M: CY=1
CY Z CY 0
ZF 1
A B8 2050H
B8 A B8 2050H
B8
CMP M
H 20 L 50 H 20 L 50
A-M
B8=B8 :ZF=01
Opcode Operand Description
CY Z CY 0 AC 0
CPI 30H
A BA
A-DATA A BA
BA>30 : CY=00
Rotate
• Each bit in the accumulator can be shifted
either left or right to the next position.
Opcode Operand Description
RLC None Rotate accumulator left
CY B7 B6 B5 B4 B3 B2 B1 B0
AFTER EXECUTION
B7 B6 B5 B4 B3 B2 B1 B0 B7
Opcode Operand Description
RRC None Rotate accumulator right
B7 B6 B5 B4 B3 B2 B1 B0 CY
AFTER EXECUTION
B0 B7 B6 B5 B4 B3 B2 B1 B0
CY B7 B6 B5 B4 B3 B2 B1 B0
AFTER EXECUTION
B7 B6 B5 B4 B3 B2 B1 B0 CY
Opcode Operand Description
RAR None Rotate accumulator right
through carry
B7 B6 B5 B4 B3 B2 B1 B0 CY
AFTER EXECUTION
CY B7 B6 B5 B4 B3 B2 B1 B0
Complement
• The contents of accumulator can be
complemented.
• Each 0 is replaced by 1 and each 1 is replaced
by 0.
Opcode Operand Description
A 00 A FF
Opcode Operand Description
CMC None Complement carry
C 00 C FF
Opcode Operand Description
STC None Set carry
No operation is performed.
The instruction is fetched and decoded but no
operation is executed.
Example: NOP
Opcode Operand Description
HLT None Halt