8085 microprocessor

115

Click here to load reader

Upload: pankajkthr

Post on 23-Oct-2015

423 views

Category:

Documents


59 download

TRANSCRIPT

Page 1: 8085 Microprocessor

By: Dr. Anil SwarnkarAssistant ProfessorDepartment of Electrical

Engineering, MNIT, JaipurE-mail id: [email protected]: 98292-88581

Page 2: 8085 Microprocessor

What is Microprocessor

Page 3: 8085 Microprocessor

VLSI technology of IC’s made it possible to design the complete circuit of ALU (Arithmetic Logic Unit) and CU (Control Unit) within a single chip, which comprises the main processing part, called Central Processing Unit (CPU), of computer system. This chip was named Microprocessor.

Page 4: 8085 Microprocessor

Importance of Microprocessors

Microprocessors/microcontrollers are not used only in computer systems but may be used in many control applications and devices used in our daily life. For such applications use of advanced microprocessors may be a costly affair, hence smaller processors like 8085/86, or microcontrollers with limited features may be more suitable and cost effective.

Page 5: 8085 Microprocessor

Temperature Control System

Page 6: 8085 Microprocessor

8085 Microprocessor

Page 7: 8085 Microprocessor

Accumulator (A)

It is an 8-bit register, which is the most important part of the arithmetic and logic unit (ALU). It is used to store 8-bit data. The results of arithmetical and logical operations are stored in the accumulator. It is also used to receive data from input port to microprocessor and to send data to output port from microprocessor. It is referred as register A in the program.

Page 8: 8085 Microprocessor

General Purpose Registers• Registers B, C, D, E, H and L are 8-bit

general-purpose registers. These registers store 8-bit data temporarily for processing.

• Some time it is required to store 16-bit data. In 8085 microprocessor, BC, DE and HL are used as register pairs to store 16-bit data.

• Hence there are 6 general-purpose 8-bit registers and they can be used as 3 pairs as 16-bit registers.

Page 9: 8085 Microprocessor

Flag Register (F)

Flag register is also an 8-bit register. Out of 8-bits, five bits are defined as flags to indicate status of the accumulator (with some exceptions), hence it is also called status register. Flags are flip-flops, which can be set or reset. After any arithmetical/logical operation some or all flags are modified according to the result of operation. Flag register, showing the bit position reserved for various flags

Page 10: 8085 Microprocessor

Program Counter (PC)

It is a 16-bit register. It is a memory pointer. It stores the memory address of the next byte of the program is to be executed

Page 11: 8085 Microprocessor

Stack Pointer (SP)

It is also a 16-bit register and a memory pointer similar to Program Counter. It holds the memory address of the top of the stack.

Page 12: 8085 Microprocessor

Bus Organisation

There are three sets of busses in 8085-microprocessor. Address bus, Data bus and Control bus

Page 13: 8085 Microprocessor

Basic Operations of 8085-microprocessor

Opcode Fetch: Reading and decoding operation code of an instruction.

Memory Read: Reading data from memory.Memory Write: Writing data into memory.I/O Read: Accepting data from Input Port.I/O Write: Sending data to Output Port.

Page 14: 8085 Microprocessor

Memory Read Operation

Page 15: 8085 Microprocessor

Pins and Signals

• Higher Order Address Bus• Multiplexed Address/data Bus • Control signals• Status signals• Power supply and clock frequency • Interrupt signals• Other externally initiated signals • Serial Input/Output ports

Page 16: 8085 Microprocessor

Pins and Signals of 8085-microprocessor

Page 17: 8085 Microprocessor

Assembly Language Instructions

• An instruction is a binary pattern, which when applied to the microprocessor digital circuit (architecture) - a specific task is performed.

• The entire group of instructions of particular microprocessor is called its instruction set. In 8085-microprocessor each instruction code is of 8-bits (1 byte), hence there may 28 (=256) different binary patterns; therefore total 256 instructions in its instruction set.

Page 18: 8085 Microprocessor

Classification of Instructions

Data copy operationsInput/Output operationsArithmetic operationsLogical operationsBranch operationsMachine control operationsStack Operations

Page 19: 8085 Microprocessor

Data Copy Operations

These instructions are used to copy data From one register to another register8/16-bit data directly from the instruction to

any register Data from any register to memoryData from memory to any register

Page 20: 8085 Microprocessor

MOV (Move) instructionCopies the contents of the source into destination.

MOV destination, source

Format 1: MOV Rd, RsFrom one register to another register, i.e., Rd ← Rs

Example: MOV B, C

Page 21: 8085 Microprocessor

Example: MOV M, D

Format 2: MOV M, RFrom any register to memory. Memory address is specified by the contents of HL pair, i.e. [HL] ← R

Page 22: 8085 Microprocessor

Format 3: MOV R, MFrom memory to any register, i.e., R ← [HL]

Example: MOV B, M

Page 23: 8085 Microprocessor

MVI (Move Immediate) instruction

This instruction is used to copy 8-bit data specified in the instruction is directly into the register (R) or Memory location specified by HL pair.

Format 1: MVI R, 8-bit dataFormat 2: MVI M, 8-bit data

Example: MVI A, 21H

Page 24: 8085 Microprocessor

LXI (Load Register-pair Immediate) instruction

This instruction is used to copy 16-bit data specified in the instruction is directly into the register pair (Rp).

Format: LXI Rp, 16-bit data

Example: LXI B, 3E21H

Page 25: 8085 Microprocessor

LDAX (Load Accumulator Indirect) InstructionThis instruction is used to copy data from memory location

pointed by register pair (only BC or DE pair) to the Accumulator (A). HL pair cannot be used in this instruction.

Format: LDAX Rp

A ← [Rp]

Example: LDAX B

Page 26: 8085 Microprocessor

Other Data Copy InstructionsSTAX (Store Accumulator Indirect)

