Professional Documents
Culture Documents
1
Outline
Introduction
Organization of 8085
-Data and address bus
-Addressing memory and I/O devices
-functional organization of 8085
-registers in 8085 MP
Machine codes
Instruction formats
Addressing modes
Instruction set of 8085 2
Introduction
• The MP has a set of instructions designed to manipulate data and
communicate with peripherals
• The MP is programmed using these instructions
• The instructions are given to the MP by writing them into a
memory
• The MP:
-Reads or transfer one instruction at a time
-Performs the data manipulation indicated by the instruction
-The result can be stored in memory or sent to o/p devices such
as LEDs or other terminals
• In addition the MP can respond to external signals
-It can be interrupted, reset, or asked to wait to synchronize with
slower peripherals
3
Organization of 8085
4
The Data and Address Busses
• The data bus is 8-bits wide. i.e.8-bits(1 byte) of data can be
transferred to/from 8085 in parallel
• The address bus has 8 signal lines A8 –A15 which are
unidirectional.
•The other 8 address bits are multiplexed(time shared) with the 8
data bits.
-So, the bits AD0 –AD7are bi-directional and serve for both A0 –
A7 and D0 –D7.
-During the execution of the instruction, these lines carry the
address bits during the early part, then during the late parts of
the execution, they carry the 8 data bits.
• 8085 has a 16-bit address transmission capability. This implies a
total of 216(65536) memory locations can be addressed directly.
• Therefore we say that 8085 can directly address 64K(1k=1024)
bytes of memory. 5
Memory map and addresses
-The memory map is a picture representation of the address range and
shows where the different memory chips are located within the address
range.
6
• A memory is a circuit that can store bits- high or low, generally
voltage levels or capacity charges representing 1 or 0.
• A flip-flop or a latch is a typical basic element of memory.
• This latch, which can store one binary bit, is called a memory cell.
DIN D Q Dout I7 I0
.......
WR
EN EN WR I/p Buffer
RD
A0 R0 0000
(a) R1 0001
A1 . R2
. 0002
. .
2 16 =65,536
.
Decoder
. .
. . .
A14 . .
A15 R65,535 FFFE
Fig. R65,536 FFFF
A memory cell latch with two tri-state
Buffers (a). Each register Ri in (b) contains RD O/P Buffer
.......
8 D latches or flip-flops. The i/p and o/p
(b) O7 O0
buffers are each of 8-tri-state buffers 7
To communicate with memory, the MP should be able to:
- select a chip
- identify the register
- read from or write in to the register
The memory that is addressed by the MP (RAM or ROM) consists of
one or more LSI chips arranged to provide the designed memory
capacity.
CS WR CS
A0 RD RD
A0
A1 A1
RAM ROM
.....
Memory
.....
Memory
chip chip
2nx8 2nx8
An An
8
Addressing the I/O devices:
There are two different methods by which I/O devices can be
interfaced to 8085:
1. I/O mapped I/O mode
- treat I/O devices as distinct from the memory and assign them
addresses that do not conflict with the memory addresses.
- The signal is used to distinguish between I/O read/write
operation and memory read/write operation
- The I/O devices can be accessed during IN and OUT instructions
11
Registers in the 8085 MP
-There are several registers used during the execution
of a program
-we shall describe the size & use of each of these registers
1.Special purpose registers
A. Accumulator(Acc)
-an 8-bit register
-used in various arithmetic & logical operations
E.g during addition of two 8-bit registers, one of the
operand must be in acc. And the other may be in
memory or in one of the other registers
12
B. Flag register
-The ALU includes five flip-flops that are set or
reset according to the result of an operation.
-The microprocessor uses the flags for testing the
data conditions.
-They are Zero (Z), Carry (CY), Sign (S), Parity
(P), & Auxiliary Carry (AC) flags. The most
commonly used flags are Sign, Zero, & Carry.
-The bit position for the flags in flag register is,
13
-The state of a flag flip flop is changed only, after the execution of an
arithmetic or logic instruction.
1. Sign flag(s):-After executing an arithmetic or logic instruction, if
the most significant bit of the result is 1 then the sign flag is set to
1 else 0.
Example: 35H: 0 0 1 1 0 1 0 1
+82H: 1 0 0 0 0 0 1 0
--------------------------------------------------------
1 0 1 1 0 1 1 1 => s=1
Exercises
1. Indicate the status flag after performing following operation.
(a) 78H
+99H
----------------------
(b) FCH
+FDH
--------------------- 16
2. General purpose registers
• they are 6 in number & are 8-bit wide
• can be used by a programmer for a variety of
purposes
• they are labeled as B,C,D,E,H & L
• these registers can be used individually, when
operation on 8-bit data is desired, or in pair when
a 16-bit address is to be stored.
• when used in pairs, only the combinations shown
below are permitted.
17
3. 16-bit registers
• they are two in number, Program counter and stack
pointer
A. Program counter(PC)
• The program counter (PC) keeps track of program execution
• To execute a program the starting address of the program is loaded
in program counter
• The PC is updated by the processor and points to the next
instruction after it has fetched an instruction(i.e. when a byte
of instruction is fetched, the PC holds the address of the next byte
of the instruction )
• the exact number by w/c the processor updates depends on
the nature of the instruction
e.g 1-byte instruction-updates by 1
3-byte instruction-updates by 3 18
B. Stack pointer(SP)
• The stack is a sequence of RAM memory locations
defined by the programmer
• The stack is used to save the content of registers
during the execution of a program.
• The contents are stored and retrieved in LIFO (Last
In First Out) form.
• Stack pointer- is a 16-bit memory pointing register,
having the last address of the stack in RAM.
• Stack writing instructions fill memory positions in
progressively decreasing addresses
• Increasing/decreasing is always by two bytes since
all stack operations involve register pairs 19
Machine codes
In the design of the 8085 P chip, all operations, registers, and
status flags are identified with a specific codes.
Codes for registers codes for some operations
Code Registers Function code
000 B 1. RLC 00000111 =07H (8-bit code)
001 C
010 D 2. ADD RS 10000 SSS
011 E (5-bits opcode, 3-bits are for a register)
100 H e.g. ADD : 10000
101 L B : 000 ADD B
110 … to A : implicit
111 A binary instruction 10000000 = 80H
110 is reserved for memory-related
3. MOV Rd, Rs 01 DDD SSS
operations
op Rd Rs
Code Register pair e.g. MOV : 01
00 BC to C : 001 (DDD) MOV C, A
01 DE from A : 111 (SSS)
10 HL Binary instruction 01001111 =4FH
11 SP (2-bit opcode, 6-bits are for registers) 20
Instruction formats
22
Two byte instructions
• In a two-byte instruction, the first byte specifies the
operation code and the second byte specifies the
operand.
23
Three byte instructions
• In a three-byte instruction, the first byte specifies the opcode,
and the following two bytes specify the 16-bit address
• Note that the second byte is the low-order address and the
third byte is the high-order address.
24
• Can be defined as a mechanism used for
specifying the address of operands in an
instruction.
• Every instruction of a program has to operate on
a data
• The method of specifying the data to be operated
by the instruction is called Addressing.
25
Addressing modes
There are five types of addressing modes.
I. Direct addressing
II. Register Addressing Mode
III. Register Indirect Addressing Mode
IV. Immediate Addressing Mode
V. Implicit Addressing Mode
26
I. Direct Addressing
In this mode of addressing the address of the operand(data) is explicitly
given in the instruction itself.
The data will be in memory
In this addressing mode, the program instructions and data can be stored in
different memory blocks
This type of addressing can be identified by 16-bit address present in the
instruction
All such instructions are 3-byte long, except IN and OUT instructions
Instructions of these types are: LDA, STA, IN, OUT, SHLD, LHLD
E.g.
1. STA 2400H ; Store the contents of ACC in the memory
location 2400H
32, 00, 24 ; in binary code form
2. LDA 2300H ; Get the content in memory location 2300H in to ACC .
3A, 00, 23 ; in machine code form
3. IN 02 ; Read data from an I/O port (the Port C).
27
DB, 02 ; in binary code form
II. Register Addressing Mode
- In this mode, the operands are in general-purpose registers.
- The opcode specifies the address of the register in addition
to the operation to be performed.
- Instructions of these type include: MOV, ADD, SPHL,
SUB, INR, PCHL, …
E.g.
1. MOV A, B ; Move the contents of register B to
register A
78 ; in code form
2. ADD B ; add the content of Register B to the content
of Register A
80 ; in code form
28
III. Register Indirect Addressing Mode
- In this mode, the address of the operand is specified by a
register.
- Instructions of these type include: MOV, LDAX, STAX,
PUSH, ADD, SUB, INR, …
E.g.
1. LXI H, 2500H ; Load H-L pair with 2500H
MOV C, M ; move the contents of the memory location,
whose address is in register pair H-L (i.e., 2500h) to register
C.
ADD M ; add the content of memory location, whose
address is in H-L pair with ACC
2. LXI D, 2600H ; Load D-E pair with 2600H
STAX D ; Store ACC into memory location indicated by29
IV. Immediate Addressing Mode
In this addressing mode, the operand (data) is specified
within the instruction itself.
The data will be apart of the program instruction
All instructions that have ‘I’ in their mnemonics are of
Immediate addressing type
Instructions of these type include: MVI, LXI, ADI, SUI,
ANI, ACI, CPI, …
e.g.
MVI A, 05 ; Move 05 in register A . (3E, 05 in code)
ADI 06 ; Add 06 to the content of ACC . (C6, 06 in code)
LXI H, 2500H ,Load rp H-L with 2500H. (21, 00, 25 in
code)
30
V. Implicit Addressing Mode
Instructions in this category, operate on the content
of the ACC.
This type of instruction does not have any address,
register name, immediate data specified along with it
Instructions of these type include: RLC, RRC,
CMA, RAL, RAR, …
e.g.
1. CMA ; complement ACC (i.e. 1’s complement).
2F ; in code form
2. RAR ; Rotate ACC right through carry by one bit.
1F ; in code form 31
The Intel 8085 Instruction set
• The 8085 instruction set is functionally grouped as
follows:
1. Data transfer group
2. Arithmetic group
3. Logical group
4. Branch control group
5. Stack, and Machine control group
32
I. Data Transfer group instructions
moves(copy)data - between registers,
- between registers & memory,
- specific data byte to register or memory,
- between I/O device and ACC.
Data transfer instructions do not affect the flags.
Data transfer instructions do not affect the contents of
source register or memory or I/O.
• These instructions include: MOV, MVI, LXI, LDA, STA,
LHLD, SHLD, LDAX, STAX, XCHG, (IN, OUT).
33
Each instruction in assembly is given as bellow.
1. MOV r1, r2 ; Move the content of one register to another
[r1] [r2]
e.g. MOV B, A
6. ACI data8 ; Add with carry immediate data to ACC. Result in ACC.
[A] [A] + data8 + [CS]
38
7. DAD rp ; Add the content of register pair to H-L pair. rp can be
H-L, B-C, D-E, SP.
[H-L] [H-L] + [rp]
- the contents of register pair rp is added to the contents of H-L pair
and the result is placed in H-L pair.
e.g. LXI H, 2000H
LXI D, 0550H
DAD D ; result is in H-L pair, H=25H, L=50H
40
11. SBB M ; subtract content of memory with borrow from ACC.
[A] [A] - [ [H-L]] - [CS]
12. SUI data8 ; Subtract 8-bit immediate data from ACC. Result in
ACC.
[A] [A] - data8
e.g. MVI A, E1H
SUI 0FH ; result is in A=D2H
13. SBI data8 ; Subtract with borrow immediate data from ACC.
Result in ACC.
[A] [A] - data8 - [CS]
42
20. DAA ; decimal adjust ACC. Decimal result is placed in
ACC.
43
Example: What would be the out put of the following Code.
mvi A,95h
mvi D,98h
add D
DAA
hlt
Exercises:
98h
+99h
44
III. Logical Group Instructions
• The 8085 microprocessor supports the following
logic operations.
• Like arithmetic operations these instructions
change the state of the flags according to the result.
• These includes:
ANA ANI
ORA ORI
XRA XRI
CMA CMC STC
CMP CPI
RLC RAL RRC RAR
45
AND logical instructions. Used to mask or extract and reset bit(s)
1. ANA r ; AND register r with ACC
[A] [A] ^ [r]
2. ANA M ; AND memory with ACC
[A] [A] ^ [[H-L]]
3. ANI data8 ; AND immediate data with ACC
[A] [A] ^ data8
Example:
4.Let A contains 82h, and D contains 54H, now logically AND D with ACC.
Ans.
ANA D ; AND reg. D with ACC
(A)=82H = 1000 0010
AND
(D)=54H = 0101 0100
0000 0000 = 00h=(A) result in ACC 46
OR logical instructions. Used to selectively set bit(s)
4. ORA r ; OR register r with ACC
[A] [A] [r]
48
13. CMP r ; Compare register with ACC
[A] - [r]
14. CMP M ; Compare memory with ACC
[A] - [[H-L]]
15. CPI data8 ; Compare immediate data with ACC
[A] - data8
Note:
Status flags are affected according to the result of the subtraction. But the result is
discarded. Neither of the operands’ contents are modified.
. If (A)< operand, CY flag is set (CS=1), and Z flag is reset (Z=0)
. If (A)==operand, CY flag is reset (CS=0), and Z flag is set (Z=1)
. If (A)>operand, both CY and Z flags reset (CS=0,Z=0)
Example:
1. Register B contains data byte 62h and ACC contains 57H. Compare B with ACC.
MVI A, 57H Before execution After execution
MVI B, 62H CY
CMP B A 57 XX F A 57 1 F
B 62 XX C B 62 XX C
HLT
49
Flags: S=1, Z=0, AC=0, P=1, CY=1
16. RLC ; Rotate accumulator left
[An+1] [An], [A0] [A7], [CS] [A7]
Cy A7 A6 A5 A4 A3 A2 A1 A0
Cy A7 A6 A5 A4 A3 A2 A1 A0
50
19. RRC ; Rotate ACC right
[A7] [A0], [CS] [A0], [An] [An+1],
CS A7 A6 A5 A4 A3 A2 A1 A0
CS A7 A6 A5 A4 A3 A2 A1 A0
51
IV. Branch Group Instructions
• These includes:
JMP
J(condition)
CALL
C(condition)
RET
R(condition)
RST n
PCHL
52
Branch instructions are used to change the normal sequence of the program.
Two types of branch instructions:
. Unconditional jump-transfer the program to specified label unconditionally.
. Conditional branch (jump)- transfer the program to specified label
when certain condition is satisfied.
1. JMP addr16 (Label) ; unconditionally jump to the instruction addressed by
Label.
[PC] Label
2. J(Condition) addr16(Label) ; Jump if condition is satisfied.
[PC] Label
These includes:
IN OUT
PUSH POP
EI DI
RIM SIM
XTHL
SPHL
HLT
NOP
57
1. IN portAddr8 ; Input from input port to ACC
[A] [portaddr8]
e.g. IN 01 ; move the data on port address to ACC
2. OUT portAddr8 ; Output from ACC to output port
[portaddr8] [A]
e.g. OUT 00H ; move from ACC to output port 00h
3. PUSH rp ; Push the content of register pair to stack
[[SP]-1] [rh], [[SP]-2] [rl]
[SP] [SP]-2
4. PUSH PSW ; Push processor status word i.e. A and Flags
[[SP]-1] [A], [[SP]-2] [PSW]
[SP] [SP]-2
5.POP rp ; pop the content which was saved in stack to register pair.
[rl] [[SP]], [rh] [[SP]+1]
[SP] [SP]+2
6. POP PSW ; Pop Processor status word, i.e. A and Flags
[PSW] [[SP]], [A] [[SP]+1]
[SP] [SP]+2
58
7. HLT ; Halt. Stop the program (but not off). Halt and enter
WAIT state
60
-Given that the stack grows backwards into memory, it is customary
to place the bottom of the stack at the end of memory to keep it as far
away from user programs as possible.
-In the 8085, the stack is defined by setting the SP (Stack Pointer)
register.
-This sets the Stack Pointer to location FFFFH (end of memory for
the 8085).
LXI SP, FFFFH
61
The PUSH Instruction
•PUSH B
–Decrement SP
–Copy the contents of register B to the memory location pointed to
by SP
–Decrement SP
–Copy the contents of register C to the memory location pointed to
by SP
62
The POP Instruction
•POP B
–Copy the contents of the memory location pointed to by the SP to
register C
–Increment SP
–Copy the contents of the memory location pointed to by the SP to
register B
–Increment SP
63
Operation of the Stack
65
The CALL Instruction
CALL 4000H
–Push the address of the instruction immediately following the
CALL onto the stack
–Load the program counter with the 16-bit address supplied with the CALL
instruction.
66
Cautions
•The CALL instruction places the return address at the two memory
locations immediately before where the Stack Pointer is pointing.
–You must set the SP correctly BEFORE using the CALL instruction.
•The RET instruction takes the contents of the two memory locations
at the top of the stack and uses these as the return address.
–Do not modify the stack pointer in a subroutine. You will loose the
return address.