Microprocessor Unit 3
Microprocessor Unit 3
(102045610)
MODULE 3
INSTRUCTION SET AND ASSEMBLY LANGUAGE
PROGRAMMING
Module 3
• Classification of instructions
• Addressing Modes
• 8085 Instruction Set, Instruction And Data Formats
• Writing 8085 assembly language programs with decision,making and looping
using data transfer, arithmetic, logical and branch instructions,
• Timing diagram of instructions
2
Hierarchy of
Languages Application
Program
Machine Independent
High Level High Level
Language Language
Machine Low Level Language
Specific Assembly
Language
MOV • Assembly
1100 Machine language
BL,05h
1011 Language is a
ADD CL 0100
1100
MUL BH 1111
1110
Micro Program low-level • Native to a
Control programming processor:
language executed
Hardware designed directly by
for a hardware
specific • Instructions
type of processor. consist of
3
• Uses symbolic binary code: 1s
3
Compilers and
Assemblers
High Level Language
Compile
r
Machine Language
Assemblers translates assembly code to machine
code
Compilers translate high-level programs to machine code
either directly, or Indirectly via an assembler
4 4
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).
5 5
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.
6 6
Instruction Fields
Opcode Operand
MOV Rd,
Rs M,
Rs R,
M
Rd → Destination
Register Rs → Source
Register
M → Memory
Translating
Languages
English: Sum of A and B
High-Level Language: A + B
8 8
Advantages of High-Level
Languages
• Program development is faster
• High-level statements: fewer instructions to code.
• Program maintenance is easier
• As Higher Level Language contains fewer instruction code.
• Programs are portable
• Contain few machine-dependent details.
• Can be used with little or no modifications on different
machines.
• Compiler translates to the target machine language.
9 9
Why to Learn Assembly
Language?
• Accessibility to system hardware
• Assembly Language is useful for implementing system
software.
• It is also useful for small embedded system applications.
• It is helpful for
• Compiler writing
• Programming microcontrollers
• Device drivers
• System design
• Low-level numeric routines 10 10
Why to Learn Assembly
Language?
• Writing assembly programs gives the computer designer, deep
understanding of the instruction set and how todesign.
• To be able to write compilers for HLL (Higher Level Language), we need to
be expert with the machine language. Assembly programming provides such
experience.
11 11
Assembly Language Programming Tools
1. Assembler
2. Linker
3. Debugger
4. Editor
12 12
Assemble
r• An assembler is a program that converts programs written in assembly language
into
object files(machine language).
• Popular assemblers have emerged over the years for the Intel family of
processors. These include …
• TASM (Turbo Assembler from Borland).
• NASM (Net wide Assembler for both Windows and Linux), and
• GNU assembler distributed by the free software foundation.
13 13
Linker
• A linker program is required to produce executablefiles.
• It combines program's object file created by the assembler with other
object files and link libraries, to produces a single executableprogram.
14
Assembly Language Programming Tools
Assemble and Link
Process
Source Object
File Assemble File
r
16 16
Editor
• Allows to create assembly language source files.
• Some editors provide syntax highlighting features and can be
customized as per programming environment.
17
Classification of 8085
Instructions
19 19
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
Opcode Operand
20 20
Classification of 8085
instructions
General
Terms
R 8085 8-bit register (A, B, C, D, E, H, L)
M Memory
Rs Register Source
Rd Register Destination
Rp Register Pair (BC, DE, HL)
21 21
One-byte
Instruction
One-byte instructions includes Opcode and Operand in the same
byte.
Instruction Binary Code Hexa Code
Opcode Operand
MOV C,A 0100 1111 4FH
ADD B 1000 0000 80H
CMA 0010 1111 2FH
22 22
List of one-byte
Instructions
Sr. Instruction Sr. Instruction Sr. Instruction Sr. Instruction
1 MOV dest.,src 13 SBB R/M 25 RNZ 37 CMA
2 LDAX RP (B/D) 14 INR R/M 26 RPE 38 CMC
3 STAX RP 15 INX RP 27 RPO 39 STC
4 XCHG 16 DCR R/M 28 RST 0-7 40 NOP
5 SPHL 17 DCX RP 29 CMP R/M 41 HLT
6 XTHL 18 DAA 30 ANA R/M 42 DI
7 PUSH RP 19 RET 31 XRA R/M 43 EI
8 POP RP 20 RC 32 ORA R/M 44 RIM
9 ADD R/M 21 RNC 33 RLC 45 SIM
10 ADC R/M 22 RP 34 RRC
11 DAD 23 RM 35 RAL
12 SUB R/M 24 RZ 36 RAR
23 23
Two-byte
Instruction
In two-byte instruction,
1st Byte : Specifies Opcode
2nd Byte: Specifies
Operand
Instruction Binary Code Hexa Code
Opcode Operand
MVI A,32H 0011 1110 3E: 1st Byte
0011 0010 32: 2nd Byte
MVI B,F2H 0011 1110 3E: 1st Byte
1111 0010 F2: 2nd Byte
IN 0AH 1101 1011 DB: 1st Byte
0000 1010 0A: 2nd Byte
24
List of two-byte
Instructions Sr. Instruction
1 MVI destination,8-bit data
2 OUT 8-bit port address
3 IN 8-bit port address
4 ADI 8-bit data
5 ACI 8-bit data
6 SUI 8-bit data
7 SBI 8-bit data
8 CPI 8-bit data
9 ANI 8-bit data
10 XRI 8-bit data
11 ORI 8-bit data
25 25
Three-byte
Instruction
In three-byte instruction,
1st Byte: Specifies Opcode
2nd Byte: Specifies lower order 8-bit
Byte: Specifies higher order 8-bit
address
3rd
address
26 26
List of three-byte
Instructions
Sr. Instruction Sr. Instruction
1 LDA 16-bit address 13 JPE 16-bit address
2 LXI Rp, 16-bit data 14 JPO 16-bit address
3 LHLD 16-bit address 15 CALL 16-bit address
4 STA 16-bit address 16 CC 16-bit address
5 SHLD 16-bit address 17 CNC 16-bit address
6 JMP 16-bit address 18 CP 16-bit address
7 JC 16-bit address 19 CM 16-bit address
8 JNC 16-bit address 20 CZ 16-bit address
9 JP 16-bit address 21 CNZ 16-bit address
10 JM 16-bit address 22 CPE 16-bit address
11 JZ 16-bit address 23 CPO 16-bit address
12 JNZ 16-bit address
27
27
Instruction Set of 8085
• An instruction is a binary pattern designed
insidea microprocessor to perform a specific
function.
• T h e entire group of instructions that a
microprocessor supports is called Instruction
Set.
• 8085 has 246 instructions.
•
Data Transfer Instruction
•
Arithmetic Instructions
•
Logical Instructions
•
Branching Instructions
•
Control Instructions
1.Data Transfer Instructions
•
These instructions move data between
registers, or between memory and
registers.
•
These instructions copy data from source
to destination(without changing the
original data ).
MOV-Copy from source to destination
Opcode Operand
Rd,
MO Rs
V M, Rs
Rd,
• T h i s instruction copies the contents of the source
M
register into the destination register. (contents of the
source register are not altered)
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
D E MOV C,M
D E
H 20 L 50 40 H 20 L 50 40
MVI-Move immediate 8-
bit
Opcode Operand
MV Rd,
Data
I M, Data
• T h e 8-bit data is stored in the destination
registeror memory.
•
Example: MVI B, 60H or MVI M, 40H
BEFORE EXECUTION AFTER EXECUTION
A F A F
B C MVI B 60 C
D E B,60H D E
H L H L
204FH 204F
HL=2050 HL=2050 40
MVI
2051H M,40H 2051H
LDA-Load
accumulator
Opcode Operand
LD 16-bit address
A
• T h e contents of a memory location, specified by
a16- bit address in the operand, are copied to the
accumulator.
•
Example: LDA 2000H
BEFORE EXECUTION AFTER EXECUTION
A
A
30
LDA 30
2000H 30
2000H
2000H
LDAX-Load accumulator
indirect
Opcode Operand
LDA B/D Register
Pair
X
Example: LDAX
•
D
BEFORE EXECUTION AFTER EXECUTION
A F A 80
B C B F C 80
2030H 80 2030H
LDAX D
D 20 D 20 E
E 30
30
LXI-Load register pair
immediate
Opcode Operand
LX Reg. pair, 16-bit
data
I
•
This instruction loads 16-bit data in the register pair.
•
Example: LXI H, 2030 H
BEFORE EXECUTION AFTER EXECUTION
A F A 80 F
B C B C
2030H 30 9030H 50
LXI
H L H, H 90 L 30
2031H 90 2030
M=50
LHLD-Load H and L registers
directOpcode Operand
LHL 16-bit address
D
•
Example: LHLD 2030 H
BEFORE EXECUTION AFTER EXECUTION
A F A 80 F
B C B C
2030H 00 8500H 60
LHLD
H L 85 H 85 L 00
2030
M=60
STA-Store accumulator direct
Opcode Operand
ST 16-bit address
A
•
T h e contents of accumulator are copied
intothe memory location specified by the
operand.
• E x ample: STA
2000 H
BEFORE EXECUTION AFTER EXECUTION
A A
50
50
STA 50
2000H 2000H
2000H
STAX-Store accumulator indirect
Opcode Operand
STA Reg.
X pair
•
T h e contents of accumulator are copied into the
memory location specified by the contents of the
register pair.
•
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
•
Example: SHLD 2550H
BEFORE EXECUTION AFTER EXECUTION
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 40 D 70 E 80
E
XCHG
H 70 80 H 20 L 40
L
SPHL-Copy H and L registers to the
stack pointer
Opcode Operand
SPH None
L
•
T h i s instruction loads the contents of H-L
pairinto SP.
•
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 H L
40 2701H 60 50
30
60 2701H
XTHL
2702H
2702H
Opcode Operand Description
PCHL None Load program counter with H-
L contents
•
Example: PCHL
PUSH-Push register pair onto stack
Opcode Operand
PUSH Reg. pair
•
Example: PUSH B
PUSH
H
POP- Pop stack to register pair
Opcode Operand
POP Reg. pair
•
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
•
T h e contents of accumulator are copied into
theI/O port.
• E x ample:
OUT 78H
BEFORE EXECUTION
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
Addition
• A n y 8-bit number, or the contents of register, or
the contents of memory location can be added to
the contents of accumulator.
•
BEFORE EXECUTION AFTER EXECUTION
A
04 A. 09
B C B. C 05
05
D E
ADD C D E
H L
H L
A=A+C 04+05=09
BEFORE EXECUTION
AFTER EXECUTION
A 04
ADD M A 14
B C B C
D E D E
H 20
L
50
10 A=A+M H 20
L
50 10
CY
01
A 50 A
B C
56
B C 20
05 ADC C D E
D E A=A+C+CY H L
H L
50+05+01=56
BEFORE EXECUTION AFTER EXECUTION
CY 1
A 06 2050H 30 ADC M A 37 2050H 30
H 20 L 50
A=A+M+CY
H 20 50
L
AD
I
Opcode Operand Description
ADI 8-bit data Add immediate to accumulator
•
Example: ADI 45 H
BEFORE EXECUTION AFTER EXECUTION
A 03 ADI 05H A 08
A=A+DATA(8)
03+05=08
•
Example: ACI 45 H
BEFORE EXECUTION AFTER EXECUTION
CY 1 ACI 20H
A 05 A=A+DATA A 26
(8)+CY 05+20+1=26
DAD
Opcode Operand Description
DAD Reg. pair Add register pair to H-L pair
•
Example: DAD B or DAD D
BEFORE EXECUTION AFTER EXECUTION
D 12 E 34 D 12 E 34
H 23 L 45 DAD D H 35 L 79
1234
2345
DAD HL=HL+DE
+ D HL=HL+BC
Subtraction
• A n y 8-bit number, or the contents of
register,or the contents of memory location can
be subtracted from the contents of accumulator.
•
Example: SUB B or SUB M
BEFORE EXECUTION AFTER EXECUTION
A
09 A. 05
B C B. C 04
04
D E
SUB C D E
H L A=A- H L
C 09-04=05
BEFORE EXECUTION
AFTER EXECUTION
A 14
SUB M A 04
B
D
C
E
A=A- B
D
C
E
10 M
H 20 50 H 20 50 10
L L
2050 14-10=04 2050
SB
B
Opcode Operand Description
SBB R Subtract register or memory
from accumulator with borrow
M
• The contents of the register or memory location and Borrow Flag (i.e.
CY) are subtracted from the contents of the accumulator.
CY
01
A 08 A
B C
02
B C 05
05
D E
SBB C D E
H L
H L A=A-C-CY
08-05-01=02
CY 1
A 06 2050H 02 SBB M A 03 2050H 02
H 20 L 50 A=A-M-CY H 20 50
L
SU
I
Opcode Operand Description
•
Example: SUI 05H
BEFORE EXECUTION AFTER EXECUTION
A 08 SUI 05H A 03
A=A-DATA(8)
08-05=03
SB
IOpcode Operand Description
SB 8-bit data Subtract immediate from
I accumulator with borrow
•
Example: SBI 45 H collected by C.Gokul
BEFORE EXECUTION AFTER EXECUTION
CY
1 SBI 20H
A 25 A=A-DATA A 04
(8)-CY
25-20-01=04
Increment / Decrement
• T h e 8-bit contents of a register or a
memory location can be incremented or
decremented by 1.
•
BEFORE EXECUTION AFTER EXECUTION
A
A A
B
B 10
1 C
C INR B B 11 C
0 E
D
D
H
H
E
L
L
R=R+1 D
H
E
L
10+1=11
BEFORE EXECUTION AFTER EXECUTION
H L
2050H 10 H L
11 2050H
20 50
INR M 20 50
M=M+1 10+1=11
IN
X
Opcode Operand Description
INX R Increment register pair by 1
•
Example: INX H or INX B or INX D
BEFORE EXECUTION AFTER EXECUTION
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
•
BEFORE EXECUTION AFTER EXECUTION
A A
B C B C
D E 20 DCR E D E 19
H L R=R- H L
1 20-1=19
BEFORE EXECUTION AFTER EXECUTION
H L
H L 2050H
21 20 50 2050H 20
20 50 DCR M
M=M-1 21-1=20
DCX
•
Example: DCX H or DCX B or DCX D
BEFORE EXECUTION AFTER EXECUTION
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.
collected by C.Gokul
BEFORE EXECUTION 1010 1010=AAH AFTER EXECUTION
0000 1111=0FH
CY AC CY 0
0000 1010=0AH AC
AA AA 1
B 0F C B 0F
B 1 C ANA B 0AC
D 0 E A
D E
D E A=A and
H
H L
L H L
R
0101 0101=55H
CY AC 1011 CY 0
0011=B3H AC
B3 0001 0001=11H 1 B3
A 55 2050H A 11 2050H
H 20 50 ANA M H 20 L
L
A=A and 50
Opcode Operand Description
ANI 8-bit data Logical AND immediate with
accumulator
1011 0011=B3H
0011 1111=3FH
0011 0011=33H
CY AC 1
CY AC
ANI 3FH 0
A B3 A=A and DATA(8) A 33
Opcode Operand Description
ORA R Logical OR register or memory with
M accumulator
• The contents of the accumulator are logically ORed with the contents of the
register or memory.
CY AC CY 0
AC 0
ORA B
A=A or
R
A AA A BA
B 12 B 12
D E D E
C C
H L H L
0101 0101=55H
1011
BEFORE EXECUTION 0011=B3H AFTER EXECUTION
1111 0111=F7H
CY AC CY AC
0
0
ORA M
B3 A=A or B3
A 55 2050H A F7 2050H
H 20 50 M H 20 50
L L
Opcode Operand Description
CY AC
CY AC
ORI 08H 0 0
A B3 A=A or
A BB
DATA(8)
Opcode Operand Description
CY AC CY 0
AC
0
A AA A 87
B 1 C 2D B C 2D
D 0 E XRA C D E
H L A=A xor H L
R
0101 0101=55H
BEFORE EXECUTION 1011 AFTER EXECUTION
0011=B3H
1110 0110=E6H
CY AC CY 0
2050H
B3 XRA M AC
0 2050H B3
A 55 A E6
H 20 50 A=A xor H 20 50
L L
M
Opcode Operand Description
CY AC
CY AC
XRI 39H 0 0
A B3 A=A xor
A 8A
DATA(8)
Compare
• A ny 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:
CY Z ZF=1 CY
ZF 1
A<M: CY=1
A B8
B8 0
A
B8
2050H B8
CMP 2050H
H 20 50 H 20
L M A- L 50
Opcode Operand Description
A BA
A- A BA
DATA
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 B0
B1
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 B0
B1
Complement
• T h e contents of accumulator can
be complemented.
A 00 A FF
Opcode Operand Description
CMC None Complement carry
• T h e Carry flag is
complemented.
• No other flags are affected.
•
Example: CMC => c=c’ AFTER EXECUTION
BEFORE EXECUTION
C 00 C FF
Opcode Operand Description
STC None Set carry
S-set C-clear
(1) (0)
• T h e branch group instructions allows
the microprocessor to change the
sequence of program either
conditionally or under certain test
conditions.The group includes,
• ( 1 ) Jump instructions,
• ( 2 ) Call and Return instructions,
• ( 3 ) Restart instructions,
Opcode Operand Description
JMP 16-bit Jump unconditionally
address
•
T h e program sequence is transferred to
thememory location specified by the 16-bit address
given in the operand.
•
Example: JMP 2034 H.
Opcode Operand Description
•
T h e program sequence is transferred to
thememory location specified by the 16-bit address
given in the operand based on the specified flag of
the PSW.
•
Example: JZ 2034 H.
Jump Conditionally
Opcode Description Status Flags
JC Jump if Carry CY = 1
•
T h e program sequence is transferred to
thememory location specified by the 16-bit
address given in the operand.
•
Before the transfer, the address of the next instruction
after CALL (the contents of the program counter) is
pushed onto the stack.
• Example: CALL 2034 . H
Call Conditionally
Opcode Description Status Flags
CC Call if Carry CY = 1
•
T h e RST instruction jumps the control to one of
eight memory locations depending upon the
number.
•
These are used as software instructions in a
program to transfer program execution to one of
the eight locations.
•
Instruction Code Vector Address
RST 0 0*8=0000H
RST 1 1*8=0008H
RST 2 2*8=0010H
RST 3 3*8=0018H
RST 4 4*8=0020H
RST 5 5*8=0028H
RST 6 6*8=0030H
RST 7 7*8=0038H
5. Control Instructions
•
T h e control instructions control the
operation of microprocessor.
• No operation is performed.
• T h e instruction is fetched and decoded
butno operation is executed.
•
Example: NOP
Opcode Operand Description
HLT None Halt
Indirect Addressing
Mode
A ←
ADD B ; A+B
DAD H ; HL ←
HL+RP
SPHL
PCHL
▪ Comment is optional.
Example:
MOV A,B ; Move data from B to A
Χ
MOV A,B ; send data to accumulator for processing
√
B <- ACh
YES
Carry? Increment Result
NO
Display Result
End
160
8085 Assembly Program
Write a program to add two 8-bit number with carry
1. MVI A, ABh
2. MVI B, ACh
3. ADD B ; A=A+B
4. JC L1 ; if CY=1
5. JNC L2 ; if CY=0
7. L2:HLT
161
162
8085 Assembly Program
Exercise
Write a program to subtract two 8-bit number
163
164
165
166
8085 Assembly Program
Write a program to exchange the data at 1501H & 1502H memory location.
1. LDA 1501 ;load A <- M[1501]
2. MOV B,A ; B <- A
167
8085 Assembly Program
Write a program for reverse counter and display result in output port1
Initialize counter
A <- 0Ah
C <- 00h
Decrement Counter
YES
Counter ≠0
No
Halt
168
8085 Assembly Program
Write a program for reverse counter and display result in output port1
1. MVI A,0A
2. MVI C,00
3. L1: OUT 01 ; display content of accumulator
4. DCR A ; decrement accumulator
5. CMP C ; compare C with accumulator
6. JNZ L1 ; if Z ≠ 0
7. JZ L2 ; if Z = 0
8. L2: HLT
169
8085 Assembly Program
Write a program to Set PSW (Accumulator & 5 Flags)
1. LXI H, FFFF
2. PUSH H
4. LXI H, 0000
5. PUSH H
6. POP PSW
170 170
8085 Assembly Program
Exercise
1. Memory Location 2050H holds databyte F7H. Write an instruction to transfer data byte to
Accumulator using 3 different Opcodes: MOV, LDAX, LDA
171 171
172
173
8085 Assembly Program
Write a program to add the content of M[2040H] with A,
Assume
A=30H
M[2040]=68H
M[2041]=7FH
PROGRAM:
1. LXI H,2040
2. ADD M ; A=A+M[2040]
3. INX H ; HL=HL+1
4. SUB M ; A=A-M[2041]
5. HLT
174
8085 Assembly Program
WAP to add 10 bytes starting from 3001h to 300Ah. Use register B to save any carries generated, while
adding data bytes. Display result to output port 01h and store at M[300B].
Registers Memory
03 3001
A Result 04 3002
09 .
B Carry Counter C 06 .
D E D2
.
08
H L F7
A5
02
E3 300A
175
8085 Assembly Program
WAP to find largest number among 10 bytes starting from 3001h to 300Ah. Display result to output port 01h
and store at M[300B].
Registers Memory
03 3001
A Result 04 3002
09 .
B Counter C 06 .
D E D2
.
08
H L F7
A5
02
E3 300A
177
Start 1. MVI A,00
2. MVI C,0A
WAP to find largest number from 3001h to 300Ah.
180 180
8085 Assembly Program
WAP to find odd and even numbers in given array of 10 elements starting from
2001H and perform addition of Odd and Even number respectively.
Data=05h RRC
A:Accumulator
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 0 1 0 1
0 0 0 0 0 1 0
CY
181 181
1. MVI B,00;StoreODD
Start
2. MVI D,00;StoreEVEN
3. MVI C,0AH;Counter
B <- 00h 4. LXI H,0001;Pointer
D<- 00h 5. L1: MOV A,M
WAP to find sum of ODD and EVEN number.
NO
Pointer=Pointer + 1
Is YES
Counter=Counter - 1 Counter= End 182
0 182
8085 Assembly Program
Exercise
• An array of Ten numbers is stored from memory location 2000H onwards. Write an 8085 assembly
language program to separate out and store the EVEN and ODD numbers on new arrays from 2100H and
2200H, respectively.
• WAP to find number of 1’s and 0’s of 8-bit number stored at M[2010]
• WAP to multiply two 8-bit numbers.
• WAP to arrange an array of 10 numbers starting from 3001 to 300A in descending order.
• WAP to eliminate duplicate entry from an array of 10 numbers.
183
184
185
186
187
Timing & Machine Cycle
for 8085 Instructions
Operation M/C
Fetch (F) 1
Memory Read (MEMR) 1
Memory Write (MEMW) 1
I/O Read (IOR) 1
I/O Write (IOW) 1
Read Immediate Data (R) 1
02 0001
A 04 0002
C 0A 0003
06 0004
B E
0F 0005
L
0 D 0006
D 0 D
0 5 0007
0 5
LHLD 0006H 03 0008
H
CLK
A
15
High order memory address Unspecified
A8
AD7 Low order
Opcode
M/m addr.
AD0
ALE
IO/M
RD
Memory read cycle
CLK
A
15
High order memory address
A8
AD7 Low order
Data from memory
M/m addr. S1 S0 Mode
0 0 HLT
AD0
0 1 WRITE
1 0 READ
ALE
IO/M
S0 IO/M=0, S1=1 , S0=0
S1
RD
Memory write cycle
CLK
A
15
High order memory address
A8
AD7 Low order Data from
M/m addr. Microprocessor S1 S0 Mode
0 0 HLT
AD0
0 1 WRITE
1 0 READ
ALE
IO/M
S1 IO/M=0, S1=0 , S0=1
S0
WR
I/O read cycle
CLK
A
15
High order I/O address
A8
AD7 Low order
I/O
I/O addr. S1 S0 Mode
data 0 0 HLT
AD0
0 1 WRITE
1 0 READ
ALE
S0
IO/M=1, S1=1 , S0=0
IO/M
S1
RD
I/O write cycle
CLK
A
15
High order I/O address
A8
AD7 Low order Data from
I/O addr. Microprocessor S1 S0 Mode
0 0 HLT
AD0
0 1 WRITE
1 0 READ
ALE
S1
IO/M=1, S1=0 , S0=1
IO/M
S0
WR
Timing Diagram : MOV
Opcode Fetch Memory Read
B,M
T1 T2 T3 T4 T5 T6 T7
CLK
ALE
IO/M
RD
Timing Diagram : MVI A, 32H
Opcode Fetch Memory Read
T1 T2 T3 T4 T5 T6 T7
CLK
ALE
IO/M
RD
Calculate Execution time of MVI A,32H
Given: Clock Frequency (f) = 2 MHz
Calculation:
1
Step-1: T-state = clock period = = = 0.5
1 μsec
Step-2: Execution time for Opcode
𝑓
Fetch
= 4T x 0.5 = 2μsec
2
Step-3: Execution time for Memory Read
= 3T x 0.5 = 1.5μsec
Step-4: Execution time for Instruction
= (4T + 3T) x 0.5
= 7T x 0.5
= 3.5μsec
Timing Diagram : OUT
02H
Opcode Fetch Memory Read I/O Write
T1 T2 T3 T4 T1 T2 T3 T1 T2 T3
CLK
ALE
IO/M
RD
IOW
Timing Diagram : IN 02H
CLK
ALE
IO/M
RD
IOR