Вы находитесь на странице: 1из 93

8085 Microprocessor

Microprocessor understands Machine Language


only!
 Microprocessor cannot understand a program written
in Assembly language
 A program known as Assembler is used to convert a
Assembly language program to machine language

Assembly Machine
Assembler
Language Language
Program
Program Code
INTRODUCTION TO 8085

 Microprocessor –silicon chip which includes ALU,


register circuits & control circuits
 Microcomputer –a computer with a microprocessor as
its CPU. Includes memory, I/O etc.
 Microcontroller –silicon chip which includes
microprocessor, memory & I/O in a single package.
Definition of the Microprocessor

The microprocessor is a programmable device


that takes in numbers, performs on them
arithmetic or logical operations according to
the program stored in memory and then
produces other numbers as a result.
1. Introduction
 A microprocessor executes instructions given by the
user
 Instructions should be in a language known to the
microprocessor
 Microprocessor understands the language of 0’s and
1’s only
 This language is called Machine Language
Definition (Contd.)

• Lets expand each of the

 Programmable device: The microprocessor can perform


different sets of operations on the data it receives depending on the
sequence of instructions supplied in the given program. By
changing the program, the microprocessor manipulates the data in
different ways.
 Instructions: Each microprocessor is designed to execute a
specific group of operations. This group of operations is called an
instruction set. This instruction set defines what the
microprocessor can and cannot do.
Definition (Contd.)

 Takes in:
The data that the microprocessor manipulates must come from somewhere.
 It comes from what is called “input devices”.
 These are devices that bring data into the system from the outside
world.
 These represent devices such as a keyboard, a mouse, switches, and the
like.
Definition (Contd.)

 Numbers:
There are only 10 type of people in the world one can understand others don’t

The microprocessor has a very narrow view on life. It only understands binary
numbers.
A binary digit is called a bit
The microprocessor recognizes and processes a group of bits together. This
group of bits is called a “word”.
The number of bits in a Microprocessor’s word, is a measure of its “abilities”.
Definition (Contd.)

 Arithmetic and Logic Operations:


 Every microprocessor has arithmetic operations such as add and subtract as
part of its instruction set.
 Most microprocessors will have operations such as multiply and divide.
 Some of the newer ones will have complex operations such as square root.
 In addition, microprocessors have logic operations as well. Such as AND,
OR, XOR, shift left, shift right, etc.
 Again, the number and types of operations define the microprocessor
instruction set and depends on the specific microprocessor.
Definition (Contd.)

 Stored in memory :
 First, what is memory?
 Memory is the location where information is kept while not in current use.
 Memory is a collection of storage devices. Usually, each storage device
holds one bit. Also, in most kinds of memory, these storage devices are
grouped into groups of 8. These 8 storage locations can only be accessed
together. So, one can only read or write in terms of bytes to form memory.
 Memory is usually measured by the number of bytes it can hold. It is
measured in Kilos, Megas and lately Gigas. A Kilo in computer language is
=1024. So, a KB (KiloByte) is 1024 bytes. Mega is 1024 Kilos and Giga is
1024 Mega.
Definition (Contd.)

 Stored in memory:
 When a program is entered into a computer, it is stored in memory. Then as
the microprocessor starts to execute the instructions, it brings the instructions
from memory one at a time.
 Memory is also used to hold the data. The microprocessor reads (brings in)
the data from memory when it needs it and writes (stores) the results into
memory when it is done.
Definition (Contd.)

 Produces:
For the user to see the result of the execution of the program, the results must be
presented in a human readable form.
 The results must be presented on an output device.
 This can be the monitor, a paper from the printer, a simple LED or many
other forms.
8085 Architecture
8085 Architecture
The features of INTEL 8085 are :
• It is an 8 bit processor.
• It is a single chip N-MOS device with 40 pins.
• It has multiplexed address and data bus.(AD0-AD7).
• It works on 5 Volt dc power supply.
• The maximum clock frequency is 3 MHz while
minimum frequency is 500kHz.
• It provides 74 instructions with 5 different addressing
modes.
Contd..

 It provides 16 address lines so it can access 2^16 =64K bytes