STAX RpLDA (Load Accumulator Direct)

LDA 16-bit addressSTA (Store Accumulator Direct)

STA 16-bit address

Page 27: 8085 Microprocessor

Other Data Copy Instructions• LHLD (Load HL pair Direct) instruction

– LHLD 16-bit address– This instruction is used to load HL register pair by data

stored at memory address specified in the instruction and the next address.

• SHLD (Store HL pair Direct) instruction– SHLD 16-bit address– This instruction is used to store the contents of HL register

pair to memory address specified in the instruction and the next address.

Page 28: 8085 Microprocessor

XCHG (Exchange) instructionXCHGHL ↔ DE

Page 29: 8085 Microprocessor

INPUT/OUTPUT OPERATIONS

IN (Input) instructionIN 8-bit port address

OUT (output) instructionOUT 8-bit port address

Page 30: 8085 Microprocessor

ARITHMETIC OPERATIONS• ADD instruction

– ADD R A ← A + R– ADD M A ← A + [HL]

• ADI (Add Immediate) instruction– ADI 8-bit data A ← A + (8-bit data)

• ADC (Add with Carry) instruction– ADC R A ← A + R + CY– ADC M A ← A + [HL] + CY

• ACI (Add Immediate with Carry) instruction– ACI 8-bit data

• DAD (Double Add) instruction– DAD Rp HL ← HL + Rp

Flags are modified according to the result.

Page 31: 8085 Microprocessor

Ex.: Execution of ADD B instruction

Page 32: 8085 Microprocessor

ARITHMETIC OPERATIONS (continued ...)SUB (Subtract) instruction

SUB R A ← A – RSUB M A ← A – [HL]

SUI (Subtract Immediate) instructionSUI 8-bit data A ← A – 8-bit data

SBB (Subtract with Borrow) instructionSBB R A ← A – (R + Borrow) SBB M A ← A – ([HL] + Borrow) SBI 8-bit data A ← A – (data + Borrow)

All Flags are modified according to the result.

Page 33: 8085 Microprocessor

ARITHMETIC OPERATIONS (continued ...)INR (Increment) instruction

INR R R ← R + 1 INR M [HL] ← [HL] + 1

DCR (Decrement) InstructionDCR R R ← R – 1DCR M [HL] ← [HL] – 1

INX (Increment Register Pair) instruction INX Rp Rp ← Rp + 1

DCX (Decrement register pair) instructionDCX Rp Rp ← Rp – 1

Flags?

Page 34: 8085 Microprocessor

LOGICAL OPERATIONS• ANA (Logical AND with Accumulator) instruction ANA R A ← A & R ANA M A ← A & [HL]• ANI (AND Immediate with Accumulator) instruction ANI 8-bit data A ← A & (8-bit data)

S, Z, and P are modified according to the result. CY is always reset. AC is always set.

Page 35: 8085 Microprocessor

LOGICAL OPERATIONS (continued...)

• ORA (Logical OR with Accumulator) instruction ORA R A ← A | R ORA M A ← A | [HL]• ORI (OR Immediate with Accumulator) instruction ORI 8-bit data

S, Z, and P are modified according to the result. CY and AC are always reset.

Page 36: 8085 Microprocessor

LOGICAL OPERATIONS (continued...)• XRA (Exclusive-OR with Accumulator) instruction XRA R XRA M• XRI (Exclusive-OR Immediate with Accumulator)

instruction XRI 8-bit data

S, Z, and P are modified according to the result. CY and AC are always reset

Page 37: 8085 Microprocessor

LOGICAL OPERATIONS (continued...)

CMA (Complement Accumulator) instructionFormat: CMA Complements the contents of the Accumulator (A). i.e., In the

Accumulator all ones are converted to zeros and all zeros are converted to ones.

AA

Page 38: 8085 Microprocessor

LOGICAL OPERATIONS (continued...)• CMP (Complement) instruction CMP R The contents of the register R are compared with the contents

of the Accumulator (A). Actually, the comparison is done by subtracting the contents

of the register R from the contents of the Accumulator (A). The contents of the register R and the Accumulator do not change.

All flags are modified similar to subtraction.

Page 39: 8085 Microprocessor

Compare InstructionAlthough, all flags are modified, but the conclusion can

be made only by CY and Z flag, as shown below:

If A > R; CY and Z flags are reset. If A = R; Z flag is set and CY flag is reset. If A < R; CY is set and Z flag is reset.

Page 40: 8085 Microprocessor

More compare instructions Compare A with the contents of memory

CMP M• CPI (Compare Immediate) instruction CPI 8-bit data

Page 41: 8085 Microprocessor

Logical Instructions (continued...)

RAL (Rotate Accumulator Left through Carry) instruction

Format: RAL

Page 42: 8085 Microprocessor

Logical Instructions (continued...)

• RLC (Rotate Accumulator Left) instruction

Format: RLC

Page 43: 8085 Microprocessor

Logical Instructions (continued...) • RAR (Rotate Accumulator Right through Carry)

instruction

Format: RAR

Page 44: 8085 Microprocessor

Logical Instructions (continued...)

• RRC (Rotate Accumulator Right) instruction

Format: RRC

Page 45: 8085 Microprocessor

BRANCH OPERATIONSJump instructions

Unconditional Jump instructionFormat: JMP 16-bit memory address

Conditional Jumps instructions JC (Jump on Carry) JNC (Jump on No Carry) JZ (Jump on Zero) JNZ (Jump on No Zero) JP (Jump on Plus) JM (Jump on Minus) JPE (Jump on Parity Even) JPO (Jump on Parity Odd)

Page 46: 8085 Microprocessor

BRANCH OPERATIONS (continued..)Unconditional Call instruction

Format: CALL 16-bit memory addressConditional Call Instructions

CC (Call on Carry) CNC (Call on No Carry) CZ (Call on Zero) CNZ (Call on No Zero) CP (Call on Plus) CM (Call on Minus) CPE (Call on Parity Even) CPO (Call on Parity Odd)

