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
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
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
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
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
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
Algorithm:
3. Jump to step 7
10. Go to step 4
Address Opcode Mnemonics Operands comments
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
9005 02
9006 90
9007 57 MOV D,A Transfer contents of A to D
observations
input data output
memory location data memory location data