of memory.
 It generates 8 bit I/O address so it can access 2^8=256 input
ports.
 It provides 5 hardware interrupts: TRAP, RST 5.5, RST 6.5,
RST 7.5,INTR.
 It provides Acc ,one flag register ,6 general purpose registers
and two special purpose registers(SP,PC).
 It provides serial lines SID ,SOD. So serial peripherals can be
interfaced with 8085 directly.
8085 Architecture Diagram
Arithmetic and Logical group

Accumulator:
It is 8 bit general purpose register.
 It is connected to ALU.
 So most of the operations are done in Acc.
 Temporary register: It is not available for user
 All the arithmetic and logical operations are done in the
temporary register but user can’t access it.
 Flag: It is a group of 5 flip flops used to know status of
various operations done.
 The Flag Register along with Accumulator is called PSW
 or Program Status Word.
Arithmetic and Logical group Contd..

Flag Register is given by:

S Z X AC X P X CY

S : Sign flag is set when result of an operation is negative.

X : It is don’t care flip flops.

Z : Zero flag is set when result of an operation is 0.

Ac : Auxiliary carry flag is set when there is a carry out of lower nibble or
lower four bits of the operation.

CY : Carry flag is set when there is carry generated by an operation.

P : Parity flag is set when result contains even number of 1’s.


Register Group

• Temporary registers (W,Z):


These are not available for user. These are loaded only when there is an operation
being performed.

• General purpose:
There are six general purpose registers in 8085 namely B,C,D,E,H,L.These are
used for various data manipulations.
• There are two special purpose registers in 8085:
SP :Stack Pointer.
PC:Program Counter.
Register Group Contd..

Stack Pointer: This is a temporary storage memory 16 bit register. Since


there are only 6 general purpose registers, there is a need to reuse them .
 Whenever stack is to be used previous values are PUSHED on stack and
then after the program is over these values are POPED back.

Program Counter: It is 16 bit register used to point the location from


which the next instruction is to be fetched.
 When a single byte instruction is executed PC is automatically
incremented by 1.
 Upon reset PC contents are set to 0000H and next instruction is
fetched onwards.
Instruction Register, Decoder & Control

 Instruction register:
When an instruction is fetched , it is executed in instruction
register. This register takes the Opcode value only.
 Instruction decoder:
It decodes the instruction from instruction register and then
to control block.
 Timing and control:
This is the control section of µP. It accepts clock input .
Interrupt Control

 Itaccepts different interrupts like TRAP INT5.5, 6.5,


7.5 and INTR.

Serial IO Control Group

• It is used to accept the serial 1 bit data by using SID


and SOD signals and it can be performed by using
SIM & RIM instructions.
Interrupts
2 type –
Maskable interrupts – can be delayed or rejected
Non Maskable Interrupts – can’t ne delayed or rejected

Classified into VECTOR and NON VECTORED


interrupts
Vector – the address of the service routine is hard wired
Non vector – service routine needs to be supplied
externally by the device.
INTR – it’s a maskable interrupt .
When interrput occurs . The processor fetches the
bus from 1 instruction usaully one of EI an DI
instruction

RST 5.5 ,6.5 ,7.5 – Maskable interrupt


When the interrupt is received , the processor saves
the contents of the Program Counter register into the
STACK and the branches to address

TRAP – Non Maskable interrupt


Doesn’t need to be enabled or disabled
Highest priority amongst all interrupts.
8085 Pin Diagram
8085 Pin Diagram
8085 Pin Description

Some important pins are :


 AD0-AD7: Multiplexed Address and data lines.
 A8-A15: Tri-stated higher order address lines.
 ALE: Address latch enable is an output signal.It goes high when operation is started
by processor .
 S0,S1: These are the status signals used to indicate type of operation.
 RD¯: Read is active low input signal used to read data from I/O device or memory.
 WR¯:Write is an active low output signal used write data on memory or an I/O
device.
Contd..

 READY: This an output signal used to check the status of output device. If
it is low, µP will WAIT until it is high.
 TRAP: It is an Edge triggered highest priority , non mask able interrupt.
After TRAP, restart occurs and execution starts from address 0024H.
 RST5.5,6.5,7.5:These are maskable interrupts and have low priority than