Page 47: 8085 Microprocessor

BRANCH OPERATIONS (continued..)• Unconditional Return Instruction

Format: RET

Conditional Return Instructions RC (Return on Carry) RNC (Return on No Carry) RZ (Return on Zero) RNZ (Return on No Zero) RP (Return on Plus) RM (Return on Minus) RPE (Return on Parity Even) RPO (Return on Parity Odd)

Page 48: 8085 Microprocessor

BRANCH OPERATIONS (continued..)RST (Restart) instructions

Format: RST n

Where n may be 0-7.

Restart Instructions Called Locations

RST 0 0000H

RST 1 0008H

RST 2 0010H

RST 3 0018H

RST 4 0020H

RST 5 0028H

RST 6 0030H

RST 7 0038H

Page 49: 8085 Microprocessor

PCHL (Load PC with HL) instruction

Format: PCHL

This is a special instruction, which copies the contents of HL register pair into the Program Counter (PC) register. Hence the program execution is transferred to the memory location specified by HL register pair.

Page 50: 8085 Microprocessor

MACHINE CONTROL INSTRUCTIONSHLT (Halt) instruction

Format: HLT

NOP (No Operation) instructionFormat: NOP

STC (Set Carry) instructionFormat: STC

CMC (Complement Carry) instructionFormat: CMC

EI, DI, SIM and RIM insructions

Page 51: 8085 Microprocessor

STACK OPERATIONS Initialise Stack Pointer

LXI SP, 16 bit

PUSH instruction PUSH RpPUSH PSW

POP instruction POP RpPOP PSW

XTHL (Exchange Top of the stack with HL) instructionL <-> [SP]; H <-> [SP+1]

SPHL (Load Stack Pointer with HL)SP <- HL

Page 52: 8085 Microprocessor

INSTRUCTION SIZEAccording to the size 8085 instructions are classified into following three groups:

One Byte InstructionsTwo Byte InstructionsThree Byte Instructions

Page 53: 8085 Microprocessor

OPCODE FORMATThe instructions, which use registers or register pairs as their operands, have following codes somewhere in their opcode byte.

Registers Code Register Pairs CodesB 000 BC 00C 001 DE 01D 010 HL 10E 011 AF (PSW) or

SP11

H 100L 101A 111M (memory) 110

Page 54: 8085 Microprocessor

MOV instruction

0 1 D D D S S S

Opcode format of MOV instruction is as follows:

MOV Rd, Rs

Example: opcode of MOV B, C is

0 1 0 0 0 0 0 1 = 41H

Page 55: 8085 Microprocessor

Opcodes of Various MOV instructions

Page 56: 8085 Microprocessor

Opcode format of ADD instruction:

1 0 0 0 0 R R R

Opcode format of SUB instruction:

1 0 0 1 0 R R R

Page 57: 8085 Microprocessor

ADDRESSING MODESRegister Addressing

MOV C, BImmediate Addressing

MVI A, 33HDirect Addressing

STA 3050HIndirect Addressing

MOV B, M

Page 58: 8085 Microprocessor

Assembly Language Programming

Memory Address

Mnemonics Hex Code

Remarks

2000H MVI A, 20H 3EH Store 20H in register A.

2001H 20H2002H MVI B, 30H 06H Store 30H in register B.

2003H 30H2004H ADD B 80H Add contents of register B with A

and store the result in A.2005H OUT 01H D3H Send the contents of A to output

port 01H.2006H 01H2007H HLT 76H Stop the program.

Write an assembly language program to add two 8-bit numbers stored in register A and register B. Display the result at output port 01H.

Page 59: 8085 Microprocessor

Write an assembly language program to add two 8-bit numbers stored in register A and register B. Store the result at the memory location 3000H using STA instruction.

Memory Address

Mnemonics Hex Code

Remarks

2000H MVI A, 20H 3EH Store 20H in register A.2001H 20H2002H MVI B, 30H 06H Store 30H in register B.2003H 30H2004H ADD B 80H Add contents of register B with A and

store the result in A.2005H STA 3000H 32H Store the contents of A (i.e. result) at

the memory location 3000H.2006H 00H2007H 30H2008H HLT 76H Stop the program.

Page 60: 8085 Microprocessor

What is Masking? Assume that 37H is stored in the Accumulator. Mask high-order 4-bits of the given data and display the result on the output port 02H.

Memory Address

Mnemonics Hex Code

Remarks

2000H MVI A, 37H 3EH Store 37H in register A.

2001H 37H

2002H ANI 0FH E6H AND the contents of A with 0FH. (Masking high-order 4-bits)2003H 0FH

2004H OUT 02H D3H Display the contents of A on output port 02H.2005H 02H

2006H HLT 76H Stop the program.

Page 61: 8085 Microprocessor

Add two 8-bit numbers stored in memory location 2050H and 2051H and store the result at memory location 2052H.

Memory Address

Mnemonics Hex Code Remarks

2000H LXI H, 2050H 21H Load memory address of the first number in HL register pair.2001H 50H

2002H 20H2003H MOV A, M 7EH Copy first number into A.2004H INX H 23H Increment the contents of HL

pair. HL pair now pointing to second number.

2005H ADD M 86H Add first & second numbers.2006H STA 2052H 32H Store the result at memory

location 2052H.2007H 52H2008H 20H2009H HLT 76H Stop the program.

Page 62: 8085 Microprocessor

Write an assembly language program to find the largest of three numbers stored in the memory location 2050H, 2051H and 2052H, assuming that all three numbers are unequal.

START

Read A, B, C

A>B?

A>C? B>C?

Display A Display C Display B

STOP

Yes (CY=0) No (CY=1)

Yes (CY=0)No (CY=1) No (CY=1)

Yes (CY=0)

