I have managed to get data across the main function
and I have initialized the array index to zero as well and read all the theories on how things are supposed to go but i'm having hard time translating my idea into actual assembly code. How do I extract an element and match it with all the elements up to the sort_listed at that point? can someone help me finish this code please?
; INSERTION SORT
[org 0x0100]
jmp start
data: 2, 3, -4
sorted_index: db 0
insert_sort: dec cx ; last element not compared
shl cx, 1 ; turn into byte count
mainloop: mov si, 0 ; initialize array index to zero
mov byte [sorted_index], 0 ; make all element sorted until 0th
innerloop: mov ax, [bx+si] ; load 1st number in ax
cmp ax, [bx+si+2] ; compare with next number
jge nosort ; no sort if already sorted
?????????? ;how do i sort here?
nosort: add si, 2 ; advance si to next index
cmp si, cx ; are we at last index
jne innerloop ; if not compare next two
cmp byte [swap], cx ; sorted_index is same as cx?
je mainloop ; if yes make another pass
ret ; go back to where we came from
start: mov bx, data ; send start of array in bx
mov cx, 3 ; send count of elements in cx
call insert_sort ; call our subroutine
mov ax, 0x4c00 ; terminate program
int 0x21
Comments
Post a Comment