You are on page 1of 50

8085 PrACTICALS

INDEX
Sr. Description Page Date Teacher's
No. No. Signature
1 Familiarization with 8085 microprocessor kit
2 Program to add two 8-bit numbers
3 Program to add two 16-bit numbers
4 Program to add subtract 8-bit numbers
5 Program that multiplies two 1 byte hex numbers
6 Program to find absolute difference between two nos.
7 Program to divide a 1 byte dividend by 1 byte divisor
8 Program to add the contents of block of memory
9 Program to transfer a block of data in reverse order
10 Program to exchange the contents of two blocks
11 Program to find the smallest as well as greatest
number from given block using linear search
12 Program to sort the data in ascending order
13 Program to sort the data in descending order
14 Program to search for the first occurrence of a number
in a given block of data
15 Program to count the occurrence of number in given
block of data
16 Program to find number of odd as well as even
numbers in given block
17 Program to convert a 2 digit BCD number into its
equivalent binary number
18 Program to convert binary number into its BCD
equivalent
19 To identify the working of given program in 8085
20 Program to multiply two 1 byte numbers by rotation
21 Study of transmission media
22 Study of modem, hub, repeaters and routers
Practical No. 2
Aim : To perform addition of two 8-bit numbers

Flow Chart:
Start

Initialize reg. C with 00H

Load first 8 bit number into


accumulator

Move the byte from


accumulator in Reg. B

Load second 8 bit number into


accumulator

Add two numbers

Is No
carry=1?

YES

Increment contents of Reg. C

Store the result in accumulator (SUM)

Move contents of Reg. C into Reg. A

Store the result in accumulator


(CARRY)

Stop
Algorithm :

Step 1: Initialize reg. C to 00H to store carry.


Step 2: Load first number into accumulator.
Step 3: Move the data from accumulator in Reg. B.
Step 4: Load second number into accumulator.
Step 5: Add the contents of Reg. B with accumulator.
Step 6: If carry is generated, increment Reg. C else go to step 7.
Step 7: Store addition into destination memory location.
Step 8: Move the contents of Reg. C into accumulator
Step 9: Store the carry from accumulator to destination
Step 10: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 MVI C, 00H 0E ; Initialize reg. C to 00h, i.e. number of bytes.
2001 00 ; Immediate value 00h.
2002 LDA 2100H 3A ; Load first number from memory 2100 into
accumulator
2003 00 ; Lower-order of 2100H.
2004 21 ; Higher-order of 2100H.
2005 MOV B,A 47 ; Move the data from accumulator in Reg. B.
2006 LDA 2101H 3A ; Load second number from memory 2101 into
accumulator
2007 01 ; Lower-order of 2101H.
2008 20 ; Higher-order of 2101H.
2009 ADD B 80 ; Add two numbers
200A JNC LOOP D2 ; If carry is not generated, go to 200E
200B 0E
200C 20
200D INR C 0C ; If carry is generated, increment Reg. C
200E LOOP: STA 2200 32 ; Store the addition into memory location 2200
200F 00
2010 22
2011 MOV A,C 79 ; Move the data from Reg. C(carry) into accumulator.
2012 STA 2201 32 ; Store the carry into memory location 2201
2013 01
2014 22
2015 HLT 76 ; Stop

Result :

Input Output
2100 FF 2200 04
2101 05 2201 01
Practical No. 3

Aim : To perform addition of two 16-bit numbers.


Flow Chart:
Start

Initialize reg. C with 00H

Load first16 bit number into HL pair

Move the byte from HL in DE pair

Load second 16 bit number into HL pair

Transfer first lower byte to accumulator

Add lower byte of two numbers

Store lower byte addition to destination

Transfer first higher byte to accumulator

Add higher byte of two numbers

Is carry = No
1?

YES

Increment contents of Reg. C

Store the result in accumulator (SUM)

Move contents of Reg. C into Reg. A

Store the result in accumulator (CARRY)

Stop
Algorithm :

Step 1: Initialize reg. C to 00H to store carry.


Step 2: Load first number into HL register pair.
Step 3: Move first data into register pair DE.
Step 4: Load second number into HL register pair.
Step 5: Transfer first lower byte to accumulator
Step 6: Add lower byte of two numbers and store it to destination
Step 7: Transfer first higher byte to accumulator
Step 8: Add higher byte of two numbers and store it to destination
Step 9: If carry is generated, increment Reg. C else go to step 10.
Step 10: Store addition into destination memory location.
Step 11: Move the contents of Reg. C into accumulator
Step 12: Store the carry from accumulator to destination
Step 13: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 MVI C, 00H 0E ; Initialize reg. C to 00h, i.e. number of bytes.
2001 00 ; Immediate value 00h.
2002 LHLD 2100H 2A ; Load first number from memory 2100 into
accumulator
2003 00 ; Lower-order of 2100H.
2004 21 ; Higher-order of 2100H.
2005 XCHG EB ; Exchange data from HL to DE pair
2006 LHLD 2102H 2A ; Load second number from memory 2101 into
accumulator
2007 01 ; Lower-order of 2101H.
2008 20 ; Higher-order of 2101H.
2009 MOV A,L 7D ; Move the data from Reg. L into accumulator.
200A ADD E 83 ; Add two lower byte numbers
200B STA 2200 32 ; Store the addition into memory location 2200
200C 00
200D 22
200E MOV A,H 7C ; Move the data from Reg. H into accumulator.
200F ADD D 82 ; Add two numbers
2010 JNC LOOP D2 ; If carry is not generated, go to 2015
2011 15
2012 20
2013 INR C 0C ; If carry is generated, increment Reg. C
2014 MOV A,C 79 ; Move the data from Reg. C(carry) into accumulator.
2015 LOOP: STA 2201 32 ; Store the carry into memory location 2201
2016 00
2017 22
2018 HLT 76 ; Stop
Result :

Input Output
2100 A2 2200 A4
2101 02 2201 D3
2102 D2
2103 01
Practical No. 4
Aim : To perform subtraction of two 8-bit numbers

Flow Chart:
Start

Initialize reg. C with 00H

Load first 8 bit number into


accumulator

Move the byte from


accumulator in Reg. B

Load second 8 bit number into


accumulator

Subtract contents of Reg. B

Is carry = No
1?

YES

Increment contents of Reg. C