Page 63: 8085 Microprocessor

Write an assembly language program to find the largest of the given list of n data bytes stored in the memory starting from memory location 2071H. Count of data bytes in the list (i.e. n) is stored at memory location 2070H.

START

Initialise Memory PointerInitialise Counter C

A=0

Read number from the liststore in B

A>B?

Store largernumber in A

DecrementCounter C

No

Yes

C=0?

No

Display Highestnumber

Yes

STOP

Page 64: 8085 Microprocessor

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 2070H 21H Initialise the HL register pair with the memory address 2070H of the count.

2001H 70H2002H 20H2003H MOV C, M 4EH Copy count from memory to register C.

2004H XRA A AFH Clear the Accumulator, which will store the largest number.

2005H INX H 23H Increment memory pointer to address 2071H, which is the address of the first number.

2006H LOOP: MOV B, M 46H Copy number stored at address pointed by HL.

2007H CMP B B8H Compare A with B. All flags are modified.

2008H JNC SKIP D2H If Carry flag is not set (B<A) then goto memory location 200CH.

2009H 0CH200AH 20H200BH MOV A, B 78H If B>A. Store larger number in A.

200CH SKIP: INX H 23H Increment memory pointer to the address of the next number.

200DH DCR C 0DH Decrement the counter.

200EH JNZ LOOP C2H Repeat the process from location 2006H if counter is not zero.

200FH 06H2010H 20H2011H OUT 01H D3H When counter reaches zero. Loop is terminated. A

contains the largest number, which is displayed at Port 01H.2012H 01H

2013H HLT 76H Stop the program.

Page 65: 8085 Microprocessor

Write an assembly language program to add the given list of n data bytes stored in the memory starting from memory location 3000H. Store the 8-bit sum in the memory location 3050H. Where n may be any number but for this case choose n=10.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 3000H 21H Store the starting address of the list of data bytes in HL register pair.

2001H 00H2002H 30H2003H MVI C, 0AH 0EH Initialise the counter with 0AH (= 10 in decimal).

2004H 0AH2005H XRA A AFH Clear Accumulator.

2006H LOOP: ADD M 86H Add the data stored at memory location pointed by HL pair with A.

2007H INX H 23H Increment the memory pointer. Now, pointing to the next number.

2008H DCR C 0DH Decrement the counter.

2009H JNZ LOOP C2H Repeat the process, until the conter is zero.

200AH 06H200BH 20H200CH STA 3050H 32H Store the sum (available in A) at memory location 3050H.

200DH 50H200EH 30H200FH HLT 76H Stop the program.

Page 66: 8085 Microprocessor

Write an assembly language program to add the given list of n data bytes stored in the memory starting from memory location 3050H. Store the 16-bit sum in the memory location 3070H (lower byte) and 3071H (higher byte). Where n may be any number but for this case choose n=25.

Memory Address Label Mnemonics Hex Code

Remarks

2000H LXI H, 3050H 21H Store the starting address of the list of data bytes in HL register pair.

2001H 50H2002H 30H2003H MVI C, 19H 0EH Initialise the counter with 19H (= 25 in decimal).

2004H 19H2005H XRA A AFH Clear the Accumulator. (A=00H)2006H MOV B, A 47H Clear the register B. (B=00H).

2007H LOOP: ADD M 86H Add the data stored at memory location pointed by HL pair with A.2008H JNC SKIP D2H If Carry flags is not set, goto memory location 200CH.

2009H 0CH200AH 20H200BH INR B 04H If Carry flag is set, B is incremented by one.200CH SKIP: INX H 23H Increment the memory pointer. Now, pointing to the next number.200DH DCR C 0DH Decrement the counter.200EH JNZ LOOP C2H Repeat the process, until the conter is zero.

200FH 07H2010H 20H2011H STA 3070H 32H Store the low-order byte of the sum (available in A) at memory

location 3070H.2012H 70H2013H 30H2014H MOV A, B 78H Copy high-order byte of the sum to A.

2015H STA 3071H 32H Store the high-order byte of the sum at memory location 3071H.

2016H 71H2017H 30H2018H HLT 76H Stop the program.

Page 67: 8085 Microprocessor

Write an assembly language program to add the set of data bytes stored in the memory starting form 2050H. The end of data string is indicated by 00H. Result may be larger than FFH. Display the sum at port 1 and port 2.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 2050H 21H Store the starting address of the list of data bytes in HL register pair.

2001H 50H2002H 20H2003H XRA A AFH Clear the Accumulator. (A=00H)2004H MOV C, A 4FH Clear the register C. (C=00H).

2005H LOOP: MOV A, M 7EH Read first number in the Accumulator.

2006H CPI 00H FEH Check whether the number is 00H or not.

2007H 00H2008H JZ DISPLAY CAH If it is 00H then goto 2015H to display the sum.

2009H 15H200AH 20H200BH ADD C 81H Otherwise Add the number in A with previous sum in C. Result is

stored in A.200CH JNC SKIP D2H If Carry flags is not set, goto memory location 200CH.

200DH 10H200EH 20H200FH INR B 14H If Carry flag is set, B is incremented by one.2010H SKIP: MOV C, A 4FH Save the low-order sum in C.

2011H INX H 23H Increment the memory pointer. Now, pointing to the next number.

2012H JMP LOOP C3H Repeat the process.

2013H 05H2014H 20H2015H DISPLAY: MOV A, B 78H Copy high-order sum in A.

2016H OUT PORT1 D3H Display it at PORT 1.

2017H PORT12018H MOV A, C 79H Copy low-order sum in A.

2019H OUT PORT2 D3H Display it at PORT 2.

201AH PORT2201BH HLT 76H Stop the program.

Page 68: 8085 Microprocessor

Write an assembly language program to find the sum of positive numbers only and ignore negative numbers from the list of numbers. The length of the list is in memory location 2050H and the series itself begins from memory location 2051H. Store the 8-bit sum at the memory location 3070H.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 2050H 21H Initialise Memory Pointer with the memory address of the count.

