basic programming of 8085

45
Basic Programming of 8085 B.SAKTHISUDHURSUN 12MT06PED003

Upload: vijaydeepakg

Post on 29-Jun-2015

144 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Basic programming of 8085

Basic Programming of 8085

B.SAKTHISUDHURSUN12MT06PED003

Page 2: Basic programming of 8085

CONTENTS

1)Introduction

2)Methods of programming

3)Assembler Instruction format

4)Instructions set of 8085

5) Simple Programs

Page 3: Basic programming of 8085

1) Introduction Purpose of Processors & Controllers:

To perform the user defined task How to communicate this tasks to microprocessor?????

Through program What is program????

Sequence of instructions to perform the specified task.Instructions:

An instruction is a binary pattern designed inside a microprocessor to perform a specific function A microprocessor executes instructions given by the user to perform specified task. Microprocessor understands the language of 0’s and 1’s only This language is called Machine Language

Page 4: Basic programming of 8085

2) Types of Programming Language

0011111000000010000001100000010010000000

Very difficult to understand

Difficult to correct the errors

What is the solution ?????1) Assembly Language 2) High Level language

Program to add two numbers

Can we understand this????

Page 5: Basic programming of 8085

Assembly Language

• 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

AssemblyLanguageProgram

AssemblerProgram

Machine Language

Code

Page 6: Basic programming of 8085

High Level Language

• Machine language and Assembly language are both

– Microprocessor specific (Machine dependent)

• 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

Page 7: Basic programming of 8085

With whom we have to communicate???

Accumulator (8-bit) Flag Register (8-bit)

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

Bidirectional

16- Lines

Unidirectional

Page 8: Basic programming of 8085

Registers of 8085Six general-purpose registers:

- B, C, D, E, H, L- Can be combined as register pairs to perform 16-bit

operations Accumulator :

– identified by name A – part of ALU – Performs arithmetic and logical operations & is stored in it

Flag Register: -Part of ALU- 8085 has five flags named

1. Zero flag (Z)2. Carry flag (CY)3. Sign flag (S)4. Parity flag (P)5. Auxiliary Carry flag (AC)

Stack Pointer Register-16-bit memory pointer register-Points to a location in Stack memory-Beginning address defined by user

Page 9: Basic programming of 8085

What is an Instruction set???

• An instruction is a binary pattern designed inside a microprocessor to perform a specific function

• The entire group of instructions that a microprocessor supports is called Instruction Set.

• Consists of– 246 Instructions, e.g. MOV A,B

• Each instruction is represented by an 8-bit binary value.

• These 8-bits of binary value is called Op-Code

Page 10: Basic programming of 8085

3) Assembler Instruction Format

Format: 4 Fields

Label: Mnemonic operand1, operand2; comment

Label Mnemonic Operands Comment

START: MOV A, 54 ;Load A Register with 54H

Mnemonic:Aims to translate information into a form that

the human brain can retain better than its original form.Definition:

Specifies operation to be executed in human understandable format

Operand: On which operation is performed. It can have no or single or double operator

Label: An identifier or a symbolic name Used in conjunction with branch instruction

Example:

Page 11: Basic programming of 8085

4) Classification of Instruction Sets

• 8085 instructions can be classified as1. Data Transfer (Copy) 2. Arithmetic3. Logical and Bit manipulation4. Branch5. Machine Control

Page 12: Basic programming of 8085

Data Transfer Instructions

• These instructions move data between registers, or between memory and registers

• These instructions copy data from source to destination

• While copying, the contents of source are not modified.

Page 13: Basic programming of 8085

Data Transfer Instructions

Page 14: Basic programming of 8085

Data Transfer Instructions

Page 15: Basic programming of 8085

Data Transfer Instructions

Page 16: Basic programming of 8085

Data Transfer Instructions

Page 17: Basic programming of 8085

Data Transfer Instructions

Page 18: Basic programming of 8085

Data Transfer Instructions

LHLD 16-Bit Address Load HL pair with content of Direct address

•The contents of 16-bit address is stored to L register•The contents of next memory location is stored to H register•Example: LHLD 1500H

Page 19: Basic programming of 8085

Data Transfer Instructions

Page 20: Basic programming of 8085

Data Transfer Instructions

Page 21: Basic programming of 8085

Data Transfer Instructions

Page 22: Basic programming of 8085

Data Transfer Instructions

Page 23: Basic programming of 8085

Data Transfer Instructions

Page 24: Basic programming of 8085

Data Transfer Instructions

Page 25: Basic programming of 8085

Summary of Data Transfer Instructions

1. Load a 8-bit number in a Register2. Copy from Register to Register3. Copy between Register and Memory4. Copy between Input/output Port and

Accumulator5. Load a 16-bit number in a Register pair6. Copy between Register pair and Stack memory

Page 26: Basic programming of 8085

Program