Store the result in accumulator (Difference)

Move contents of Reg. C into Reg. A

Store the result in accumulator (CARRY)

Stop
Algorithm :

Step 1: Initialize reg. C to 00H to store carry.


Step 2: Load first number into accumulator.
Step 3: Move the data from accumulator in Reg. B.
Step 4: Load second number into accumulator.
Step 5: Subtract the contents of Reg. B from accumulator.
Step 6: If carry is generated, increment reg. C contents by 1.
Step 7: Store difference into destination memory location.
Step 8: Move the contents of Reg. C into accumulator
Step 9: Store the carry from accumulator to destination
Step 10: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 MVI C, 00H 0E ; Initialize reg. C to 00h, i.e. number of bytes.
2001 00 ; Immediate value 00h.
2002 LDA 2100H 3A ; Load first number from memory 2100 into
accumulator
2003 00 ; Lower-order of 2100H.
2004 21 ; Higher-order of 2100H.
2005 MOV B,A 47 ; Move the data from accumulator in Reg. B.
2006 LDA 2101H 3A ; Load second number from memory 2101 into
accumulator
2007 01 ; Lower-order of 2101H.
2008 20 ; Higher-order of 2101H.
2009 SUB B 80 ; Subtract two numbers
200A JNC LOOP D2 ; If carry is not generated, go to 200E
200B 0E
200C 20
200D INR C 0C ; If carry is generated, increment Reg. C
200E LOOP: STA 2200 32 ; Store the addition into memory location 2200
200F 00
2010 22
2011 MOV A,C 79 ; Move the data from Reg. C(carry) into accumulator.
2012 STA 2201 32 ; Store the carry into memory location 2201
2013 01
2014 22
2015 HLT 76 ; Stop

Result :

Input Output
2100 02 2200 04
2101 06 2201 00
Practical No. 5
Aim : To perform multiplication of two 8-bit numbers

Flow Chart:
Start

Initialize reg. C and reg. D with 00H

Load first 8 bit number into Reg. B

Load second 8 bit number into Reg. C

Add contents of reg. B into reg.A

Is carry
No
= 1?
YES

Increment reg. D

Decrement contents of Reg. C

Contents
of C=0?
NO

YES

Store the result in accumulator

Move contents of Reg. D into Reg. A

Store the result in accumulator into memory

Stop
Algorithm :

Step 1: Initialize reg. D to 00H to store carry.


Step 2: Initialize accumulator contents with 00H.
Step 3: Load first number into reg. B.
Step 4: Load second number into reg. C.
Step 5: Add contents of Reg. B to accumulator.
Step 6: If carry is not generated, jump to step 8 else jump to step 7.
Step 7: Increment the contents of Reg. D.
Step 8: Decrement contents of reg. C.
Step 9: If contents of reg. C are not zero, jump to step 5 else goto step 10.
Step 10: Store the contents of accumulator into destination memory location.
Step 11: Move the contents of Reg. D into accumulator.
Step 12: Store the contents of accumulator to destination.
Step 13: Halt.

Program:

Address Label Mnemonics Opcode Comment


2000 MVI D, 00H 16 ; Initialize reg. D to 00h, i.e. number of bytes.
2001 00 ; Immediate value 00h.
2002 MVI A,00H 3E ; Initialize accumulator to 00h
2003 00
2004 LXI H,2100H 21 ; Load first number from memory 2100 into HL pair
2005 00 ; Lower-order of 2100H.
2006 21 ; Higher-order of 2100H.
2007 MOV B,M 46 ; Get first no. in reg. B.
2008 INX H 23 ; Load second number from memory 2101 into HL
pair
2009 MOV C,M 4E ; Get second no. in reg. C.
200A LOOP2: ADD B 80 ; Add contents of B to accumulator
200B JNC LOOP1 D2 ; If carry is not generated, go to 200FH
200C 0F
200D 20
200E INR D 14 ; Increment reg. D contents
200F LOOP1: DCR C 0D ; Decrement contents of reg. C
2010 JNZ LOOP2 02 ; If contents of reg. C are not zero, jump to 200AH
2011 0A
2012 20
2013 STA 2200H 32 ; Store accumulator contents into memory location
2200H
2014 00
2015 22
2016 MOV A,D 7A ; Move contents of Reg. D into accumulator
2017 STA 2201H 32 ; Store accumulator contents into memory location
2201H
2018 01
2019 22
201A HLT 76 ; Stop
Result :

Input Output
2100 02 2200 06
2101 03 2201 00
Practical No. 6
Aim : To find absolute difference between two numbers.

Flow Chart:

Start

Load first 8 bit number

Move contents from memory into Reg. A

Load second 8 bit number

Compare the two numbers

Is carry
No
= 1?
YES

Move contents from reg. A into Reg. C

Move contents from reg. B into Reg. A

Move contents from reg. C into Reg. B

Subtract two numbers

Store the result in accumulator into memory

Stop
Algorithm :

Step 1: Initialize H-L pair to source memory location.


Step 2: Move the byte from source to accumulator.
Step 3: Increment the H-L pair to load second byte.
Step 4: Move the byte from memory to reg. B.
Step 5: Compare the two data bytes.
Step 6: If carry is not generated, go to step 8 else go to step 7.
Step 7: Swap the two numbers.
Step 8: Subtract two numbers.
Step 9: Store result at destination memory location.
Step 10: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 LXI H, 2100H 21 ; Initialize H-L pair to source memory location.
2001 00 ; Lower-order of 2100H.
2002 21 ; Higher-order of 2100H.
2003 MOV A, M 7E ; Move the byte from memory to accumulator.
2004 INX H 23 ; Increment H-L pair.
2005 MOV B,M 46 ; Move the byte from reg. B to reg. C.
2006 CMP B B8 ; Compare the two bytes.
2007 JNC SKIP D2 ; If carry is not generated, go to 200D.
2008 0D
2009 20
200A MOV C,A 4F ; Move the byte from accumulator to reg. C.
200B MOV A,B 78 ; Move the byte from reg. B to accumulator.
200C MOV B,C 41 ; Move the byte from reg. C to reg. B.
200D SKIP: SUB B 90 ; Subtract two numbers.
200E STA 2200 32 ; Store the byte from accumulator to destination.
200F 00 ; Lower-order of 2200H.
2010 22 ; Higher-order of 2200H.
2011 HLT 76 ; Halt