2001H 50H2002H 20H2003H MOV C, M 4EH Store Count in C.

2004H XRA A AFH Clear Accumulator.2005H MOV B, A 47H Clear B, which will be used to store the sum.

2006H INX H 23H Increment memory pointer.2007H LOOP: MOV A, M 7EH Copy data stored in the memory location pointed by HL register pair

into A.2008H RLC 07H Rotate Accumulator Left to put D7 bit in Carry flag.

If Carry flag is set by RLC instruction, i.e., the number in Accumulator was negative. Reject the number and jump to 200EH.

2009H JC REJECT DAH

200AH 0EH200BH 20H200CH RRC 0FH If Carry flag is not set. Rotate right the Accumulator to get the original

number in the Accumulator.200DH ADD B 80H Add the positive number with the previous sum stored in B.200EH MOV B, A 47H Store the new sum in B

200FH REJECT: INX H 23H Increment the memory pointer.

2010H DCR C 0DH Decrement counter.2011H JNZ LOOP C2H Repeat the process from 2007H, until counter reaches zero.

2012H 06H2013H 20H2014H MOV A, B 78H Copy the final sum from B to A.

2015H STA 3070H 32H Store the contents of A in memory location 3070H.

2016H 70H2017H 30H2018H HLT 76H Stop the program.

Page 69: 8085 Microprocessor

Write an assembly language program to copy a block of data bytes from one memory location starting from 2051H to another section of memory starting from 3051H. Number of bytes to be copied is given at memory location 2050H.

Memory Address

Label Mnemonics HexCode

Remarks

2000H LXI H, 2050H 21H Initialise memory pointer with the address of the memory location where the count is stored.

2001H 50H

2002H 20H

2003H LXI D, 3051H 11H Store the starting memory address of the destination in DE register pair.

2004H 51H

2005H 30H

2006H MOV C, M 4EH Store the count from memory location pointed by HL pair to C.

2007H INX H 23H Increment memory pointer; now pointing to starting memory address of the source.

2008H LOOP: MOV A, M 7EH Copy source data from the memory location pointed by HL pair into A.

2009H STAX D 12H Copy data in A to destination memory location pointed by DE pair.

200AH INX H 23H Increment source address.

200BH INX D 13H Increment destination address.

200CH DCR C 0DH Decrement counter.

200DH JNZ LOOP C2H Repeat the process from 2008H, until counter reaches zero.

200EH 08H

200FH 20H

2010H HLT 76H Stop the program.

Page 70: 8085 Microprocessor

Write an assembly language program to exchange a block of data bytes stored in the memory starting from 2051H with a block of data bytes stored at another section of memory starting from 3051H. Number of bytes to be exchanged is given at memory location 2050H.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 2050H 21H Initialise memory pointer with the address of the memory location where the count is stored.

2001H 50H2002H 20H2003H LXI D, 3051H 11H Store the starting memory address of the destination in DE

register pair.

2004H 51H2005H 30H2006H MOV C, M 4EH Store the count from memory location pointed by HL pair to C.

2007H INX H 23H Increment memory pointer; now pointing to starting memory address of the source.

2008H LOOP: MOV A, M 7EH Read source data into A.

2009H MOV B, A 47H Save it in B.

200AH LDAX D 1AH Read destination data in A.

200BH MOV M, A 77H Store destination data at source location pointed by HL pair.

200CH MOV A, B 78H Get source data in A.

200DH STAX D 12D Store source data at destination location pointed by DE pair.

200EH INX H 23H Increment source pointer.

200FH INX D 13H Increment destination pointer.

2010H DCR C 0DH Decrement counter.

2011H JNZ LOOP C2H Repeat the process from 2009H, until counter reaches zero.

2012H 08H2013H 20H2014H HLT 76H Stop the program.

Page 71: 8085 Microprocessor

Write an assembly language program for shifting of block of data from memory locations 3000H – 3009H to new memory locations 3050H – 3059H in reverse order. i.e., data from 3000H will be moved to 3059H and so on.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 3000H 21H Initialise the source pointer (i.e., HL pair) with the starting address of the source data

2001H 00H

2002H 30H

2003H LXI D, 3059H 11H Initialise destination pointer (i.e., DE pair) with the last address of the destination

2004H 59H

2005H 30H

2006H MVI C, 0AH 0EH Initialise the counter with 0AH (= 10 in decimal) as given in the question.

2007H 0AH

2008H LOOP: MOV A, M 7EH Read the source data from the memory location pointed by HL pair.

2009H STAX D 12H Store at destination address pointed by DE pair.

200AH INX H 23H Increment source pointer.

200BH DCX D 1BH Decrement destination pointer.

200CH DCR C 0DH Decrement counter.

200DH JNZ LOOP C2H Repeat the process from 2008H, until counter reaches zero.

200EH 08H

200FH 20H

2010H HLT 76H Stop the program.

Page 72: 8085 Microprocessor

Write an 8085 assembly program to check if the Input string of characters (in ASCII codes) stored at location 2050H to 205FH is equal to a string stored at location 2100H to 210FH (in ASCII codes). If two strings are same, display 1 at Port 1, otherwise 0.

Memory Address Label Mnemonics Hex Code

Remarks

2000H LXI D, 2050H 11H Initialise DE pair with the starting address of first data set.

2001H 50H2002H 20H2003H LXI H, 2100H 21H Initialise HL pair with the starting address of second data set.

2004H 00H2005H 21H2006H MVI C, 10H 0EH Initialise counter with 10H (= 16 in decimal).

2007H 10H2008H MVI B, 00H 06H Initialise B with 00H.

2009H 00H200AH LOOP: LDAX D 1AH Read data of the first set from the memory location pointed by DE pair

