Wednesday, May 4, 2016

Sorting of Array


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.


;<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
view raw ascending.asm hosted with ❤ by GitHub
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.


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.


;<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
view raw descending.asm hosted with ❤ by GitHub

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