Result :

Input Output
2100 06 3100 04
2101 02 3102 00
Practical No. 7
Aim : To divide a 1 byte dividend by 1 byte divisor.

Flow Chart:

Start

Load first byte 07H into reg. A

Load second byte 07H into reg. A

Initialize reg. C with 00H

reg. C of reg. B
Subtract contents

Increment reg. C

Compare reg. C with reg. A

Is carry No
= 1?

YES
Store the result in accumulator

Move contents of Reg. C into Reg. A

Store the result in accumulator into memory

Stop
Algorithm :

Step 1: Move first byte immediately to accumulator.


Step 2: Move second byte immediately to reg. B.
Step 3: Move data 00H immediately to reg. C.
Step 4: Subtract reg. A & B contents.
Step 5: Increment the content of reg. C.
Step 6: Compare reg. C contents with accumulator.
Step 7: Jump to Step 4 if no carry is generated.
Step 8: Store the remainder from accumulator to destination 2200H.
Step 9: Move contents of reg. C to reg. A.
Step 10: Store quotient from accumulator to destination 2201H.
Step 11: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 MVI A,07H 3E ; Initialize reg. A to 07h.
2001 07 ; Immediate value 07h.
2002 MVI B,02H 06 ; Initialize reg. B to 02h.
2003 02 ; Immediate value 02h.
2004 MVI C,00H 0E ; Initialize reg. C to 00h.
2005 00 ; Immediate value 00h.
2006 BACK: SUB B 90 ; Subtract reg. A & B contents.
2007 INR C 0C ; Increment contents of reg. C.
2008 CMP C B9 ; Compare reg. C with accumulator.
2009 JNC BACK D2 ; Jump to address 2006H if carry is not zero.
200A 06
200B 20
200C STA 2200 32 ; Store remainder to address location 2200H.
200D 00 ; Lower-order of 2200H.
200E 22 ; Higher-order of 2200H.
200F MOV A,C 79 ; Move the content from reg. C to accumulator.
2010 STA 2201 32 ; Store quotient to address location 2201H.
2011 01 ; Lower-order of 2201H.
2012 22 ; Higher-order of 2201H.
2013 HLT 76

Result :

Output
2200 01
2201 03
Practical No. 8
Aim : A block of data is stored in memory locations from 2200h. Another block
of data having the same length is stored in memory locations starting from
2300h. Write a program to add the contents of block of memory.

Flow Chart:
Start

Initialize H-L pair to source block 1

Initialize B-C pair to source block 2

Initialize D-E pair to destination block 3

Load second block contents to accumulator

Add first block contents with accumulator

Store the result to destination block 3

Increment Source pointer HL pair

Increment Source pointer BC pair

Increment destination pointer D-E pair

Move reg. L contents to accumulator

Compare accumulator contents with 0Ah

Is Z = 1? NO

YES
Stop
Algorithm :

Step 1: Initialize H-L pair to source memory location 2200H for first block.
Step 2: Initialize B-C pair to source memory location 2300H for second block.
Step 3: Initialize D-E pair to destination memory location 2400H.
Step 4: Load second block contents to accumulator.
Step 5; Add H-L pair contents with accumulator.
Step 6: Store the byte from accumulator to destination D-E pair location.
Step 7: Increment the source pointer H-L pair.
Step 8: Increment the source pointer B-C pair.
Step 9: Increment the destination pointer D-E pair
Step 10: Move the lower byte of H-L pair to accumulator.
Step 11: Compare the accumulator contents with 0Ah.
Step 12: Jump to Step 6 if zero flag is not set.
Step 13: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 LXI H,2200H 21 ; Initialize H-L pair for source block 1.
2001 00 ; Lower-order of 2200H.
2002 22 ; Higher-order of 2200H.
2003 LXI B,2300H 01 ; Initialize B-C pair for source block 2.
2004 00 ; Lower-order of 2300H.
2005 23 ; Higher-order of 2300H.
2006 LXI D,2400H 11 ; Initialize D-E pair to destination block 3.
2007 00 ; Lower-order of 2400H.
2008 24 ; Higher-order of 2400H.
2009 LOOP: LDAX B 0A ; Load second block contents to accumulator.
200A ADD M 86 ; Add memory content with accumulator.
200B STAX D 12 ; Store the byte from accumulator to block 3.
200C INX H 23 ; Increment the source pointer H-L pair.
200D INX B 0B ; Increment the source pointer B-C pair.
200E INX D 13 ; Increment the destination pointer D-E pair.
200F MOV A,L 7D ; Move the reg. L contents to accumulator.
2010 CPI 0A FE ; Compare accumulator contents with 0Ah.
2011 0A ; Data byte 0Ah.
2012 JNZ LOOP D2 ; Jump to address 2009H if zero flag is not set.
2013 09
2014 20
2015 HLT 76 ; Halt
Result:

Input Block 1 Input Block 2 Output Block 3


2200 01 2300 10 2400 11
2201 02 2301 20 2401 22
2202 03 2302 30 2402 33
2203 04 2303 40 2403 44
2204 05 2304 50 2404 55
2205 06 2305 60 2405 66
2206 07 2306 70 2406 77
2207 08 2307 80 2407 88
2208 09 2308 90 2408 99
2209 10 2309 15 2409 25
Practical No. 9

Aim : A block of data is stored in memory locations from 2100h to 2109h.


Write a program to transfer the data in reverse order to memory
locations starting from 3100h.

Flow Chart:

Start

Initialize counter C to number of


bytes

Initialize H-L pair to source


memory location

Initialize D-E pair to destination


memory location

Move the byte from source to


accumulator

Move the byte from accumulator


to destination

Increment Source pointer HL pair

Decrement destination pointer D-


E pair

Decrement counter C.

Is Counter No
= 0?

Yes

Stop
Algorithm :

Step 1: Initialize reg. C to 0AH, i.e. number of bytes.