TRAP.
 INTR¯&INTA:INTR is a interrupt request signal after which µP generates
INTA or interrupt acknowledge signal.
 IO/M¯:This is output pin or signal used to indicate whether 8085 is
working in I/O mode(IO/M¯=1) or Memory mode(IO/M¯=0 ).
Contd..

 HOLD&HLDA:HOLD is an input signal .When µP receives HOLD signal it


completes current machine cycle and stops executing next instruction.In
response to HOLD µP generates HLDA that is HOLD Acknowledge signal.
 RESET IN¯:This is input signal.When RESET IN¯ is low µp restarts and starts
executing from location 0000H.
 SID: Serial input data is input pin used to accept serial 1 bit data .
 X1X2 :These are clock input signals and are connected to external LC,or RC
circuit.These are divide by two so if 6 MHz is connected to X1X2, the
operating frequency becomes 3 MHz.
 VCC&VSS:Power supply VCC=+ -5Volt& VSS=-GND reference.
Low-level/High-level languages

 Machine language and Assembly language are both


 Microprocessor specific (Machine dependent)
so they are called
 Low-level languages
 Machine independent languages are called
 High-level languages
 For e.g. BASIC, PASCAL,C++,C,JAVA, etc.
 A software called Compiler is required to convert a high-
level language program to machine code
2. Programming model of 8085

Accumulator 16-bit Address


Bus
Register Array
ALU

Memory Pointer
Flags Registers 8-bit Data
Bus
Instruction
Decoder

Control Bus
Timing and Control Unit
Accumulator (8-bit) Flag Register (8-bit)
S Z AC P CY

B (8-bit) C (8-bit)
D (8-bit) E (8-bit)
H (8-bit) L (8-bit)
Stack Pointer (SP) (16-bit)
Program Counter (PC) (16-bit)

8- Lines 16- Lines


Bidirectional Unidirectional
Overview: 8085 Programming model

1. Six general-purpose Registers


2. Accumulator Register
3. Flag Register
4. Program Counter Register
5. Stack Pointer Register
1. Six general-purpose registers
 B, C, D, E, H, L
 Can be combined as register pairs to perform 16-bit
operations (BC, DE, HL)
2. Accumulator – identified by name A
 This register is a part of ALU
 8-bit data storage
 Performs arithmetic and logical operations
 Result of an operation is stored in accumulator
3. Flag Register
 This is also a part of ALU
 8085 has five flags named
 Zero flag (Z)
 Carry flag (CY)
 Sign flag (S)
 Parity flag (P)
 Auxiliary Carry flag (AC)
 These flags are five flip-flops in flag register
 Execution of an arithmetic/logic operation can set or
reset these flags
 Condition of flags (set or reset) can be tested through
software instructions
 8085 uses these flags in decision-making process
4. Program Counter (PC)
 A 16-bit memory pointer register
 Used to sequence execution of program instructions
 Stores address of a memory location
 where next instruction byte is to be fetched by
the 8085
 when 8085 gets busy to fetch current instruction from
memory
 PC is incremented by one
 PC is now pointing to the address of next
instruction
5. Stack Pointer Register
 a 16-bit memory pointer register
 Points to a location in Stack memory
 Beginning of the stack is defined by loading a 16-bit
address in stack pointer register
TIMING DIAGRAM
TIMING DIAGRAM
Timing Diagram is a graphical representation. It represents the execution
time taken by each instruction in a graphical format. The execution time
is represented in T-states.
Instruction Cycle:
    The time required to execute an instruction is called instruction cycle.
Machine Cycle:
The time required to access the memory or input/output devices is called
machine cycle.
T-State:
The machine cycle and instruction cycle takes multiple clock periods.
A portion of an operation carried out in one system clock period is called
as T-state.
Timing and State Diagram

 The µP operates with reference to clock signal.The rise and fall of the pulse of
the clock gives one clock cycle.
 Each clock cycle is called a T state and a collection of several T states gives a
machine cycle.
 Important machine cycles are :

1.Op-code fetch.

2.Memory read.

3.Memory write.

4.I/Op-read.

