section .data
fmt_in db "%d",0
fmt_out db "%d ",0
newline db 10,0
section .bss
n resd 1
arr resd 10001
section .text
global main
extern scanf,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,[arr+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 label
xor esi,esi
inner:
cmp esi,ecx
jge inner_done
mov eax,[arr+esi*4]
cmp eax,[arr+esi*4+4]
jle no_swap
mov eax, [arr+esi*4]
mov ebx, [arr+esi*4+4]
mov [arr+esi*4+4], eax
mov [arr+esi*4], ebx
no_swap:
inc esi
jmp inner
inner_done:
dec ecx
jmp outer
sort_done:
xor esi,esi
print:
cmp esi,[n]
jge print_done
push dword [arr+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