Step 2: Initialize H-L pair to source memory location.
Step 3: Initialize D-E pair to destination memory location.
Step 4: Move the byte from source to accumulator.
Step 5: Store the byte from accumulator to destination
Step 6: Increment the source pointer H-L pair
Step 7: Decrement the destination pointer D-E pair
Step 8: Decrement counter C
Step 9: Jump to Step 4 if counter is not zero.
Step 10: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 MVI C, 0AH 0E ; Initialize reg. C to 0Ah, i.e. number of bytes.
2001 0A ; Immediate value 0Ah.
2002 LXI H, 2100H 21 ; Initialize H-L pair to source memory location.
2003 00 ; Lower-order of 2100H.
2004 21 ; Higher-order of 2100H.
2005 LXI D, 3109H 11 ; Initialize D-E pair to destination memory location.
2006 09 ; Lower-order of 3109H.
2007 31 ; Higher-order of 3109H.
2008 LOOP: MOV A, M 7E ; Move the byte from source to accumulator.
2009 STAX D 12 ; Store the byte from accumulator to destination.
200A INX H 23 ; Increment the source pointer H-L pair.
200B DCX D 1B ; Decrement the destination pointer D-E pair.
200C DCR C 0D ; Decrement counter C.
200D JNZ LOOP C2 ; Jump to address 2008H if counter is not zero.
200E 08 ; Lower-order of 2008H.
200F 20 ; Higher-order of 2008H.
2010 HLT 76 ; Halt

Result :

Input Output
2100 01 3100 09
2101 02 3102 08
2102 03 3103 07
2103 04 3104 06
2104 05 3105 05
2105 06 3106 04
2106 07 3107 03
2107 08 3108 02
2108 09 3109 01
Practical No. 10
Aim : A block of data is stored in memory locations from 2501h. Another block
of data having the same length is stored in memory locations starting from
3501h. Size of the block is stored in memory location 2500h.Write a
program to exchange the contents of these two blocks.

Flow chart :
Start

Initialize H-L pair to memory location to get count

Move the contents of memory to Reg C i.e. counter

Initialize D-E pair with address one byte less than actual
destination

Increment HL and DE Pairs

Move the 1st byte of 1st block in Reg B

Move the 1st byte of 2nd block in Reg A

Store contents of Reg A in memory

Copy contents of Reg B in Reg A

Store the contents of A register into memory location 3000H

Decrement counter C.

NO
Is Counter =
0?

YES
Stop

Algorithm :
Step 1: Initialize HL register pair as a pointer to memory location for counter
Step 2: Initialize the counter Reg C
Step 3: Initialize DE register pair as a pointer to memory location 3500H
Step 4: Increment HL pair and DE pair
Step 5: Get the contents of memory location 2501H into B register
Step 6: Get the contents of memory location 3501H into A register
Step 7: Store the contents of A register into memory location 2501H
Step 8: Copy the contents of B register into accumulator
Step 9: Store the contents of A register into memory location 3501H
Step 10: Decrement contents of C
Step 11: If counter is not zero, jump to Step 4
Step 12: Halt
Program:
Address Label Mnemonics Opcode Comment
2000 LXI H, 2500 21 ; Initialize HL reg pair as a pointer to memory location 2500H.
2001 00
2002 25
2003 MOV C, M 4E ; Initialize the counter
2004 LXI D, 3500 11 ; Initialize DE reg pair as a pointer to memory location 3501H
2005 00
2006 35
2007 LOOP: INX H 23 ; Increment HL pair
2008 INX D 13 ; Increment DE pair
2009 MOV B, M 46 ; Get the contents of memory location 2501H into B register
200A LDAX D 1A ; Get the contents of memory location 3501H into A register
200B MOV M, A 77 ; Store the contents of A register into memory location 2501H
200C MOV A, B 78 ; Copy the contents of B register into accumulator
200D STAX D 12 ; Store the contents of A register into memory location
3501H.
200E DCR C 0D ; Decrement contents of C
200F JNZ LOOP C2 ; If counter is not zero, jump to LOOP
07
20
2010 HLT 76 ; Halt

Result :
Input Output
2500 0A (Count) 2500 0A (Count)
2501 01 3501 11 2501 11 3501 01
2502 02 3502 12 2502 12 3502 02
2503 03 3503 13 2503 13 3503 03
2504 04 3504 14 2504 14 3504 04
2505 05 3505 15 2505 15 3505 05
2506 06 3506 16 2506 16 3506 06
2507 07 3507 17 2507 17 3507 07
2508 08 3508 18 2508 18 3508 08
2509 09 3509 19 2509 19 3509 09
250A 0A 350A 1A 250A 1A 350A 0A
Practical No. 11
Aim : A block of data is stored in memory locations from 2100h to 2109h.
Write a program to find the smallest as well as greatest number from given
block using Linear Search. Store the results immediately after the end of the block.

Flow Chart:
Start

Get the count of numbers to search in Reg. B

Get the first number in Reg. C & Reg. D

Decrement the count

Increment the memory pointer

Move the memory content into accumulator

Compare contents of accumulator with reg. C

YES Contents of Reg


A < Memory ?
NO
Move the accumulator contents to Reg C

Contents of Reg
YES
A > Memory ?
NO
Move the accumulator contents to Reg D

Decrement the counter

Is Counter = YES
0?
NO

Move the contents of Reg. C to Reg A

A
A

Store largest number in MEMORY

Move the contents of Reg. D to Reg A

Store smallest number in MEMORY

Stop
Algorithm:

Step 1: Load the address of the first element (Count) of the array in HL pair.
Step 2: Move the count to Reg. B.
Step 3: Increment the pointer.
Step 4: Get the first data in Reg. C and D.
Step 5: Decrement the count.
Step 6: Increment the memory pointer.
Step 7: Move this number in accumulator.
Step 8: Compare the content of Reg C with accumulator.
Step 9: If Carry = 1, go to step 11 else goto step 10.
Step 10: Move the contents of accumulator to Reg C.
Step 11: If Carry = 0, go to step 13 else goto step 12.
Step 12: Move the contents of accumulator to Reg D.
Step 13: Decrement the counter.
Step 14: If counter = 0, go to step 6. If counter is not Zero, goto next step
Step 15: Move the reg. C contents to accumulator.
Step 16: Store the largest data in memory location 2200h.
Step 17: Move the reg. D contents to accumulator.
Step 18: Store the largest data in memory location 2201h.
Step 19: Halt

Program :

Address Label Mnemonics Opcode Comment