5.I/O write.
MACHINE CYCLES OF 8085
The 8085 microprocessor has 5 basic machine cycles.
 Opcode fetch cycle (4T)
 Memory read cycle (3 T)
 Memory write cycle (3 T)
 I/O read cycle (3 T)
 I/O write cycle (3 T)
Timing and State Diagram Cont..

Op-code Fetch:

It basically requires 4 T states from T1-T4


 S0=1,S1=1 for Op-code fetch cycle.
 The ALE pin goes high at first T state always.
 AD0-AD7 are used to fetch OP-code and store the lower byte of Program Counter.
 A8-A15 store the higher byte of the Program Counter while IO/M¯ will be low
since it is memory related operation.
 RD¯ will only be low at the Op-code fetching time.
 WR¯ will be at HIGH level since no write operation is done.
Opcode fetch cycle (4T)
Timing and State Diagram Contd..

Memory write Cycle:


It basically requires 3T states from T1-T3 .
 The ALE pin goes high at first T state always.
 AD0-AD7 are used to fetch data from CPU and store the lower byte of address.
 A8-A15 store the higher byte of the address while IO/M¯ will be low since it is
memory related operation.
 RD¯ will be HIGH since no read operation is done.
 WR¯ will be at LOW level only when data fetching is done.
 S0=1,S1=0 for Memory write cycle.
Memory Write Machine Cycle
 The memory write machine cycle is executed by the processor to write a data byte
in a memory location.
 The processor takes, 3T states to execute this machine cycle.
Timing and State Diagram Contd..

Memory Read Cycle:


It basically requires 3T states from T1-T3 .
 The ALE pin goes high at first T state always.
 AD0-AD7 are used to fetch data from memory and store the lower byte of
address.
 A8-A15 store the higher byte of the address while IO/M¯ will be low since
it is memory related operation.
 RD¯ will only be low at the data fetching time.
 WR¯ will be at HIGH level since no write operation is done.
 S0=0,S1=1 for Memory read cycle.
Memory Read Machine Cycle
I/O Write Cycle
 The I/O write machine cycle is executed by the processor to write a data byte in the
I/O port or to a peripheral, which is I/O, mapped in the system.
 The processor takes, 3T states to execute this machine cycle
Addressing Modes of 8085
Addressing Modes of 8085

 To perform any operation, we have to give the corresponding


instructions to the microprocessor.
 In each instruction, programmer has to specify 3 things:
 Operation to be performed.
 Address of source of data.
 Address of destination of result.
 The method by which the address of source of data or the
address of destination of result is given in the instruction is
called Addressing Modes.
 The term addressing mode refers to the way in which the
operand of the instruction is specified.
Addressing Modes Contd..

 Intel 8085 uses the following addressing modes:

1. Direct Addressing Mode

2. Register Addressing Mode

3. Register Indirect Addressing Mode

4. Immediate Addressing Mode

5. Implicit Addressing Mode


Direct Addressing Mode

 In this mode, the address of the operand is given in the instruction itself.
 LDA 2500 H //Load the contents of memory location 2500 H in
accumulator is the address of source.
 LDA is the operation.
 2500 H is the address of source
 Accumulator is the destination.
Example: Direct Addressing
 16-bit Address of the memory location is specified in the
instruction directly
 Examples-
LDA 2050H ;load A with contents of memory
location with address 2050H
STA 3050H ;store A with contents of memory
location with address 3050H
Register Addressing Mode

 In this mode, the operand is in general purpose register


 MOV A, B //Move the contents of register B to A.
 MOV is the operation.
 B is the source of data.
 A is the destination.
Register Addressing
 Operands are one of the internal registers of 8085
 Examples-
MOV A, B
ADD C
Register Indirect Addressing Mode

 In this mode, the address of operand is specified by a register pair.


 MOV is the operation.
 M is the memory location specified by H-L register pair.
 A is the destination.
 MOV A, M \\ Move data from memory location specified by H-L pair to
accumulator.
Example: Indirect Addressing

 A memory pointer register is used to store the address of


the memory location
 Example-
MOV M, A ;copy register A to memory location
whose address is stored in register pair HL

