- Suppose, there is an array of ten 8-bit data stored in memory addresses from 2030h to 2039h.
- Starting from 2030h, we compare the data of the first location with that of the second location.
- If the data of the first location is greater than that of the second location, they are swapped.
- Running external loop for 9 times, 8 times, 7 times and so on, we run every internal loop as 9 times, 8 times, 7 times and so on for every corresponding external loop. For e.g. for external loop 9, we run respective internal loop 9 times.
- Doing so, after every external loop, the largest number will be at the last memory location.
MVI C, 09h
AGAIN: MOV D, C
LXI H, 2030h
NEXT: MOV A, M
INX H
CMP M
JC SKIP
MOV B, M
MOV M, A
DCX H
MOV M, B
INX H
SKIP: DCR D
JNZ NEXT
DCR C
JNZ AGAIN
HLT
No comments:
Post a Comment