0% found this document useful (0 votes)
81 views9 pages

Write An 8085 ALP To Sort A Given Block of N Bytes Starting From 9000 H in Ascending Order With N Being User Input. Algorithm

1. The algorithm loads a number n from memory into register B, and initializes register D to 1 to start the multiplication process. 2. It then calls a subroutine to compute the factorial of n by repeatedly adding the contents of register D to the accumulator, decrementing register E each time. 3. After computing the factorial, it stores the result back in memory and returns control to the main program. The main program then decrements B and repeats the process until all numbers from 0 to 5 have been computed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views9 pages

Write An 8085 ALP To Sort A Given Block of N Bytes Starting From 9000 H in Ascending Order With N Being User Input. Algorithm

1. The algorithm loads a number n from memory into register B, and initializes register D to 1 to start the multiplication process. 2. It then calls a subroutine to compute the factorial of n by repeatedly adding the contents of register D to the accumulator, decrementing register E each time. 3. After computing the factorial, it stores the result back in memory and returns control to the main program. The main program then decrements B and repeats the process until all numbers from 0 to 5 have been computed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

LAB – 2

Powrohitham Sanjay Datta


SC20B107

write an 8085 ALP to sort a given block of n bytes starting from 9000 H in ascending
order with n being user input.
Algorithm:
1. Load size of list in C register and set D register to be 0
2. Decrement C as for n elements n-1 comparisons occur
3. Load the starting element of the list in Accumulator
4. Compare Accumulator and next element
5. If accumulator is less than or equal to the next element jump to step 8
6. Swap the two elements
7. Set D register to 1
8. Decrement C
9. If C>0 take next element in Accumulator and go to point 4
10. If D=0, this means in the iteration, no exchange takes place consequently we
know that it won’t take place in further iterations so the loop in exited and
program is stopped
11. Jump to step 1 for further iterations
Address Opcode Mnemonics Operands comments

8000 21 LXI H,8FFF


8001 FF Load size of array

8002 8F
8003 16 MVI D, 00H
clear D register to set up a flag
8004 00
8005 4E MOV C, M set C register with number of elements in list
8006 0D DCR C Decrement C
8007 23 INX H Increment memory to access list of numbers
8008 7E MOV A, M Retrieve list element in Accumulator
8009 23 INX H Increment memory to access next element
800A B9 CMP M compare Accumulator with next element
800B DA JC 8018
800C 18 If accumulator is less then jump to 8018
800D 80
800E CA JZ 8018
800F 18 If accumulator is equal then jump to 8018
8010 80
8011 46 MOV B, M
8012 77 MOV M, A swap the two elements
8013 2B DCX H
8014 70 MOV M, B
8015 23 INX H
8016 16 MVI D, 01H If exchange occurs save 01 in D register
8017 01
8018 0D DCR C decrement C for next iteration
8019 C2 JNZ 8008
801A 08 Jump to 8008 if C>0
801B 80
801C 7A MOV A, D Transfer contents of D to Accumulator
801D FE CPI 01H
compare accumulator contents with 01H
801E 01
801F CA JZ 8000
8020 00 Jump to 8000 if D=01H
8021 80
8022 DF RST 3 Return control to the monitor
observations
input data output
memory location data memory location data

8FFF 06H

9000 06H 9000 00H

9001 05H 9001 01H

9002 04H 9002 02H

9003 03H 9003 03H

9004 02H 9004 04H

9005 01H 9005 05H

9006 00H 9006 06H


write an 8085 ALP to sort a given block of n bytes starting from 8500H in descending order
with n being user input

Algorithm:
1. Load size of list in C register and set D register to be 0
2. Decrement C as for n elements n-1 comparisons occur
3. Load the starting element of the list in Accumulator
4. Compare Accumulator and next element
5. If accumulator is greater than or equal to the next element jump to step 8
6. Swap the two elements
7. Set D register to 1
8. Decrement C
9. If C>0 take next element in Accumulator and go to point 4
10. If D=0, this means in the iteration, no exchange takes place consequently we
know that it won’t take place in further iterations so the loop in exited and
program is stopped
11. Jump to step 1 for further iterations
Address Opcode Mnemonics Operands comments

8000 21 LXI H,8FFF


8001 FF Load size of array

8002 8F
8003 16 MVI D, 00H
clear D register to set up a flag
8004 00
8005 4E MOV C, M set C register with number of elements in list
8006 0D DCR C Decrement C
8007 23 INX H Increment memory to access list of numbers
8008 7E MOV A, M Retrieve list element in Accumulator
8009 23 INX H Increment memory to access next element
800A B9 CMP M compare Accumulator with next element
800B D2 JNC 8018
800C 18 If accumulator is greater then jump to 8018
800D 80
800E CA JZ 8018
800F 18 If accumulator is equal then jump to 8018
8010 80
8011 46 MOV B, M
8012 77 MOV M, A swap the two elements
8013 2B DCX H
8014 70 MOV M, B
8015 23 INX H
8016 16 MVI D, 01H If exchange occurs save 01 in D register
8017 01
8018 0D DCR C decrement C for next iteration
8019 C2 JNZ 8008
801A 08 Jump to 8008 if C>0
801B 80
801C 7A MOV A, D Transfer contents of D to Accumulator
801D FE CPI 01H
compare accumulator contents with 01H
801E 01
801F CA JZ 8000
8020 00 Jump to 8000 if D=01H
8021 80
8022 DF RST 3 Return control to the monitor
observations
input data output
memory location data memory location data

8FFF 06H

9000 00H 9000 06H

9001 01H 9001 05H

9002 02H 9002 04H

9003 03H 9003 03H

9004 04H 9004 02H

9005 05H 9005 01H

9006 06H 9006 00H


write an 8085 ALP to compute the factorial of a number n (0 ≤ n ≤ 5)

Algorithm:

1. Load the data into register B

2. To start multiplication set D to 01H

3. Jump to step 7

4. Decrements B to multiply previous number

5. Jump to step 3 till value of B>0

6. Take memory pointer to next location and store result

7. Load E with contents of B and clear accumulator

8. Repeatedly add contents of D to accumulator E times

9. Store accumulator content to D

10. Go to step 4
Address Opcode Mnemonics Operands comments

8000 21 LXI H,8500


8001 00 Load data from memory

8002 85
8003 46 MOV B,M Load data to B register
8004 16 MVI D, 01H
Set D register with 1
8005 01
8006 CD CALL MULTIPLY
Subroutine call for multiplication
8007 00
8008 90
8009 05 DCR B Decrement B
800A C2 JNZ 8006
800B 06 Call 8006 till B becomes 0
800C 80
800D 23 INX H Increment memory
800E 72 MOV M, D Store result in memory
800F DF RST 3 Return control to the monitor

subroutine
9000 58 MOV E,B Load B to E
9001 AF XRA A Clear accumulator to store result

9002 82 ADD D Add D to A

9003 1D DCR E Decrement E

9004 C2 JNZ 9002 If E is not 0, jump to ML

9005 02
9006 90
9007 57 MOV D,A Transfer contents of A to D

9008 C9 RET Return result

observations
input data output
memory location data memory location data

8500 03H 8501 06H

You might also like