2000 LXI H, 2100h 21 ; Set pointer for array
2001 00 ; Lower byte of 2100h
2002 21 ; Higher byte of 2100h
2003 MOV B, M 46 ; Load the count in reg. B
2004 INX H 23 ; Increment HL pair
2005 MOV C, M 4E ; set 1st element as largest data in reg. C
2006 MOV D,M 56 ; Move the no. in reg. D
2007 DCR B 05 ; decrement the count
2008 LOOP3: INX H 23 ; Increment HL pair
2009 MOV A,M 7F ; Load first byte in accumulator
200A CMP C B9 ; Compare contents of reg. C with Reg A
200B JC LOOP1 DA ; If Reg A < C, go to LOOP1
200C 0F
200D 20
200E MOV C,A 4F ; set new value as largest
200F LOOP1: JNC LOOP2 D2 ; If Reg A > C, go to LOOP2
2010 13
2011 20
2012 MOV D,A 57 ; set new value as smallest
2013 LOOP2: DCR B 05 ; decrement the count
2014 JNZ LOOP3 C2 ; repeat comparison till counter = 0
2015 08
2016 20
2017 MOV A,C 79 ; Move the reg. C contents in reg. A
2018 STA 2200 H 32 ; store largest value at 2200H
2019 00
201A 22
201B MOV A,D 7A ; Move the reg. D contents in reg. A
201C STA 2201 H 32 ; store smallest value at 2201H
201D 01
201E 22
201F HLT 76 ; Halt

Result :

Input Output
2100 09 2200 09
2101 01 2201 01
2102 07
2103 09
2104 05
2105 06
2106 03
2107 08
2108 04
2109 02
Practical No. 12
Aim : A block of data is stored in memory locations from 2201h. The length of
the block is stored at 2200. Write a program that sorts the given data in
Ascending Order.

Start
Flow Chart:
Initialize Counter 1

Initialize Memory Pointer


Initialize Counter 2

Get the number

Increment memory pointer

NO Is contents of (memory
pointer – 1) > contents
of (Pointer)?

YES

Interchange the contents

Decrement Counter 2; Increment memory pointer

NO Is Counter2
= 0?
YES

Decrement Counter 1

NO Is Counter1
= 0?

YES
Stop
Algorithm :
Step 1: Initialize the HL pair with memory location 2100H to get count of numbers
Step 2: Move the contents of memory to Reg. C i.e. counter
Step 3: Decrement Reg. C
Step 4: Load HL pair with address 2101H
Step 5: Move contents of memory to Reg. A
Step 6: Increment HL Pair
Step 7: Compare memory with Reg. A
Step 8: If contents of A are less or equal, don’t interchange
Step 9: Interchange the numbers
Step 10: Increment HL pair
Step 11: Decrement counter 2
Step 12: If counter is not zero, jump to Step 4
Step 13: Decrement counter 1
Step 14: If counter 1 is not zero, jump to Step 2
Step 15: Halt
Program:
Address Label Mnemonics Opcode Comment
2000 LXI H, 2100H 21 ;Initialize HL pair with memory location 2100H
2001 00
2002 21
2003 MOV C, M 4E ;Move the contents of memory to Reg. C
2004 DCR C 0D ;Decrement Reg. C
2005 REPEAT: MOV D, C 51 ; Move the contents of C to D (Counter 2)
2006 LXI H, 2101H 21 ; Load HL pair with address 2101H
2007 01
2008 21
2009 LOOP: MOV A, M 7E ; Move contents of memory to Reg. A
200A INX H 23 ; Increment HL Pair
200B CMP M BE ; Compare memory with Reg. A
200C JC SKIP DA
200D 14
200E 20
200F MOV B, M 46 ; Move contents of M to B
2010 MOV M, A 77 ; Move contents of A to M
2011 DCX H 2B ; Decrement HL Pair
2012 MOV M, B 70 ; Move contents of B to M
2013 INX H 23 ; Increment HL pair
2014 SKIP: DCR D 15 ; Decrement D
2015 JNZ LOOP C2 ; Jump if Contents of D are not zero
2016 09
2017 20
2018 DCR C 0D ; Decrement contents of C
2019 JNZ REPEAT C2 ; Jump if contents of C are not zero
201A 05
201B 20
201C HLT 76 ; Halt
Result :

Input Output
2100 09 2100 09
2101 01 2101 01
2102 07 2102 02
2103 09 2103 03
2104 05 2104 04
2105 06 2105 05
2106 03 2106 06
2107 08 2107 07
2108 04 2108 08
2109 02 2109 09
Practical No. 13
Aim : A block of data is stored in memory locations from 2201h. The length of
the block is stored at 2200. Write a program that sorts the given data in
Descending Order.

Start

Flow Chart:
Initialize Counter 1

Initialize Memory Pointer


Initialize Counter 2

Get the number

Increment memory pointer

YES Is contents of (memory


pointer – 1) > contents
of (Pointer)?

NO

Interchange the contents

Decrement Counter 2; Increment memory pointer

NO Is Counter2
= 0?
YES

Decrement Counter 1

NO
Is Counter1
= 0?

YES
Stop
Algorithm :
Step 1: Initialize the HL pair with memory location 2100H to get count of numbers
Step 2: Move the contents of memory to Reg. C i.e. counter
Step 3: Decrement Reg. C
Step 4: Load HL pair with address 2101H
Step 5: Move contents of memory to Reg. A
Step 6: Increment HL Pair
Step 7: Compare memory with Reg. A
Step 8: If contents of A are greater, don’t interchange
Step 9: Interchange the numbers
Step 10: Increment HL pair
Step 11: Decrement counter 2
Step 12: If counter is not zero, jump to Step 4
Step 13: Decrement counter 1
Step 14: If counter 1 is not zero, jump to Step 2
Step 15: Halt
Program:
Address Label Mnemonics Opcode Comment
2000 LXI H, 2100H 21 ;Initialize the HL pair with memory location
2100H
2001 00
2002 21
2003 MOV C, M 4E ;Move the contents of memory to Reg. C
2004 DCR C 0D ;Decrement Reg. C
2005 REPEAT: MOV D, C 51 ; Move the contents of C to D (Counter 2)
2006 LXI H, 2101H 21 ; Load HL pair with address 2101H
2007 01
2008 21
2009 LOOP: MOV A, M 7E ; Move contents of memory to Reg. A
200A INX H 23 ; Increment HL Pair
200B CMP M BE ; Compare memory with Reg. A
200C JNC SKIP D2
200D 14
200E 20
200F MOV B, M 46 ; Move contents of M to B
2010 MOV M, A 77 ; Move contents of A to M
2011 DCX H 2B ; Decrement HL Pair
2012 MOV M, B 70 ; Move contents of B to M
2013 INX H 23 ; Increment HL pair
2014 SKIP: DCR D 15 ; Decrement D
2015 JNZ LOOP C2 ; Jump if Contents of D are not zero
2016 09
2017 20
2018 DCR C 0D ; Decrement contents of C
2019 JNZ REPEAT C2 ; Jump if contents of C are not zero
201A 05
201B 20
201C HLT 76 ; Halt
Result :

