1. Program for arranging a given array in ascending order. The length of array is stored at memory location 5000H and the array starts from 5001H.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;<Program for arranging a given array in ascending order.The length of array | |
;is stored at memory location 5000H and the array starts from 5001H> | |
jmp start | |
;code | |
start: lxi h, 5000H | |
mov b,m | |
dcr b | |
loop1: mov c,b | |
lxi h, 5001H | |
loop2: mov a,m | |
inx h | |
cmp m | |
jc skip | |
mov d,m | |
mov m,a | |
dcx h | |
mov m,d | |
inx h | |
skip: dcr c | |
jnz loop2 | |
dcr b | |
jnz loop1 | |
hlt |
Screenshot of the array content after arranging. See the content of memory locations from 5001H.
2. Program for arranging a given array in descending order. The length of array is stored at memory location 5000H and the array starts from 5001H.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;<Program for arranging a given array in descending order.The length of array | |
;is stored at memory location 5000H and the array starts from 5001H> | |
jmp start | |
;code | |
start: lxi h, 5000H | |
mov b,m | |
dcr b | |
loop1: mov c,b | |
lxi h, 5001H | |
loop2: mov a,m | |
inx h | |
cmp m | |
jnc skip | |
mov d,m | |
mov m,a | |
dcx h | |
mov m,d | |
inx h | |
skip: dcr c | |
jnz loop2 | |
dcr b | |
jnz loop1 | |
hlt |
Screenshot of the array content before arranging. See the content of memory locations from 5000H.
Screenshot of the array content after arranging. See the content of memory locations from 5001H.
No comments:
Post a Comment