into A.200BH CMP M BEH Compare data in A with respective data of the second set pointed by HL

pair.200CH JNZ EXIT C2H If Zero flag is not set, i.e., data does not match then jump to 2017H,

where 00H from B is copied to A and displayed.200DH 16H200EH 20H200FH INX H 23H Otherwise increment HL pair.2010H INX D 13H Increment DE pair.2011H DCR C 0DH Decrement counter.2012H JNZ LOOP C2H Repeat the process from 200AH, until counter reaches zero.

2013H 09H2014H 20H2015H MVI B, 01H 3EH Store 01 in B, if data set match is successful.

2016H 01H2017H EXIT: MOV A, B 78H Copy contents of B in A.

2018H OUT 01H D3H Display the contents to A.

2019H 01HHLT 76H Stop the program.

Page 73: 8085 Microprocessor

Write an assembly language program to search a data byte, stored at memory location 3000H in the list of 100 data bytes stored in the memory starting from location 3001H. If the data byte is found, display 01H and if not found display 00H, on the output port 82H.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 3000H 21H HL pair is initialised with the memory address 3000H, where the data byte to be searched is stored.

2001H 00H2002H 30H2003H MOV A, M 7EH Copy the data byte to be searched into A.

2004H MVI B, 01H 06H Store 01H in B. Register B is used to store the value to be displayed.

2005H 01H2006H MVI C, 64H 0EH Initialise the counter with 64H (=100 in decimal) as given in the

question.

2007H 64H2008H INX H 23H Increment the memory pointer; now pointing to first data in the list.2009H LOOP: CMP M BEH Compare the data byte to be searched (in A) with data in the list at

memory location pointed by HL pair.200AH JZ END CAH If zero flag is set, i.e., match is found, then stop the comparison and

jump to memory location 2014H.200BH 14H200CH 20H200DH INX H 23H Otherwise increment HL pair.200EH DCR C 0DH Decrement counter200FH JNZ LOOP C2H Repeat the process from 2009H, until counter reaches zero.

2010H 09H2011H 20H2012H MVI B, 00H 06H Store 00H in B.

2013H 00H2014H END: MOV A, B 78H Copy the contents of B in A.

2015H OUT 82H D3H Display the contents of A.

2016H 82H2017H HLT 76H Stop the program.

Page 74: 8085 Microprocessor

Write a program to multiply two 8-bit numbers. Multiplicand is extended to 16-bit and stored in the two consecutive memory locations 2050H and 2051H. The multiplier is stored at 2052H. Store the 16-bit product at two consecutive memory locations 2053H and 2054H.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LHLD 2050H 2AH Load HL pair with 16-bit multiplicand stored at 2050H and 2051H.

2001H 50H2002H 20H2003H XCHG EBH Exchange the contents of HL with DE pair. Multiplicand is now in DE pair.2004H LDA 2052H 3AH Load 8-bit multiplier into Accumulator.

2005H 52H2006H 20H2007H LXI H, 0000H 21H Copy 0000H in HL pair.

2008H 00H2009H 00H200AH MVI C, 08H 0EH Initialise counter with 08H.

200BH 08H200CH LOOP: DAD H 29H Add HL with HL to shift the contents of HL left by one position.

200DH RAL 17H Shift the contents of Accumulator left by one position.200EH JNC SKIP D2H If Carry flag is not set skip following DAD D instruction.

200FH 12H2010H 20H2011H DAD D 19H Add DE with HL. Store result in HL.2012H SKIP: DCR C 0DH Decrement counter.

2013H JNZ LOOP C2H Repeat the process from 200CH, until counter reaches zero.

2014H 0CH2015H 20H2016H SHLD 2053H 22H Store result in HL to the memory locations 2053H & 2054H.

2017H 53H2018H 20H2019H HLT 76H Stop the program.

Page 75: 8085 Microprocessor

Write an assembly language program to divide a 16-bit dividend, stored in memory locations 2051H & 2052H, by an 8-bit divisor, stored in memory location 2053H. After division the quotient must be stored in memory location 2054H and remainder in memory location 2055H.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LHLD 2051H 2AH Load 16-bit dividend in HL register pair from the memory locations 2051H & 2052H

2001H 51H2002H 20H2003H LDA 2053H 3AH Load 8-bit divisor into A from memory location 2053H.

2004H 53H2005H 20H2006H MOV B, A 47H Copy A into B.

2007H MVI C, 08H 0EH Initialise Counter with 08H.

2008H 08H2009H LOOP: DAD H 29H Shift Dividend and quotient left by one position.

200AH MOV A, H 7CH Copy high-order byte of the dividend in A

200BH SUB B 90H Subtract divisor form high-order byte of the dividend.

200CH JC SKIP DAH If high-order byte of the dividend is less than divisor then go to 200FH.

200DH 0FH200EH 20H200FH MOV H, A 67H Otherwise copy high-order into H.

2010H INR L 2CH Increment the quotient by one.

2011H SKIP: DCR C 0DH Decrement the count.

2012H JNZ LOOP C2H Repeat the process from 2009H, until counter reaches zero.

2013H 09H2014H 20H2015H SHLD 2054H 22H Store the result in Hl pair at memory locations 2054H & 2055H

2016H 54H2017H 20H2018H HLT 76H Stop the program.

Page 76: 8085 Microprocessor

Write an assembly language program to perform addition of two Hexadecimal Numbers as given below:

9A5B8938H & 8BC34AD1H

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 3000H 21H Load starting address of the first set of bytes in HL register pair.

2001H 00H2002H 30H2003H LXI D, 3051H 11H Load starting address of the second set of bytes in DE

register pair.

2004H 50H2005H 30H2006H MVI C, 04 0EH Load the counter with 4, as 4 bytes in each number

given in the question.2007H 04H2008H XRA A AFH Clear the Accumulator and Carry Flag.2009H LOOP: LDAX D 1AH Load accumulator with the first byte of the second