H L
A 30H 20H 50H 2050H 30H
Immediate Addressing Mode

 In this mode, the operand is specified within the instruction itself.


 MVI A, 05 H //Move 05 H in accumulator.
 MVI is the operation.
 05 H is the immediate data (source).
 A is the destination.
Example: Immediate
Addressing
 Value of the operand is given in the instruction itself
 Example-
MVI A, 20H
LXI H, 2050H
ADI 30H
SUI 10H
Implicit Addressing Mode

 If address of source of data as well as address of destination of result is


fixed, then there is no need to give any operand along with the instruction.

CMA //Complement accumulator


 CMA is the operation.
 A is the source.
 A is the destination.
Assembly Language
of 8085
 It uses English like words to convey the action/meaning
called as MNEMONICS
 For e.g.
 MOV to indicate data transfer
 ADD to add two values
 SUB to subtract two values
Assembly language program to add two
numbers

MVI A, 2H;Copy value 2H in register A


MVI B, 4H;Copy value 4H in register B
ADD B ;A = A + B

Note:
 Assembly language is specific to a given processor
 For e.g. assembly language of 8085 is different than
that of Motorola 6800 microprocessor
3.Instruction Set of 8085

 Consists of
 74 operation codes, e.g. MOV
 246 Instructions, e.g. MOV A,B
 8085 instructions can be classified as
1. Data Transfer (Copy)
2. Arithmetic
3. Logical and Bit manipulation
4. Branch
5. Machine Control
1. Data Transfer (Copy) Operations
1. Load a 8-bit number in a Register
2. Copy from Register to Register
3. Copy between Register and Memory
4. Copy between Input/Output Port and Accumulator
5. Load a 16-bit number in a Register pair
6. Copy between Register pair and Stack memory
Example Data Transfer (Copy)
Operations / Instructions

1. Load a 8-bit number 4F in MVI B, 4FH


register B
2. Copy from Register B to MOV A,B
Register A
3. Load a 16-bit number 2050 in
LXI H, 2050H
Register pair HL
4. Copy from Register B to
Memory Address 2050 MOV M,B
5. Copy between Input/Output
Port and Accumulator OUT 01H
IN 07H
2. Arithmetic Operations
1. Addition of two 8-bit numbers
2. Subtraction of two 8-bit numbers
3. Increment/ Decrement a 8-bit number
Example Arithmetic
Operations / Instructions

1. Add a 8-bit number 32H to ADI 32H


Accumulator
2. Add contents of Register B to ADD B
Accumulator
3. Subtract a 8-bit number 32H from SUI 32H
Accumulator
4. Subtract contents of Register C SUB C
from Accumulator
5. Increment the contents of Register
D by 1 INR D
6. Decrement the contents of Register
E by 1 DCR E
3. Logical & Bit Manipulation
Operations
1. AND two 8-bit numbers
2. OR two 8-bit numbers
3. Exclusive-OR two 8-bit numbers
4. Compare two 8-bit numbers
5. Complement
6. Rotate Left/Right Accumulator bits
Example Logical & Bit Manipulation
Operations /
Instructions

1. Logically AND Register H with ANA H


Accumulator
2. Logically OR Register L with ORA L
Accumulator
3. Logically XOR Register B with XRA B
Accumulator
4. Compare contents of Register CMP C
C with Accumulator
5. Complement Accumulator CMA
6. Rotate Accumulator Left RAL
4. Branching Operations
These operations are used to control the flow of program
execution
1.Jumps
 Conditional jumps
 Unconditional jumps
2.Call & Return
 Conditional Call & Return
 Unconditional Call & Return
Example Branching
Operations / Instructions

1. Jump to a 16-bit Address 2080H if JC 2080H


Carry flag is SET
2. Unconditional Jump JMP 2050H
3. Call a subroutine with its 16-bit
CALL 3050H
Address
4. Return back from the Call
5. Call a subroutine with its 16-bit RET
Address if Carry flag is RESET CNC 3050H
6. Return if Zero flag is SET
RZ
5. Machine Control Instructions
These instructions affect the operation of the processor. For
e.g.
HLT Stop program execution
NOP Do not perform any operation
Input/Output Addressing
 8-bit address of the port is directly specified in the