Write a program to exchange memory contents of 2000H with 4000H.

Page 27: Basic programming of 8085

Programs

2000 AA

2001 BB

2002 CC

Find the contents of H & L register after executing following Instruction?LXI H, 2001 LHLD 2001

Solution:After first instruction H=20H & L=01After second instruction H=CC & L=BB

Memory Contents:

Page 28: Basic programming of 8085

PUSH & POP Testing Point

1) If the Initial content of SP is 2000H. What is the value in SP if the number PUSH operation is equal to number of POP operation.

2) If the content of SP is 2000HIf POP instruction is used before PUSH instruction what will happen

Answers:1) SP value will be same2) Garbage or unpredicted operation results

Page 29: Basic programming of 8085
Page 30: Basic programming of 8085

Data Transfer Instructions

Page 31: Basic programming of 8085

More Test on PUSH & POP operations

Find the contents of DE pair and PSW after executing following Instruction/PUSH BPUSH HPOP DPOP PSWInitial Contents:SP=A000HBC=1050HL=8090

90 E

80 D

50 Flag

10 A

9FFC9FFD9FFE9FFFA000SP

Page 32: Basic programming of 8085

Program to understand I/O Operation

Write a program to display following letter E. Assume the address of the LED is 20H.Assume A is connected to AD0 and G is connected to AD7

Assume it is connected in Common Cathode.Means all the cathode are connected through a resistance and grounded

It is not an actual 7 Segment Display available in market. It is just for our example

Page 33: Basic programming of 8085

Program to understand I/O Operation

8085

Decoder

LATCH

ABCDEFG

Address Bus

IO/M, WR_ _

Enable Signal

Grounded

Data Bus

D0

D6

Solution:MVI A,F9OUT 20HHLT

Page 34: Basic programming of 8085

Arithmetic Instructions

Page 35: Basic programming of 8085

Arithmetic Instructions

1. Add an immediate data with Accumulator

2. Add contents of Registers(B,C,D,E ,H,L) or memory to Accumulator

3. Add an immediate data with carry to Accumulator

4. Add contents of or memory to Accumulator with carry

5. Add 16 bit contents of Register pair with content of HL register

ADI 32H

ADD B

ACI 42H

ADC D

DAD D

Page 36: Basic programming of 8085

Arithmetic Instructions

1. Subtract an immediate data from Accumulator

2. Subtract contents of Rn from Accumulator

3. Subtract an immediate data from Accumulator with borrow

4. Subtract contents of Rn from Accumulator with borrow

SUI 32H

SUB B

SIB 42H

SBB D

Page 37: Basic programming of 8085

Arithmetic Instructions

1. Increment the contents of Rn or memory by 1

2. Increment the contents of Rp by 1

3. Decrement the contents of Rn or memory by 1

4. Decrement the contents of Rp by 1

5. Decimal Adjust accumulator

INR A

INX B

DCR C

DCX D

DAA

Page 38: Basic programming of 8085

Flag Register Status on Arithmetic Instructions

Sl.NO Instruction CY AC S P Z

1 ADD

2 ADI

3 ADC

4 ACI

5 SUB

6 SUI

7 SBB

8 SBI

9 INR

10 INX

Not affected Affected

Page 39: Basic programming of 8085

Flag Register Status on Arithmetic Instructions

Sl.NO Instruction CY AC S P Z

11 DCR

12 DCX

13 DAD

14 DAA

Not affected Affected

Page 40: Basic programming of 8085

Example

Write a program/Instruction to Shift 16 bit data stored in HL Register towards left by 1 bit.

CLUE: Use DAD instruction

To shift left by 5 bit. How many times we have to execute the above Instruction

What will happen if results exceed the FFFF. Will it work

What are the application of shifting operation?1. Multiplication & Division2. Serial communication

Page 41: Basic programming of 8085

How to Clear Flag Register

One of the example:LXI B, 00HPUSH BPOP PSW

Page 42: Basic programming of 8085

Test point for Flag Register operation

1. LXI H, 20402. LHLD 20413. ADD M4. INX H5. MOV M,A

F0

20

42

02

A

2043204220412040

Find the content of Flag Register after each operation. Identify what this program is doing

Solution:1. No change2. No change3. Affected4. No change 5. No change

1) H=20 , L=402) H=20, L=423) A=F0+20= 104) H=20, L=435) 2043=10

0 0 X 0 X 0 X 1Flag Status:

Adding the content in 2042 and store the sum in 2043

Page 43: Basic programming of 8085

Machine Control Instructions

1. NOP

2. HALT

3. DI

4. EI

No operation is performed

An interrupt or Reset is required to come out from Halt State

Disable all interrupt except TRAP

To Enable all interrupt except TRAP.After Reset or interrupt acknowledgement interrupt flag is disabled

Page 44: Basic programming of 8085

Steps to write 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

Page 45: Basic programming of 8085