Input Output
2100 09 2100 09
2101 01 2101 09
2102 07 2102 08
2103 09 2103 07
2104 05 2104 06
2105 06 2105 05
2106 03 2106 04
2107 08 2107 03
2108 04 2108 02
2109 02 2109 01
Practical No. 14
Aim: A block of data is stored in memory locations from 2101h. Length of the
block is stored at 2100h. Write program that searches for first occurrence
of the data byte 05h in the given block. Store the address of this occurrence
in the HL pair. If number not found, then HL pair must contain 0000h.

Flow Chart:
Start

Initialize HL pair with address 2100 to get count in Reg B

Initialize H-L pair to memory location of 1st data to compare

Store the data whose occurrence to be checked in Reg C

Get the number in Accumulator and compare it with Reg C

YES
Is Zero Flag
= 1?

NO

Increment HL contents and Decrement Reg B

NO
Is Reg B =
0?

YES

Make HL contents 0000h

Store the contents of HL pair at 2200H

Stop
Algorithm :

Step 1: Initialize H-L pair to get the count of numbers and store it in Reg B
Step 2: Store the number to be searched in Reg C
Step 3: Initialize H-L pair for number to search and store it in Reg A
Step 4: Compare contents of Reg C
Step 5: If Reg A = Reg C, goto Step 8 else goto Step 6
Step 6: Increment HL pair and Decrement the counter i.e. Reg B
Step 7: If Reg B contents are zero, store 0000h in HL pair else goto Step 3
Step 8: Store the contents of HL pair at 2200h
Step 9: Halt

Program:
Address Label Mnemonics Opcode Comment
2000 LXI H, 2100 21 ; Initialize memory pointer to get the count
2001 00
2002 21
2003 MOV B, M 46 ; Store the count into Reg B
2004 LXI H, 2101 21 ; Initialize memory pointer for data
2005 01
2006 21
2007 MVI C, 05h 0E ; Store the number to be searched in Reg C
2008 05
2009 REPEAT: MOV A, M 7E ; Move contents of Memory to Reg A
200A CMP C B9 ; Compare contents of Reg A with Reg C
200B JZ LAST CA ; Jump if Reg A = Reg C
200C 1C
200D 20
200E INX H 23 ; Increment HL pair contents
200F DCR B 05 ; Decrement Reg B
2010 JNZ REPEAT C2 ; Jump if contents of Reg B is not zero
2011 09
2012 20
2013 LXI H, 0000h 21 ; Load HL pair with address 0000h
2014 00
2015 00
2016 SHLD 2200h 22 ; Store contents of HL pair to address 2200h
2017 00
2018 22
2019 JMP END C3 ; Jump to END
201A 1F
201B 20
201C LAST: SHLD 2200h 22 ; Store memory address to memory 2200h
201D 00
201E 22
201F END: HLT 76 ; Halt
Result :

Reg C : 05h Output


Input
2100 09 (Count) 2200 05
2101 01 2201 21
2102 02
2103 03
2104 04
2105 05
2106 06
2107 07
2108 08
2109 09
Practical No. 15
Aim: A block of data is stored in memory locations from 2101h. Length of the
block is stored at 2100h. Write program that searches for first occurrence
of the data byte 05h in the given block. Store the count of this occurrence
in the HL pair. If number not found, then HL pair must contain 0000h.

Flow Chart:
Start

Initialize HL pair with address 2100 to get count in Reg B

Initialize H-L pair to memory location of 1st data to compare & Reg E for count

Store the data whose occurrence to be checked in Reg C

Get the number in Accumulator and compare it with Reg C

YES
Is Zero Flag
= 1?

NO

Increment contents of Reg E

Increment HL contents and Decrement Reg B

NO
Is Reg B =
0?

YES
Move contents of Reg E to Reg A

Store contents of Reg A to memory 2200h

Stop
Algorithm :

Step 1: Initialize H-L pair to get the count of numbers and store it in Reg B
Step 2: Store the number to be searched in Reg C
Step 3: Load HL pair for number to compare and store it in Reg A
Step 4: Compare contents of Reg C
Step 5: If Reg A ! = Reg C, goto Step 8 else goto Step 6
Step 6: Increment HL pair and Decrement the counter i.e. Reg B
Step 7: If Reg B contents are not zero, goto step 3 else goto step 8
Step 8: Increment contents of Reg E
Step 9: Move contents of Reg E into Reg A and store it to memory 2200h
Step 9: Halt

Program:
Address Label Mnemonics Opcode Comment
2000 LXI H, 2100 21 ; Initialize memory pointer to get the count
2001 00
2002 21
2003 MOV B, M 46 ; Store the count into Reg B
2004 LXI H, 2101 21 ; Initialize memory pointer for data
2005 01
2006 21
2007 MVI C, 05h 0E ; Store the number to be searched in Reg C
2008 05
2009 REPEAT: MOV A, M 7E ; Move contents of Memory to Reg A
200A CMP C B9 ; Compare contents of Reg A with Reg C
200B JNZ NEXT C2 ; Jump if Reg A != Reg C
200C 0F
200D 20
200E INR E 1C ; Increment Reg E
200F NEXT: INX H 23 ; Increment HL pair contents
2010 DCR B 05 ; Decrement Reg B
2011 JNZ REPEAT C2 ; Jump if contents of Reg B is not zero
2012 09
2013 20
2014 MOV A, E 7B ; Move the contents of Reg E to Reg A
2015 STA 2200h 32 ; Store contents of accumulator into 2200h
2016 00
2017 22
2018 HLT 76 ; Halt
Result :

Reg C : 05h Output