number, stored in the memory location pointed by DE pair.

200AH ADC M 8EH Add Accumulator with the first byte of the first number with carry.

200BH MOV M, A 77H Store the result in the memory pointed by the HL pair. Overwriting the first number.

200CH INX H 23H Increment the memory pointer of the first number.200DH INX D 13H Increment the memory pointer of the second number.200EH DCR C 0DH Decrement the counter.200FH JNC LOOP C2H Repeat the process from 2009H, until counter reaches

zero.2010H 09H2011H 20H2012H HLT 76H Stop the program.

Page 77: 8085 Microprocessor

Write an assembly language program to sort the list of bytes, in ascending order, stored in the memory starting from 2061H. The count of the bytes in the list is stored at memory location 2060H.

Memory Address

Label Mnemonics Hex Code

Remarks

2000H LXI H, 2060H 21H Load the HL pair with the memory address where the count of the list is stored.

2001H 60H2002H 20H2003H MOV C, M 4EH Store the count in C (counter 1).

2004H DCR C 0DH Decrement Counter 1.2005H DOPASS: LXI H, 2061H 21H Initialise HL pair with the memory address of the first number in the list.

2006H 61H2007H 20H2008H MOV D, C 51H Copy counter 1 into counter 2.

2009H CHECK: MOV A, M 7EH Read one number into the accumulator.

200AH INX H 23H Increment HL pair pointing to next number in the list.200BH MOV B, M 46H Copy next number in register B.

200CH DCX H 2BH Decrement HL register pair to get the previous address.200DH CMP B B8H Compare two adjacent numbers.200EH JNC NOSWAP D2H If later number is smaller, then no swap.

200FH 15H2010H 20H2011H MOV M, B 70H Swapping.

2012H INX H 23H2013H MOV M, A 77H

2014H DCX H 2BH2015H INX H 23H2016H NOSWAP: DCR D 15H Decrement counter 2.

2017H JNZ CHECK C2H Repeat process from 2009H, until counter 2 is not zero.

2018H 09H2019H 20H201AH DCR C 0DH Decrement counter 1.201BH JNZ DOPASS C2H Repeat for next pass, until counter 1 is not zero.

201CH 05H201DH 20H201EH HLT 76H Stop the program.

Page 78: 8085 Microprocessor

Stack

Stack is a part of Read/Write memory (RAM) used to store data or binary information temporarily during the execution of the program. The part of the R/W memory, used as a stack, is defined by the programmer. It works on the concept of ‘Last In Fist Out’ (LIFO).

Page 79: 8085 Microprocessor

Stack and Stack Pointer

Microprocessor and R/W Memory are two separate chips. As explained above, Stack is the part of R/W memory.

But the Stack Pointer is a 16-bit register in microprocessor, used to store the memory address of the ‘top of the stack’, i.e., pointing to the top location of the stack.

Page 80: 8085 Microprocessor

Instructions related to Stack

LXI SP, 16 bit PUSH Rp

e.g., PUSH B[SP-1] ← B; [SP-2] ← C

PUSH PSW

Page 81: 8085 Microprocessor

Instructions related to Stack(conti…)POP Rp

e.g., POP DE ← [SP]; D ← [SP+1]

POP PSWXTHL (Exchange Top of the stack with

HL) instruction L <-> [SP]; H<->[SP+1] SPHL instruction SP ← HL

Page 82: 8085 Microprocessor

SubroutineA subroutine is a sub-program (or set of instructions) to perform a specific task, which is written separately from the main program but may be used once or more than once by the main program.

Subroutine once written may also be used in any program.

Page 83: 8085 Microprocessor

Instructions required for using subroutine

CALL 16-bit memory address

RETConditional Call

CC & CNCCZ & CNZCP & CMCPE & CPO

Difference between CALL & JMP?

Conditional ReturnRC & RNCRZ & RNZRP & RMRPE & RPO

Page 84: 8085 Microprocessor

Timing & Time Delay

Important Terms T-State

One subdivision of the operation performed in one clock period is defined as T-state. These subdivisions are internal states synchronised with the system clock, and each T-state is precisely equal to one clock period. The terms T-state and clock period are often used synonymously.

Page 85: 8085 Microprocessor

Machine CycleTime required to complete one operation of accessing memory, I/O, or acknowledge an external request is defined as Machine cycle or Machine Operation. One machine cycle may have 3 to 6 T-States. Various machine cycles in 8085-microprocessor are:

Opcode Fetch Memory Read Memory Write Input/Output Read Input/Output Write Interrupt Acknowledge Halt Hold Reset

Page 86: 8085 Microprocessor

Instruction CycleTime required to complete the execution of an instruction is defined as Instruction Cycle. One instruction cycle consists of 1 to 6 machine cycles in 8085-microprocessor.

Page 87: 8085 Microprocessor

Opcode Fetch Machine Cycle

Page 88: 8085 Microprocessor

Memory Read Machine Cycle

Page 89: 8085 Microprocessor

Memory Write Machine Cycle

Page 90: 8085 Microprocessor

I/O Read Machine Cycle

Page 91: 8085 Microprocessor

I/O Write Machine Cycle

Page 92: 8085 Microprocessor

Time Delay

There are two main techniques for providing time-delay:Software techniqueHardware technique (using Intel 8253/8254)

Page 93: 8085 Microprocessor

The disadvantages of Software Tech. are:Not accurate. The time delay depends on the T-

states of instructions used. Hence cannot be used in real time applications.

Misuse of microprocessor. The microprocessor is busy in simply decrementing the register.

Calculation of time-delay is tedious.Hardware technique requires additional hardware,

i.e., Intel 8253 or 8254 (Programmable Interval Timer). The only disadvantage of this technique is the additional cost for the extra chip. The advantages are

More accurate, hence can be used for real time application.

Microprocessor is free to perform other function.

