Asm 2
Asm 2
jmp start
len equ 10
sorted_flag db ?
start_tick_low dw 0
start_tick_high dw 0
end_tick_low dw 0
end_tick_high dw 0
start:
xor ax, ax
mov ax, cs
mov ds, ax
mov es, ax
mov [start_tick_high], cx
outer_loop:
mov [sorted_flag], 1
mov dx, cx
inner_loop:
cmp al, bl
jae no_swap
mov [si], bl
mov [si+1], al
mov [sorted_flag], 0
no_swap:
inc si
dec dx
jnz inner_loop
cmp [sorted_flag], 1
je sorted_done
dec cx
jnz outer_loop
sorted_done:
print_loop:
xor ah, ah
push cx
call print_number_16
pop cx
cmp cx, 1
jne print_space
int 21h
jmp done_print
print_space:
int 21h
done_print:
inc si
dec cx
jnz print_loop
mov es, ax
mov [end_tick_low], bx
mov [end_tick_high], cx
mov bx, ax
mov ax, bx
call print_number_16
int 21h
; K?t thúc
int 21h
print_number_16:
push ax
push bx
push cx
push dx
cmp ax, 0
jne .convert
int 21h
jmp .done
.convert:
xor cx, cx
mov bx, 10
.repeat:
xor dx, dx
div bx
push dx
inc cx
cmp ax, 0
jne .repeat
.print:
pop dx
int 21h
loop .print
.done:
pop dx
pop cx
pop bx
pop ax
ret