CS401 Assignment Number 1 Idea Solution 2019
Cs401 assignment No 1
[org 0x100]
jmp start
data: dw 8,2,0,0,-1,-1,-7,-7,-9
swap: db 0
start: mov bx,0 ; initialize array index to zero
mov byte [swap],0 ; rest swap flag to no swaps
loop1: mov ax, [data+bx] ; load number in ax
cmp ax, [data+bx+2] ; compare with next number
jae noswap ;no swap if already in order
mov dx,[data+bx+2] ; load second element in dx
mov [data+bx+2], ax ;store first number in second
mov [data+bx], dx ; store second number in first
mov byte [swap], 1 ;flag that a swap has been done
noswap: add bx,2 ; advance bx to next index
cmp bx, 11 ; are we at last index
jne loop1 ; if not compare next two
cmp byte [swap], 1 ;check if a swap has been done
je start ; if yes make another pass
mov ax, 0x4c00 ;terminate program
int 0x21