instruction
 Examples-
IN 07H
OUT 21H
Instruction & Data Formats
8085 Instruction set can be classified according to size (in
bytes) as
1. 1-byte Instructions
2. 2-byte Instructions
3. 3-byte Instructions
1. One-byte Instructions
 Includes Opcode and Operand in the same byte
 Examples-

Opcode Operand Binary Code Hex Code


MOV C, A 0100 1111 4FH
ADD B 1000 0000 80H
HLT 0111 0110 76H
2. Two-byte Instructions
 First byte specifies Operation Code
 Second byte specifies Operand
 Examples-

Opcode Operand Binary Code Hex Code


MVI A, 32H 0011 1110 3EH
0011 0010 32H
MVI B, F2H 0000 0110 06H
1111 0010 F2H
3. Three-byte Instructions
 First byte specifies Operation Code
 Second & Third byte specifies Operand
 Examples-

Opcode Operand Binary Code Hex Code


LXI H, 2050H 0010 0001 21H
0101 0000 50H
0010 0000 20H
LDA 3070H 0011 1010 3AH
0111 0000 70H
0011 0000 30H
Writing a Assembly Language
Program
Writing a Assembly Language
Program
 Steps to write a program
 Analyze the problem
 Develop program Logic
 Write an Algorithm
 Make a Flowchart
 Write program Instructions using Assembly
language of 8085
Program 8085 in Assembly language to add two
8-bit numbers and store 8-bit result in register C.

1. Analyze the problem


 Addition of two 8-bit numbers to be done
2. Program Logic
 Add two numbers
 Store result in register C
 Example
10011001 (99H) A
+00111001 (39H) D
11010010 (D2H) C
Translation to 8085
3. Algorithm operations
1. Get two numbers  Load 1st no. in register D
 Load 2nd no. in register E
2. Add them • Copy register D to A
• Add register E to A
3. Store result • Copy A to register C
4. Stop • Stop processing
4. Make a Flowchart
Start
• Load 1st no. in register D
Load Registers D, E • Load 2nd no. in register E

Copy D to A • Copy register D to A


• Add register E to A
Add A and E

Copy A to C
• Copy A to register C

• 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
Program 8085 in Assembly language to add two
8-bit numbers. Result can be more than 8-bits.

1. Analyze the problem


 Result of addition of two 8-bit numbers can be 9-bit
 Example
10011001 (99H) A
+10011001 (99H) B
100110010 (132H)
 The 9th bit in the result is called CARRY bit.
 How 8085 does it?
 Adds register A and B
 Stores 8-bit result in A
 SETS carry flag (CY) to indicate carry bit

10011001 99H A
+
10011001 99H B

0
1 10011001
00110010 32H
99H A
C
 Storing result in Register memory

C A
Y
1 10011001 32H

Register B Register C

Step-1 Copy A to C
Step-2
a) Clear register B
b) Increment B by 1
2. Program Logic

1. Add two numbers


2. Copy 8-bit result in A to C
3. If CARRY is generated
 Handle it
4. Result is in register pair BC
Translation to 8085
3. Algorithm operations

1. Load two numbers in  Load registers D, E


registers D, E
• Copy register D to A
2. Add them • Add register E to A
• Copy A to register C
3. Store 8 bit result in C
4. Check CARRY flag • Use Conditional Jump
5. If CARRY flag is SET instructions
 Store CARRY in • Clear register B
register B • Increment B
6. Stop • Stop processing
4. Make a Flowchart
Start

Load Registers D, E If False


CARRY Clear B
NOT SET
Copy D to A
Increment B
True
Add A and E

Copy A to C
Stop
5. Assembly Language Program

• Load registers D, E MVI D, 2H


• Copy register D to A
MVI E, 3H
• Add register E to A MOV A, D
• Copy A to register C ADD E
MOV C, A
• Use Conditional Jump
JNC END
instructions
• Clear register B MVI B, 0H
• Increment B INR B
• Stop processing END: HLT
Exercises
Write a program for two 8 bit numbers
 Addition
 Subtraction
 Multiplication
 Division

Вам также может понравиться