section .data
fmt_in db "%d",0
fmt_out db "%d ",0
newline db 10,0
section .bss
n resd 1
num resd 10001
section .text
global main
extern scanf
extern printf
main:
push ebp
mov ebp,esp
;----------------------------
push n
push fmt_in
call scanf
add esp,8
;----------------------------
xor esi,esi
read:
cmp esi,[n]
jge read_done
lea eax,[num+esi*4]
push eax
push fmt_in
call scanf
add esp,8
inc esi
jmp read
read_done:
mov ecx,[n]
dec ecx
outer:
cmp ecx, 0
jle sort_done
xor esi,esi
replacement:
cmp esi,ecx
jge next
mov eax,[num+esi*4]
cmp eax,[num+esi*4+4]
;----------------------------------
jle skip
;----------------------------------
mov eax, [num+esi*4]
mov ebx, [num+esi*4+4]
mov [num+esi*4+4], eax
mov [num+esi*4], ebx
skip:
inc esi
jmp replacement
next:
dec ecx
jmp outer
sort_done:
xor esi,esi
print:
cmp esi,[n]
jge print_done
push dword [num+esi*4]
push fmt_out
call printf
add esp,8
inc esi
jmp print
print_done:
push newline
call printf
add esp,4
;--------------------------
xor eax,eax
mov esp, ebp
pop ebp
ret