Here is a code to sort the given array in assembly language
.model small
.stack 100h
.data ;roll number 2435
data1 db 66h, 2, 045h, 4, 040h, 3, -025h, 5, -010h, 011h
swap db 0
.code
mov ax, @data
mov ds, ax
start:
mov swap, 0
mov bx, 0
loop1:
mov al, [bx+data1]
mov cl, [bx+data1+1]
cmp al, [bx+data1+1] ;here is the problem when compare 66h with -025h
jbe noswap
mov dl, [bx+data1+1]
mov [bx+data1+1],al
mov [bx+data1], dl
mov swap, 1
noswap:
add bx,1
cmp bx,9
jne loop1
cmp swap,1
je start
mov ah, 04ch
int 21h
it compares all elements of array to sort in ascending order, but when it compares 66h with -025h, it implies that 66h is smaller and -025h is bigger and does not swap, mov to no swap lable
i have debugged it and found that at backend -025h is being stored as DB. How can I properly sort the array with negative number