arrays - assembly program to sort in special way? help please? -
8086 assembly language program sorts array follows: smallest value in array should placed in first cell. second smallest value in last cell. third smallest value in second cell of array. fourth smallest value placed in before-last cell of array. • above procedure continues until array sorted. note in above-described sorting technique, large values in initial array end being placed @ middle part of array
here code sorting in normal way :
org 100h .model small .data table db 9,2,6,8,5,1 b db 6 dup(0) val1 db 5 nl db ' ','$' .code mov ax,@data mov ds,ax lea bx,table mov dl,val1 lbl1: lea bx,table mov cl,5 lbl2: mov al,[bx] mov dl,[bx+1] cmp al,dl jb lbl3 mov [bx],dl mov [bx+1],al lbl3: inc bx loop lbl2 mov dl,val1 dec dl mov val1,dl cmp dl,00 jne lbl1 mov cl,6 lea bx,table display: lea dx,nl mov ah,09h int 21h mov dl,[bx] add dl,30h mov ah,02h int 21h inc bx inc bx loop display mov ah,4ch int 21h ret
replace:
mov cl, val1
by:
mov cl, [val1]
this way moves content of val1 (the number 5) cl. in code above, move offset of val1 cl (the same lea cl, val1).
Hello Admin,
ReplyDeleteIt is conceivable to pass contentions to capacities by reference. This implies a reference to the variable is controlled by the capacity as opposed to a duplicate of the variable's worth.
Regards,
Thanks
RITU