This is just "your code" with a "print_array" routine. It seems to be "working" as is. I think it can be improved.
BTW, just "code" in square brackets at the beeginning of your code, and "/code" in square brackets at the end.
; from "turtle13" on the forum
; nasm -f elf32 myprog.asm
; ld -o myprog myprog.o -m elf_i386
bits 32
section .text ;section declaration
global _start
_start:
call print_array
mov edx, 9
jmp outerloop
outerloop:
mov ecx, 0 ; instead of 0, value should be the number of times outerloop has traversed
jmp innerloop
innerloop:
mov eax, [array + ecx * 4]
mov ebx, [array + 4 + ecx * 4]
cmp eax, ebx
jge next
mov [array + ecx * 4], ebx
mov [array + 4 + ecx * 4], eax
next:
; call print_array
inc ecx
cmp ecx, edx
jl innerloop
je endinner
endinner:
dec edx
jnz outerloop
done:
call print_array
mov ebx,0 ;first syscall argument: exit code
mov eax,1 ;system call number (sys_exit)
int 0x80 ;"trap" to kernel
print_array:
push eax
push ecx
xor ecx, ecx
.top:
mov eax, [array + ecx * 4]
call showeaxd
mov al, ' '
call putc
inc ecx
cmp ecx, 9
jle .top
mov al, 10
call putc
pop ecx
pop eax
ret
;---------------------------------
; showeaxd - print a decimal representation of eax to stdout
; for "debug purposes only"... mostly
; expects: number in eax
; returns; nothing useful
showeaxd:
push eax
push ebx
push ecx
push edx
push esi
sub esp, 10h
lea ecx, [esp + 12]
mov ebx, 10
xor esi, esi
mov byte [ecx], 0
.top:
dec ecx
xor edx, edx
div ebx
add dl, '0'
mov [ecx], dl
inc esi
or eax, eax
jnz .top
mov edx, esi
mov ebx, 1
mov eax, 4
int 80h
add esp, 10h
pop esi
pop edx
pop ecx
pop ebx
pop eax
ret
;---------------------------------
;---------------------------------
putc:
push edx
push ecx
push ebx
push eax
mov eax, 4 ; sys_write
mov ebx, 1 ; stdout
mov ecx, esp ; buffer is on stack
mov edx, 1 ; just one character
int 80h
pop eax
pop ebx
pop ecx
pop edx
ret
;------------------------
section .data ;section declaration
; This variable must remain named exactly 'array'
array dd 3, 9, 1, 6, 2, 4, 0, 5, 7, 8
Best,
Frank