Input
2100 09 (Count) 2200 03
2101 01
2102 02
2103 03
2104 04
2105 05
2106 05
2107 07
2108 05
2109 09
Practical No. 16
Aim : A block of data is stored in memory locations from 2501h. Size of the block is
stored in memory location 2500h.Write a program to find number of odd as well as even
numbers in given block.

Flow Chart:
Start

Initialize source Memory Pointer with 2500

Reset carry flag

Initialize reg. B to 05H

Set reg. C as odd counter to 00h

Set reg. D as even counter to 00h

Move memory contents to accumulator

Rotate accumulator contents to right through carry


No
Yes
Is Carry=0?
NO
Increment reg. D
Increment reg. C i.e. odd counter i.e. even counter

Increment memory pointer HL pair

Decrement Counter B

YES
Is Counter = 0?

NO
Initialize destination Memory Pointer with 2600

Store odd and even counters

Stop
Algorithm :

Step 1: Initialize H-L pair to source memory location.


Step 2: Reset the carry flag of accumulator.
Step 3: Initialize reg. B to 05H, i.e. number of bytes.
Step 4: Set reg. C as odd counter to 00h.
Step 5: Set reg. D as even counter to 00h.
Step 6: Move the byte from source to accumulator.
Step 7: Rotate accumulator contents to right through carry.
Step 8: If carry is not set, go to step 11, else proceed.
Step 9: Increment odd counter.
Step 10: Jump to step 12.
Step 11: Increment even counter.
Step 12: Increment the source pointer H-L pair
Step 13: Decrement the counter B.
Step 14: Decrement counter C
Step 15: Jump to Step 6 if counter is not zero.
Step 16: Set HL pair for destination.
Step 17: Store odd and even counters at these locations.
Step 18: Halt.

Program:

Address Label Mnemonics Opcode Comment


2000 LXI H,2500H 21 ; Initialize H-L pair to source memory location.
2001 00 ; Lower-order of 2500H.
2002 25 ; Higher-order of 2500H.
2003 XRA A AF ; Reset carry flag
2004 MVI B,05H 06 ; Initialize reg. B to 05h, i.e. number of bytes.
2005 05 ; Immediate value 05h.
2006 MVI C,00H 0E ; Initialize reg. C to 00h, i.e. number of bytes.
2007 00 ; Immediate value 00h.
2008 MVI D,00H 16 ; Initialize reg. D to 00h, i.e. number of bytes.
2009 00 ; Immediate value 00h.
200A AGAIN: MOV A, M 7E ; Move the byte from source to accumulator.
200B RAR 1F ; Rotate accumulator contents to right through carry
200C JNC DOWN D2 ; Jump to address 2013H if carry is not set.
200D 13
200E 20
200F INR C 0C ; Increment odd counter.
2010 JMP EVEN C3 ; Jump to address 2014h.
2011 14
2012 20
2013 DOWN: INR D 14 ; Increment even counter.
2014 EVEN: INX H 23 ; Increment the source pointer H-L pair.
2015 DCR B 05 ; Decrement counter B.
2016 JNZ AGAIN 02 ; Jump to address 200AH if counter is not zero.
2017 0A
2018 20
2019 LXI H,2600 21 ; Set HL pair for destination.
201A 00 ; Lower byte of 2600h.
201B 26 ; Higher byte of 2600h.
201C MOV M,C 71 ; Store odd counter.
201D INX H 23 ; Increment the destination pointer H-L pair.
201E MOV M,D 72 ; Store even counter.
201F HLT 76 ; Halt

Result :

Input Output
2500 11 2600 01
2501 12 2601 04
2502 14
2503 16
2504 18
Practical No. 17
Aim : Write a program to convert a 2 digit BCD number into its equivalent binary
number.

Flow Chart:
Start

Load HL pair with given BCD number

Initialize reg. C with 09h

Move the byte from source to accumulator

Move the byte from source to Reg. B

Add contents of Reg. B with accumulator

Decrement counter C

No
Is C contents
= 0?

YES
Increment contents of HL pair

Add the memory contents

Store the byte from accumulator to destination

Stop
Algorithm :

Step 1: Initialize H-L pair to source memory location.


Step 2: Initialize reg. C to 09H.
Step 3: Move the byte from source to accumulator.
Step 4: Move the byte from source to reg. B.
Step 5: Add reg. B contents with accumulator.
Step 6: Decrement counter C.
Step 7: Jump to Step 5 if counter is not zero.
Step 8: Increment the source pointer H-L pair.
Step 9: Add memory contents with accumulator.
Step 10: Store the byte from accumulator to destination.
Step 11: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 LXI H, 2100H 21 ; Initialize H-L pair to source memory location.
2001 00 ; Lower-order of 2100H.
2002 21 ; Higher-order of 2100H.
2003 MVI C,09H 0E ; Initialize reg. C to 09h, i.e. number of bytes.
2004 09 ; Immediate value 09h.
2005 MOV A,M 7E ; Move the byte from source to accumulator.
2006 MOV B,M 46 ; Move the byte from source to reg. B.
2007 LOOP: ADD B 80 ; Add reg. B contents with accumulator.
2008 DCR C 0D ; Decrement counter C.
2009 JNZ LOOP C2 ; Jump to address 2007H if counter is not zero.
200A 07
200B 20
200C INX H 23 ; Increment the source pointer H-L pair.
200D ADD M 86 ; Add memory contents with accumulator.
200E STA 2200H 32 ; Store the byte from accumulator to destination.
200F 00 ; Lower-order of 2200H.
2010 22 ; Higher-order of 2200H.
2011 HLT 76 ; Halt

Result :

Input Output
2100 02 2200 1D
2101 09
Practical No. 18
Aim : Write a program to convert binary number into its BCD equivalent.

Flow Chart:

Start

Initialize reg. D with 00H

Load HL pair with given hex number

Move the byte from source to reg. C

Add data 01H with accumulator contents

Set decimal adjust accumulator

NO Is carry = 0?

YES

Increment reg. D contents

Decrement reg. C contents

Is C contents = 0? NO

YES
Store the byte from accumulator to destination

Stop
Algorithm :

Step 1: Initialize reg. D to 00H.


