Chapter 4
Chapter 4
(MPI)
GTU # 3160712
Unit-4:
Assembly
Language
Programming
Basics
PART-I: 8085 Instruction Set
Looping
Topics to be covered
Assembly Language Programming
Basics
Hierarchy of Languages
Compilers and Assemblers
Instructions and Machine Language
Advantages of High-Level Languages
Why to Learn Assembly Language?
Assembly Language Programming
Tools
Classification of 8085 Instructions
Based on Byte Size
Based on Function
Hierarchy of Languages
Hierarchy of Languages
Application
Program
• Assembly
High Level language is
Machine Independent Language High Level Language
a low-level
Machine Specific Assembly programmi
Low Level Language
Language ng
1100 language
MOV 1011 Machine designed
BL,05h 1100 Language for a
ADD CL 1110
specific
MUL BH 0100
1111 Micro Program •type
Native toofa processor:
Control processor.
executed directly by
• Uses
hardware
Hardware •symbolic
Instructions consist of binary
names
code: 1stoand 0s
represent
operations,
registers
and
Compilers and
Assemblers
Compilers and Assemblers
High Level
Language
Compil
er
Compil Assembly
er Language
Assemb
ler
Machine
Language
Compilers translate high-level programs
Assemblers to assembly code to
translates
machine code machine code
either directly, or Indirectly via an assembler
Instructions and
Machine Language
Instructions and Machine Language
Each command of a program is called an instruction (it instructs the
computer, what to do?).
Computers only deal with binary data, hence the instructions must be in
binary format (0’s and 1’s).
Therefore, each Opcode is having unique bit pattern of (0’s and 1’s).
Instruction Fields
Assembly language instructions usually are made up of several fields.
Each field specifies different information.
The major two fields are:
1. Opcode: Operation code that specifies operation to be performed.
Each operation has its unique opcode.
2. Operands: Fields which specify, where to get the source and destination operands
for the operation specified by the opcode.
Instruction Fields
Opcod Operand
e
MOV Rd, Rs
M, Rs
R, M
Rd Destination Register
Rs Source Register
M Memory
Translating Languages
High-Level Language: A + B
Link
Source Object
Assembler Libraries
File File
Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Classification of 8085 instructions
An instruction is a binary pattern designed inside a microprocessor to
perform a specific function.
Each instruction is represented by an 8-bit binary value called Op-Code.
The entire group of instructions that a microprocessor supports is known
as an Instruction Set.
Classification of 8085 instructions
Instruction Set
It is the set of instructions that the microprocessor can understand.
Opcode
Known as Operation Code.
This required field contains the mnemonic operation code for the 8085 instruction.
Operand
The operand field identifies the data to be operated on by the specified opcode.
Some instructions require no operands, while others require one or two operands.
MVI D, 8BH
Opco Opera
de nd
Classification of 8085 instructions
General Terms
In three-byte instruction,
1st Byte: Specifies Opcode
2nd Byte: Specifies lower order 8-bit address
3rd Byte: Specifies higher order 8-bit address
Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Data Transfer
Instructions
Data Transfer Instructions
Instructions copy data from source to destination.
While copying, the contents of source is not modified.
Data Transfer Instructions do not affect the flags.
MOV: Move data from source to destination
LDA
2050H
Register Memor
s y 02 2000
A
04 …
B C 0A ..
06 .
D E
0F 2049
H L 0D 205
05 0051
2
03 2052
LDA: Load Accumulator
LDAX B ;
AM[BC]
Register Memor
s y 02 0001
A
04 0002
B 00 06 C 0A 0003
06 0004
D E
0F 0005
H L 0D 0006
05 0007
03 0008
LXI: Load the immediate register pair
D A2 03 E D D3 08 E
H D3 08 L H A2 03 L
SPHL: Copy H and L registers to stack pointer
Register Memor
s y 0001
3F 0002 SP
H A2 D3 L 0003
2C SP
0004
Example: PUSH Instruction
PUSH B
SP <- SP-1
SP <- B ;transfer high
order bit to TOS
SP <- SP-1
SP <- C ;transfer low
order bit to TOS
Register Memor
s SP y 23 0008
A
SP 06 0007
B 06 40 C SP 40 0006
D E 0005
0004
H L 0003
0002
0001
PUSH: Push the register pair onto the stack
Instruction Description Example
Opcod Operan
e d The contents of the register pair PUSH B
PUSH Rp
designated in the operand are
copied onto the stack in the
following sequence.
1. The SP register is
decremented and the
contents of the high order
register (B, D, H) are copied
into that location.
2. The SP register is
decremented again and the
contents of the low-order
register (C, E, L) are copied
to that location.
Example: POP Instruction
Register Memo
s SP ry03 0008
A
SP 06 0007
B 06 40 C SP 40 0006
D 0005
E
0004
H L 0003
0002
0001
POP B
C <- SP ; transfer to low order bit
from TOS
SP <- SP+1
Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Arithmetic Instructions
1 ADD R/M Add register or memory, to the 1 Byte
accumulator
2 ADC R/M Add register to the accumulator with 1 Byte
carry
3 ADI 8-bit Add the immediate to the accumulator 2 Byte
Arithmetic Instructions
4 data
ACI 8-bit Add the immediate to the accumulator 2 Byte
data with carry
5 DAD R p
Add the register pair to H and L registers 1 Byte
6 SUB R/M Subtract the register/memory from 1 Byte
accumulator
7 SBB R/M Subtract the source and borrow from 1 Byte
accumulator
8 SUI 8-bit Subtract the immediate from the 2 Byte
data accumulator
9 SBI 8-bit Subtract immediate from accumulator 2 Byte
1 data with borrow
INR R/M Increment the register or the memory by 1 Byte
0 1
1 INX Rp Increment register pair by 1 1 Byte
1
1 DCR R/M Decrement the register or the memory by 1 Byte
2 1
1 DCX Rp Decrement register pair by 1 1 Byte
3
1 DAA Decimal adjust accumulator 1 Byte
4
ADD: Add register/memory to accumulator
Register
s
A
B 02 08 C
D E +
H 02
04 0B
03 L 02 03
04 0B
DAD B
SUB: Subtract register/memory from
accumulator
Instruction Description Example
Opcod Operan
e d
SUB R/M • The contents of the operand SUB B ; A=A-B
(register or memory) is SUB M ; A=A-M[HL]
subtracted from the contents
of the accumulator, and the
result is stored in the
accumulator.
• If the operand is a memory
location, its location is
specified by the contents of
the HL registers.
• All flags are modified to
reflect the result of the
subtraction.
SBB: Subtract source & borrow from
accumulator
Register
s 1 11
A 2 001 1010
A 0
B C +0000 01
10
D E 0 01 1 0000
H L
Valid BCD
number
3
0
1 ADD R/M Add register or memory, to the 1 Byte
accumulator
2 ADC R/M Add register to the accumulator with 1 Byte
carry
3 ADI 8-bit Add the immediate to the accumulator 2 Byte
Arithmetic Instructions
4 data
ACI 8-bit Add the immediate to the accumulator 2 Byte
data with carry
5 DAD R p
Add the register pair to H and L registers 1 Byte
6 SUB R/M Subtract the register/memory from 1 Byte
accumulator
7 SBB R/M Subtract the source and borrow from 1 Byte
accumulator
8 SUI 8-bit Subtract the immediate from the 2 Byte
data accumulator
9 SBI 8-bit Subtract immediate from accumulator 2 Byte
1 data with borrow
INR R/M Increment the register or the memory by 1 Byte
0 1
1 INX Rp Increment register pair by 1 1 Byte
1
1 DCR R/M Decrement the register or the memory by 1 Byte
2 1
1 DCX Rp Decrement register pair by 1 1 Byte
3
1 DAA Decimal adjust accumulator 1 Byte
4
Classification of 8085 Instructions
Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Branch Instructions
1 JMP Jump unconditionally 3 Byte
2 JC Jump on carry 3 Byte
3 JNC Jump on no carry 3 Byte
4 JP Jump on positive 3 Byte
5 JM Jump on minus 3 Byte
6 JZ Jump on zero 3 Byte
7 JNZ Jump on no zero 3 Byte
8 JPE Jump on parity even 3 Byte
9 JPO Jump on parity odd 3 Byte
1 CALL Call unconditionally 3 Byte
Branch Instructions
0
1 CC Call on carry 3 Byte
1
1 CNC Call on no carry 3 Byte
2
1 CP Call on positive 3 Byte
3
1 CM Call on minus 3 Byte
4
1 CZ Call on zero 3 Byte
5
1 CNZ Call on no zero 3 Byte
6
1 CPE Call on parity even 3 Byte
7
1 CPO Call on parity odd 3 Byte
8
1 RET Return unconditionally 1 Byte
9
JMP: Jump unconditionally
Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Logical & Bit
Manipulation
Instructions
1 CMP Compare register or memory with accumulator 1 Byte
RLC
A:Accumulator
D7 D6 D5 D4 D3 D2 D1 D0
1 0 1 0 1 0 0 0
0 1 0 1 0 0 0 1
A:Accumulator
D7 D6 D5 D4 D3 D2 D1 D0
1 0 1 0 1 0 0 0
1 0 1 0 1 0 0
CY
RAL: Rotate accumulator left through carry
A:Accumulator
D7 D6 D5 D4 D3 D2 D1 D0
1 0 1 0 1 0 0 0
0 1 0 1 0 0 0
CY
0
Rotate the accumulator left through carry
RAR: Rotate accumulator right through carry
A:Accumulator
D7 D6 D5 D4 D3 D2 D1 D0
1 0 1 0 1 0 0 0
1 0 1 0 1 0 0
CY
1
CMA: Complement accumulator
A 2A CMA
001 1010
0
1100101
1
D 5
Logical Instruction
CMC: Complement Carry
Instruction Description Example
Opcod Operan
e d CMC
CMC None The Carry flag is complemented. No
other flags are affected.
Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Control Instructions
Control Instructions
1 NOP No operation 1 Byte
2 HLT Halt 1 Byte
3 DI Disable interrupts 1 Byte
4 EI Enable interrupts 1 Byte
5 RIM Read interrupt mask 1 Byte
6 SIM Set interrupt mask 1 Byte
Control Instructions
Instruction Description Example
Opcod Operan
e d NOP
NOP None • No operation is performed. The
instruction is fetched and
decoded. However no operation is
executed.
• It is used to increase processing
time of execution.
• 1 CPU cycle is "wasted" to
HLT None execute
The CPU afinishes
NOP instruction.
executing the HLT
current instruction and stops further
execution. An interrupt or reset is
necessary to exit from the halt state.
Control Instructions
A:Accumulator
D7 D6 D5 D4 D3 D2 D1 D0
SOD SDE X R7.5 MS M7. M6.
E 5 5 M5.
Serial Output Reset 5
Data To set mask for RST7.5,RST
RST 7.5 if
It is used to 6.5, RST5.5
D4=1
transmit o/p Interrupt Masked if bit=1
bits. Serial Data
Ignored if D6=0 Enable
If D6=1; bit D7 is
output to SOD Mask Set Enable: if 0, bits 0-2
Latch are ignored
if 1, mask is set
SIM Instruction
D7 D6 D5 D4 D3 D2 D1 D0
Accumul SOD SDE X R7.5 MS M7. M6. M5.
ator E 5 5 5
Example 1: MVI A,08H
SIM
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 1 0 0 0
RIM: Read Interrupt Mask
Instruction Description Example
Opcod Operan
e d RIM
RIM None
This is a multipurpose instruction
used to
1. Read the status of interrupts 7.5,
6.5, 5.5
2. Read serial data input bit.
A:AccumulatorIt reads eight bits from accumulator
D7 withD6 following
D5 Dinterpretations.
4 D3 D2 D1 D0
SID I7 I6 I5 IE 7. 6. 5.
5 5 5
To To identify pending To read interrupt
receive interrupts mask
serial 1=pending interrupt Interrupt Masked if
data Interrupt Enable
0=no pending interrupt Flag: 1=enable;
bit=1
0=disable
Control Instructions
1 NOP No operation 1 Byte
2 HLT Halt 1 Byte
3 DI Disable interrupts 1 Byte
4 EI Enable interrupts 1 Byte
5 RIM Read interrupt mask 1 Byte
6 SIM Set interrupt mask 1 Byte
References
Book: Microprocessor Architecture, Programming, and Applications with
the 8085, Ramesh S. Gaonkar Pub: Penram International
Mobile 8085 and 8086 Microprocessor Opcodes app from Play Store:
Applicatio http://tiny.cc/aopcodes
n
Thank You