Professional Documents
Culture Documents
Vipin Kizheppatt 17/01/2024: 8085 Microprocessor
Vipin Kizheppatt 17/01/2024: 8085 Microprocessor
Pinout
3
Overview
4
Overview
5
Overview
Lower 8 bits of
Address, multiplexed Upper 8 bits of
with Data Address
6
Overview
Address latch enable.
Distinguishes whether
AD0-AD7 contains
valid address or not
7
Overview
8
Overview
9
Overview
Serial output
data and serial
input data
(Similar to
RS232)
10
8085-Based System Example
A Bus is a communication structure.
Physically they will be a one or a group
A7:A0
AD7:AD0 Latch of conductors. Data communication
happens on the bus based on a set of S
En rules called protocol Y
Address Bus (16-bits wide) S
ALE T
8085 Processor E
A15:A8 M
Data Bus (8-bits wide)
B
IO/M#,RD’,WR’ Control Bus U
S
Memory Memory
(ROM) (RAM)
11
8085 Assembly Level
•
Programming
Assembly-level programs are written using the
instructions of the processor that we use
• All instructions of a processor together is called
instruction set
• 8085 has 74 unique instructions in its instruction set
13
8085 Programming Model
• Along with instructions, we should also need
to know the internal processor register
details to write assembly code
• Programming model is an abstract model of
the processor describing only the required
architecture of the processor from a
programmer’s (software engineers)
perspective
• It doesn’t describe the actual hardware
implementation of the processor
• Low-level hardware implementation details
called the micro-architecture is of interest
to hardware designers 14
8085 Programming Model
B C
(8) (8)
D E
(8) (8)
H L
(8) (8)
15
8085 Programming Model
6 General purpose
registers (B,C,D,E,H,L)
Accumulator (A) Flag Register
(8)
All are 8-bits wide
B C
(8) (8)
Can combine into
D
(8) E (8) pairs to make 16-bit
registers. Valid
H (8) L combinations are BC,
(8)
DE, HL
Stack Pointer (SP)
(16)
Program Counter (PC)
(16)
16
8085 Programming Model
17
8085 Programming Model
18
8085 Programming Model
7 6 5 4 3 2 1 0
S Z AC P CY
Auxiliary Carry: Set when there is auxiliary carry (carry from D3 to D4)
19
8085 Programming Model
21
Instruction classification
• Instructions can be classified based on
different criteria such as
(a) the type of operation the instruction does
(Eg: arithmetic instruction, data transfer
instruction etc)
(b) size of instruction (one byte, two byte etc.)
(c) based on addressing mode (register
addressing, immediate addressing etc.)
Every instruction has an operation code
(opcode) and optional one or more operands
Eg MOV A,B
Opcode Operands 22
Instruction classification
8085 instruction set
Arithmetic Branching
23
Data Transfer Instructions
• Instructions to copy data between registers
or registers and memory, registers and
input/output etc.
• Data transfer instructions will have a source
location and a destination location
• Here data is copies meaning the data at the
source location is preserved
• In 8085 data transfer instructions do not
affect any flag bits
• General instruction format
Opcode
Destination, Source
24
Data Transfer Instructions
Opcode Operand(s) Size Description
25
Data Transfer Instructions
Opcode Operand(s) Size Description
26
Arithmetic Instructions
• Instructions to perform arithmetic
operations such as addition and subtraction
• Accumulator (A) acts as one of the sources
and destination for most of the arithmetic
operations
• Arithmetic operations affect the bits in the
flag register
27
Arithmetic Instructions
Opcode Operand(s) Size Description
28
Arithmetic Instructions
Opcode Operand(s) Size Description
29
Arithmetic Instructions
Opcode Operand(s) Size Description
31
Arithmetic Instructions
Opcode Operand(s) Size Description
32
Arithmetic Instructions
Opcode Operand(s) Size Description
33
Logical Instructions
• Instructions to perform logical operations
such as AND OR etc.
• Accumulator (A) acts as one of the sources
and destination for most of the arithmetic
operations
• logical operations affect the bits in the flag
register
34
Logical Instructions
Opcode Operand(s) Size Description
35
Logical Instructions
Opcode Operand(s) Size Description
36
Logical Instructions
Opcode Operand(s) Size Description
37
Logical Instructions
Opcode Operand(s) Size Description
38
Logical Instructions
Opcode Operand(s) Size Description
39
Branch Instructions
• Instructions used to implement conditional
statements in the program (similar to if else
conditions in high-level programs)
• The change the sequence of program
• If there are no branch instructions, your
program will be always executing
sequentially one instruction after the other
• Since the next instruction for execution is
selected by program counter (instruction
pointer), branch instructions are indirect
way to manipulate it
• Branch instructions extensively use the flag
bits 40
Branch Instructions
Opcode Operand(s) Size Description
41
Branch Instructions
Opcode Operand(s) Size Description
JNZ 16-bit address 3 Bytes Jump if zero flag bit is not set
(Z=0) to the address specified
JP 16-bit address 3 Bytes Jump if positive (S=0, D7=0)
to the address specified
JM 16-bit address 3 Bytes Jump if minus (S=1, D7=1) to
the address specified
JPE 16-bit address 3 Bytes Jump if even parity (P=1) to
the address specified
JPO 16-bit address 3 Bytes Jump if odd parity (P=0) to
the address specified
42
Control Instructions
• Used to control the processor
Opcode Operand(s) Size Description
43
Programming Flow
Eg: Write an assembly level program (ALP) to
add the numbers 20H and 30H and store the
result memory location 1000H
– Step 1: Decide the algorithm you are going to
use (Algorithm you can think in terms of flow-
chart, pseudo code or in natural language)
– Find the instructions to implement each step
of the algorithm
– Assemble your code (either manually or
using an assembler)
– Store the program in processor memory
– Reset the processor and let it execute
– Verify the program output 44
Programming Flow
Eg: Write an assembly level program (ALP) to
add the numbers 20H and 30H and store the
result memory locationStart
1000H
Stop
45
Programming Flow
MVI A,20H
MVI A,0H
ADI A,20H
Store 20H in a register XRA A
ADI A,20H
MVI H,20H
MVI L,00H
MVI M,20H
LDA 2000H
MVI A,0
INR A
CPI 20
JNZ 0002 46
Programming Flow
Eg: Write an assembly level program (ALP) to
add the numbers 20H and 30H and store the
result memory location
Start 1000H
Stop HLT 47
Programming Flow
Hand assembling
MVI A,20H
MVI B,30H
ADD B
STA 1000H
HLT
MVI A 00111110 0x3E
MVI A,20H 0x3E 0x20 48
Programming Flow
MVI B,30H 06 30
ADD B 80
STA 1000H 32 00 10
HLT 76
Programming Flow
Latch
00111110 (3EH) 0
8085
Processor 00100000 (20H) 1
00000110 (06H) 2
00110000 (30H) 3
10000000 (80H) 4
Memory Memory Latch(32H)
00110010 5
(ROM) (RAM)
00000000 (00H) 6
10000101 (10H) 7
01110110 (76H) 8
XX 9
XX
A
Memory
Programming Flow
Latch
FETCH
00111110 (3EH) 0
8085
Processor 00100000 (20H) 1
00000110 (06H) 2
00110000 (30H) 3
10000000 (80H) 4
Memory Memory Latch(32H)
00110010 5
(ROM) (RAM)
00000000 (00H) 6
10000101 (10H) 7
01110110 (76H) 8
XX 9
XX
A
Memory
Programming Flow
Latch
00111110 (3EH) 0
8085
Processor 00100000 (20H) 1
00000110 (06H) 2
00110000 (30H) 3
10000000 (80H) 4
Memory Memory Latch(32H)
00110010 5
3EH (ROM) (RAM)
Control logic Decodes 00000000 (00H) 6
instructions and Finds 10000101 (10H) 7
it needs to copy data
from next memory 01110110 (76H) 8
location. Increments PC XX
by 2 (instruction size) 9
XX
A
Memory
Programming Flow
Latch
00111110 (3EH) 0
8085
Processor 00100000 (20H) 1
00000110 (06H) 2
00110000 (30H) 3
10000000 (80H) 4
After Execution Memory Memory Latch(32H)
00110010 5
20 (A) Flag Register (ROM) (RAM)
00000000 (00H) 6
B C
10000101 (10H) 7
D E
01110110 (76H) 8
H L
XX 9
Stack Pointer (SP) XX
A
PC = 2 Memory
Programming Flow 00111110 (3EH) 0
00100000 (20H) 1
00000110 (06H) 2
At the end of Program 00110000 (30H) 3
10000000 (80H) 4
50 (A) 0 (Flags)
Latch(32H)
00110010 5
30 (B) C
00000000 (00H) 6
D E
10000101 (10H) 7
H L
01110110 (76H) 8
Stack Pointer (SP)
XX 9
PC = 8
XX
A
XX 9FF
Latch (50H) 1000
01010000
Memory XX 1001
Programming Flow
Eg: Write an assembly level program (ALP) to
find the sum of first 10 natural numbers. Store
final result in 0x2000 Start
Initialize a counter to 10
Decrement count by 1
No Count
== 0?
Yes
Store sum at 0x2000
Stop 55
Programming Flow
Eg: Write an assembly level program (ALP) to
find the sum of first 10 natural numbers. Store
final result in 0x2000
61
Programming Flow
main:
MVI A,0H ;Clear accumulator
MVI B,0H ;Upper byte of result
MVI H,10H
MVI L,00H
MOV C,M ;Will use C as counter
INX H
loop:
ADD M
JNC Next
INR B
Next:
DCR C
JNZ loop
STA 2000H
MOV A,B
STA 2001H
62
HLT
Addressing Modes
• Addressing modes Various formats of
specifying operands in instruction
• Immediate Addressing Mode: Operand data
is directly specified in the instruction itself
Eg: MVI A,20H
JMP 2000H
• Register Addressing Mode: Instruction uses
operand stored in a register
Eg: MOV A,B
ADD B
INR C
63
Addressing Modes
• Direct Addressing Mode: Data to be operated
is stored/to be stored in memory and that
memory address is directly specified in the
instruction
Eg: LDA 2000H
STA 1000H
• Register Indirect Addressing Mode: Address
of the operand is stored in a register pair
(such as HL or BC) and the register pair is
used in the instruction (similar to a pointer)
Eg: MOV A,M
LDAX B ; Move content of the
memory pointed by BC pair to accumulator 64
Stack Memory
• Part of main memory used to store data
temporarily during program execution
• Starting location of stack is usually
configured from the main program
• Stack is a last-in first-out memory (LIFO)
• In 8085 top of stack (address till which data
is stored) is pointed by a 16-bit register
called stack pointer
Stack Pointer (SP) Next data will be stored here 9FF
1000H
Last dataLatch
stored in stack 1000
XX 1001
65
Stack Instructions
Opcode Operand(s) Size Description
66
Stack Program Flow
9F6
LXI SP, 1000H xx (A) xx (Flags) 9F7
xx D xxE 9F9
9FA
xx H xx L
SP Latch 9FB
PC 9FC
9FD
9FE
9FF
1000
Stack Program Flow
9F6
LXI SP, 1000H xx (A) xx (Flags) 9F7
xx D xxE 9F9
9FA
xx H xx L
1000H (SP) Latch 9FB
PC 9FC
9FD
9FE
9FF
1000
Stack Program Flow
9F6
LXI SP, 1000H xx (A) xx (Flags) 9F7
LXI B, 1234H
12H (B) 34H (C) 9F8
xx D xxE 9F9
9FA
xx H xx L
1000H (SP) Latch 9FB
PC 9FC
9FD
9FE
9FF
1000
Stack Program Flow
9F6
LXI SP, 1000H xx (A) xx (Flags) 9F7
LXI B, 1234H
12H (B) 34H (C) 9F8
PUSH B
xx D xxE 9F9
9FA
xx H xx L
9FFH (SP) Latch 9FB
PC 9FC
9FD
9FE
9FF
1000
Stack Program Flow
9F6
LXI SP, 1000H xx (A) xx (Flags) 9F7
LXI B, 1234H
12H (B) 34H (C) 9F8
PUSH B
xx D xxE 9F9
9FA
xx H xx L
9FFH (SP) Latch 9FB
PC 9FC
9FD
9FE
12H 9FF
1000
Stack Program Flow
9F6
LXI SP, 1000H xx (A) xx (Flags) 9F7
LXI B, 1234H
12H (B) 34H (C) 9F8
PUSH B
xx D xxE 9F9
9FA
xx H xx L
9FEH (SP) Latch 9FB
PC 9FC
9FD
9FE
12H 9FF
1000
Stack Program Flow
9F6
LXI SP, 1000H xx (A) xx (Flags) 9F7
LXI B, 1234H
12H (B) 34H (C) 9F8
PUSH B
xx D xxE 9F9
9FA
xx H xx L
9FEH (SP) Latch 9FB
PC 9FC
9FD
34H 9FE
12H 9FF
1000
Stack Program Flow
9F6
LXI SP,1000H xx (A) xx (Flags) 9F7
LXI B,1234H
56H (B) 78H (C) 9F8
PUSH B
LXI B,5678H xx D xxE 9F9
9FA
xx H xx L
9FEH (SP) Latch 9FB
PC 9FC
9FD
34H 9FE
12H 9FF
1000
Stack Program Flow
9F6
LXI SP,1000H xx (A) xx (Flags) 9F7
LXI B,1234H
12H (B) 34H (C) 9F8
PUSH B
LXI B,5678H xx D xxE 9F9
POP B 9FA
xx H xx L
9FEH (SP) Latch 9FB
PC 9FC
9FD
34H 9FE
12H 9FF
1000
Stack Program Flow
9F6
LXI SP,1000H xx (A) xx (Flags) 9F7
LXI B,1234H
12H (B) 34H (C) 9F8
PUSH B
LXI B,5678H xx D xxE 9F9
POP B 9FA
xx H xx L
9FFH (SP) Latch 9FB
PC 9FC
9FD
34H 9FE
12H 9FF
1000
Stack Program Flow
9F6
LXI SP,1000H xx (A) xx (Flags) 9F7
LXI B,1234H
12H (B) 34H (C) 9F8
PUSH B
LXI B,5678H xx D xxE 9F9
POP B 9FA
xx H xx L
1000H (SP) Latch 9FB
PC 9FC
9FD
34H 9FE
12H 9FF
1000
Code Manipulation with Stack
PUSH B
PUSH D
Essentially swaps BC and DE pairs
POP B
POP D
MVI L,0
PUSH H Essentially clears flag register
POP PSW
78
Stack Overflow
• Since stack grows in higher address to lower
address, SP is usually initialized at
maximum memory address
• Because of the way SP works in 8085,
initializing it to 0 doesn’t cause any issue
• But what happens if you X keep on pushing
data to stack? X+1 Code grows in this direction
X+2
X+3
Latch
X+4
X+5
Stack grows in this direction
X+6
79
X+7
Subroutines
• Subroutines are like functions in high-level
languages
• They allow modular design of program
• They enable code reuse
• They helps in reducing program size
80
Subroutine Instructions
Opcode Operand(s) Size Description
81
Subroutine Program Flow
• Write a subroutine to add two 8-bit numbers
main:
LXI SP,1000H
mvi A,20H
mvi B,30H
call add
hlt
xx D xxE 9F9
9FA
xx H xx L
9FEH (SP) Latch 9FB
PC 9FC
9FD
0AH 9FE
Address of the next instruction after call is
automatically pushed to stack 00H 9FF
1000
84
Subroutines and Stack
call add 7 CD 08 00
9F6
20H( A) xx (Flags) 9F7
30H(B) XX H (C) 9F8
xx D xxE 9F9
9FA
xx H xx L
9FEH (SP) Latch 9FB
9FD
0AH 9FE
Program counter gets loaded with starting
address of subroutine and execution jumps 00H 9FF
to the subroutine 1000
85
Subroutine Program Flow
• Write a subroutine to add two 8-bit numbers
main: Address Machine Code
LXI SP,1000H 0 31 00 10
mvi A,20H 3 3E 20
mvi B,30H 5 06 30
call add 7 CD 0A 00
hlt A 76
xx D xxE 9F9
9FA
xx H xx L
1000H (SP) Latch 9FB
9FD
0AH 9FE
When RET instruction is executed, top two
bytes from stack is read and stored in PC. Thus 00H 9FF
the function returns 1000
87
Caution
• The number of push and pop operations
within a subroutine should exactly match!!
• Otherwise, you don’t know where the
function will return when the ret instruction
is executed
• When writing a subroutine, it is a good idea
to restore every register except the one
through which you are returning the value
• For this purpose, you can push every register
to stack at the beginning of subroutine and
pop them back just before returning
• Make sure the order of push or pop are
exactly opposite in this case (since stack 88is