Step 2: Initialize H-L pair to source memory location.
Step 3: Move the byte from source to reg. C.
Step 4: Add data 01H with accumulator contents.
Step 5: Set decimal adjust accumulator.
Step 6: Jump to Step 8 if carry is not zero.
Step 7: Increment counter D.
Step 8: Decrement reg. C contents.
Step 9: Jump to Step 4 if reg. C contents is not zero.
Step10: Store the byte from accumulator to destination
Step 11: Halt

Program:

Address Label Mnemonics Opcode Comment


2000 MVI D, 00H 16 ; Initialize reg. C to 00H
2001 00 ; Immediate value 00H.
2002 LXI H, 2100H 21 ; Initialize H-L pair to source memory location.
2003 00 ; Lower-order of 2100H.
2004 21 ; Higher-order of 2100H.
2005 MOV C,M 4E ; Move the byte from source to reg. C.
2006 LOOP2: ADI 01H C6 ; Add data 01H with accumulator contents.
2007 01
2008 DAA 27 ; Set decimal adjust accumulator.
2009 JNC LOOP1 D2 ; Jump to address 200DH if carry is not zero.
200A 0D
200B 20
200C INR D 14 ; Increment reg. D contents.
200D LOOP1: DCR C 0D ; Decrement reg. C contents.
200E JNZ LOOP2 C2 ; Jump to address 2006 if reg.C contents is not zero.
200F 06
2010 20
2011 STA 2200H 32 ; Store the byte from accumulator to destination.
2012 00 ; Lower-order of 2200H.
2013 22 ; Higher-order of 2200H.
2014 HLT 76 ; Halt

Result :

Input Output
2100 1D 3100 29
Practical No. 19
Aim : A program is stored at given memory location copy the contents of this
memory locations on paper and disassemble the program using opcode sheet. Draw the
flowchart and write the working of given program in 8085.

Address Opcode
2000 16
2001 08
2002 06
2003 00
2004 0E
2005 01
2006 21
2007 00
2008 30
2009 46
200A 23
200B 71
200C 78
200D 81
200E 41
200F 4F
2010 23
2011 77
2012 15
2013 C2
2014 0C
2015 20
2016 76

Program:

Address Label Mnemonics Opcode Comment


2000 MVI D,08H 16 ; Initialize reg. D to 08h.
2001 08 ; Immediate value 08h.
2002 MVI B,00H 06 ; Initialize reg. B to 00h.
2003 00 ; Immediate value 00.
2004 MVI C,01H 0E ; Initialize reg. C to 01h.
2005 01 ; Immediate value 01h.
2006 LXI H,3000 21 ; Initialize H-L pair to source memory location.
2007 00 ; Lower-order of 3000H.
2008 30 ; Higher-order of 3000H.
2009 MOV B,M 46 ; Move the byte from memory to reg. B.
200A INX H 23 ; Increment the source pointer H-L pair.
200B MOV M,C 71 ; Move the byte from reg. C to memory.
200C LOOP: MOV A,B 78 ; Move the byte from reg. B to accumulator.
200D ADD C 81 ; Add reg. C contents with accumulator.
200E MOV B,C 41 ; Move the byte from reg. C to reg. B.
200F MOV C,A 4F ; Move the byte from accumulator to reg. C.
2010 INX H 23 ; Increment the source pointer H-L pair.
2011 MOV M,A 77 ; Move the byte from accumulator to memory.
2012 DCR D 15 ; Decrement counter D.
2013 JNZ LOOP C2 ; Jump to address 200CH if counter is not zero.
2014 0C
2015 20
2016 HLT 76 ; Halt

Flow Chart:

Start

Initialize reg. D to 08h as counter

Initialize reg. B to 00h

Initialize reg. C to 01h

Initialize H-L pair to source memory location 3000h

Move the byte from memory to reg. B

Increment the source pointer H-L pair

Move the byte from reg. C to memory

Copy contents of Reg B in Reg A

Add reg. C contents with accumulator

Move the byte from reg. C to reg. B

B
A
B
A

Move the byte from accumulator to reg. C

Increment the source pointer H-L pair

Move the byte from reg. A to memory

Decrement the of counter D

NO
Is Counter = 0?

YES
Stop

Algorithm:

Step 1: Initialize counter i.e. reg. D to 08H.


Step 2: Initialize reg. B to 00h to store previous number.
Step 3: Initialize reg. C to 01h to store current number.
Step 4: Initialize H-L pair to source memory location 3000h.
Step 5: Move the byte from memory to reg. B.
Step 6: Increment the source pointer H-L pair.
Step 7: Move the byte from reg. C to memory.
Step 8: Move the byte from reg. B to accumulator.
Step 9: Add reg. C contents with accumulator.
Step 10: Move the byte from reg. C to reg. B.
Step 11: Move the byte from accumulator to reg. C.
Step 12: Increment the source pointer H-L pair.
Step 13: Move the byte from accumulator to memory.
Step 14: Decrement the contents of counter reg. D.
Step 15: Jump to Step 8 if counter is not zero.
Step 16: Halt
Result :

Output
3001 01
3002 01
3003 02
3004 03
3005 05
3006 08
3007 0D
3008 15
3009 22
Practical No. 20
Aim : Write a program to multiply two 1 byte numbers by rotation.

Flow Chart:
Start

Initialize reg. B with 05H

Initialize reg. C with 04H

Move the byte from reg. B to reg. C

Rotate accumulator contents without carry to left

Store the byte from accumulator to destination

Stop

Algorithm :

Step 1: Initialize reg. B to 05H.


Step 2: Initialize reg. C to 04H.
Step 3: Move the byte from reg. B to accumulator.
Step 4: Rotate accumulator contents without carry to left.
Step 5: Store the byte from accumulator to destination.
Step 6: Stop.
Program:

Address Label Mnemonics Opcode Comment


2000 MVI B,05H 06 ; Initialize reg. B to 05h.
2001 05 ; Immediate value 05h.
2002 MVI C,04H 0E ; Initialize reg. C to 04h.
2003 04 ; Immediate value 04h.
2004 MOV A,B 78 ; Move the byte from reg. B to accumulator.
2005 RLC 07 ; Rotate accumulator contents without carry to left.
2006 RLC 07 ; Rotate accumulator contents without carry to left.
2007 STA 3050H 32 ; Store the byte from accumulator to destination.
2008 50
2009 30
200A HLT 23 ; Halt

Result :

Output
3050 14

You might also like