Код:
masm
model small
.data
message1 db 10,13, 'Primary array : $',10,13
message2 db 10,13, 'Sorted array : $',10,13
promt db 10,13,10,13,'Press any key to exit...$'
len equ 9
mas dw 2,7,4,0,1,9,3,6,5,8
tmp dw 0
i dw 0
j dw 0
.stack
.code
main:
mov ax,@data
mov ds,ax
mov ah,9
mov dx,offset message1
int 21h
mov cx,10
mov si,0
_outputArray:
mov ah,2
mov dx,mas[si]
add dl,30h
int 21h
add si,2
loop _outputArray
; for (i=0;i<9;i++)
; for (j=9;j>i;j--)
; if (mas[i]>mas[j])
; {tmp=mas[i];
; mas[i]=mas[j];
; mas[j]=tmp;}
sort:
mov j,9
jmp cyclj
xchng:
mov bx,i
shl bx,1
mov ax,mas[bx]
mov bx,j
shl bx,1
cmp ax,mas[bx]
jle lesser
mov tmp,ax
mov ax,mas[bx]
mov bx,i
shl bx,1
mov mas[bx],ax
mov bx,j
shl bx,1
mov ax,tmp
mov mas[bx],ax
lesser:
dec j
cyclj:
mov ax,j
cmp ax,i
jg xchng
inc i
cmp i,len
jl sort
mov ah,9
mov dx, offset message2
int 21h
mov cx,10
mov si,0
_outputSortedArray:
mov dx,mas[si]
add dl,30h
mov ah,2
int 21h
add si,2
loop _outputSortedArray
mov ah,9
mov dx,offset promt
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
end main
Не подскажет кто-нибудь как учитывать еще и знак числа? Сортирует только положительные числа...