Page 94: 8085 Microprocessor

Time Delay Using 8-bit register

MemoryAddress

Label Mnemonics HexCode

Remarks T-states

2050H MVI B, FFH 06H Load Register B with FFH. 7

2051H FFH

2052H LOOP: DCR B Decrement Register B. 4

2053H JNZ LOOP Repeat until B reaches zero. 10/7

2054H 52H

2055H 20H

If the clock frequency of the system is (f) = 2 MHzThe Clock period (T) = 1/f = 1/3 x 10-6 = 0.33 μs

Page 95: 8085 Microprocessor

Time delay to execute the statement outside loop, i.e., MVI instruction

DO= 7 T-states x 0.33 μs = 2.31 μsTime delay to execute the loop (DL)= Time period (T) x Loop T-states x Number loaded in the register in

decimalTime period (T) = 0.33 μsLoop T-states = 4 T-states (for DCR instruction) + 10 T-states (for

JNZ instruction)= 14 T-states

Number loaded in the register = FFH = 25510Hence, DL = 0.33 x 14 x 255 = 1178.1 μs ≈ 1.2 msActual Time delay in loop:DLA = DL – (3 T-states x T)

= 1178.1 μs – 3 x 0.33= 1177.11 μs

Hence total delay = DO + DLA

= 2.31 μs + 1177.11 μs= 1179.42 μs≈ 1.2 ms

Page 96: 8085 Microprocessor

Interfacing MemoryPrimary Memory

ROMRAM (R/W)

Secondary MemoryHard DiskCD etc.

Page 97: 8085 Microprocessor

Memory Address & Contents

Page 98: 8085 Microprocessor

Memory with 8 Registers

Page 99: 8085 Microprocessor

Two Memory Chips With Chip Select Pin

Page 100: 8085 Microprocessor

Register AddressesRegisters A3 A2 A1 A0 Address in

HexadecimalCS Register Select

Chip 0 R0 0 0 0 0 =00H

R1 0 0 0 1 =01H

R2 0 0 1 0 =02H

R3 0 0 1 1 =03H

R4 0 1 0 0 =04H

R5 0 1 0 1 =05H

R6 0 1 1 0 =06H

R7 0 1 1 1 =07H

Chip 1 R0 1 0 0 0 =08H

R1 1 0 0 1 =09H

R2 1 0 1 0 =10H

R3 1 0 1 1 =11H

R4 1 1 0 0 =12H

R5 1 1 0 1 =13H

R6 1 1 1 0 =14H

R7 1 1 1 1 =15H

Page 101: 8085 Microprocessor

Interfacing of 8085 with a memory chip of 256 registers: addresses rage from 0000H to 00FFH

Page 102: 8085 Microprocessor

Interfacing All 64K Locations of Memory

Page 103: 8085 Microprocessor

Interfacing I/O PortsTo interact with the real world, microprocessor needs to read data from input devices and send data to output devices. Input/Output devices are connected to microprocessor through Input/Output Ports. There are two ways of data transfer in 8085-microprocessor. One is parallel I/O mode, in which eight bits in a group are transferred from microprocessor to outside world and vice versa. Another is serial I/O mode, in which a single bit is transferred using single data line. In this chapter, we will concentrate only on parallel mode of data transfer.

In parallel I/O mode, there are two techniques by which the devices may be interfaced with 8085-microprocessor.

•Peripheral mapped I/O•Memory mapped I/O

Page 104: 8085 Microprocessor

Interfacing I/O Ports (Peripheral Mapped)

Page 105: 8085 Microprocessor

Interfacing Input Port

Page 106: 8085 Microprocessor

Interfacing an Output Port

Page 107: 8085 Microprocessor

Absolute & Multiple-Address Decoding

When all 8 address lines are decoded to generate one unique output pulse IOSEL, as in the above two examples (Ex. 7.3 and Ex. 7.4), in which the Input/Output device is selected only with one particular address, called Absolute Decoding. Such decoding requires more hardware, hence costly.

To reduce the hardware cost, only few address lines (not all 8) may be used for decoding. This type decoding is called Multiple-Address Decoding, as the used Input/Output device will have multiple addresses.

Page 108: 8085 Microprocessor
Page 109: 8085 Microprocessor

Interfacing I/O Ports with Memory Mapped Tech.

Page 110: 8085 Microprocessor

Interrupts

Software InterruptsRST0, RST1, ……., RST7

Hardware InterruptsTRAP (non-maskable, Vectored)RST7.5, RST6.5, RST5.5 (Maskable, Vectored)INTR (Maskable, non-Vectored)

Page 111: 8085 Microprocessor

Software Interrupts (Restart Instructions)

Restart Instructions Hex Code Call Location

RST0 C7H 0000H

RST1 CFH 0008H

RST2 D7H 0010H

RST3 DFH 0018H

RST4 E7H 0020H

RST5 EFH 0028H

RST6 F7H 0030H

RST7 FFH 0038H

Page 112: 8085 Microprocessor

Hardware Interrupts

Hardware Interrupts

Call Locations

Priority TriggerLevel

TRAP 0024H 1 Level & Edge

RST 5.5 002CH 4 Level

RST 6.5 0034H 3 Level

RST 7.5 003CH 2 Edge

INTR Non-vectored

5 Level

Page 113: 8085 Microprocessor

Instructions related to Interrupts

EI – Enable InterruptsDI – Disable InterruptsSIM – Set Interrupt MaskRIM – Read Interrupt Mask

Page 114: 8085 Microprocessor

SIM Instruction Format

D7 D6 D5 D4 D3 D2 D1 D0

SOD SDE X R7.5 MSE M7.5 M6.5 M5.5

Page 115: 8085 Microprocessor

RIM Instruction Format

D7 D6 D5 D4 D3 D2 D1 D0

SID P7.5 P6.5 P5.5 IE M7.5 M6.5 M5.5