"Your program doesn't work because something you believe to be true is not true." That's a "general rule" I picked up from a web page about debugging Linux programs, but it applies in Windows, too. Now, you just have to figure out what that is!
I couldn't spot anything, at first, so I assembled/compiled it for Linux. Worse than "no output", it segfaulted! Took me a while to figure out why - this is a little subtle... "scasd", of course, adds 4 to edi. No problem through the first loop, but after falling through and going back to do the next item in the array, edi doesn't get reset and just keeps going and going like the Energizer Bunny!
First, I should observe that your array, the way you initialize it in the .c program, is sorted anyway - just a "nop" would work. To prove to myself that this was actually doing something, I modified your .c program to initialize the array from 999 down to 0, instead of 0 to 999. (a[ i ] = 999 - i) Random probably would have been even better. This isn't a "bug" or a "problem", I just did it to "prove to myself"...
After fixing the "runaway scasd", I was getting a "scrambled" array! This is perhaps even subtler! Where you exchange [esi] and [edi]... both registers have been incremented by 4 by the "lodsd" and "scasd", so you're swapping the "next two" integers, instead of the two you just compared! Took me a second cup of coffee to figure that one out! Changing to [esi - 4] and [edi - 4] in that section fixed it...
You do:
mov esi,[ebp+8]
mov edi,[ebp+8]
sub esi,4
I don't like that. The first "lodsd" is getting the dword before the start of your array - not what you really want. I like "add edi, 4" better, but I realized (after the second cup of coffee) that esi, after the "lodsd", is where we want edi to start for the first "scasd", so I did:
%include "asm_io.inc"
segment .text
;global _sort
;_sort:
global sort ; Linux doesn't use the underscore - change back, for Windows
sort:
enter 0,0 ;
push ebx
push esi
push edi
mov ecx,1000
mov ebx,0
cld
mov esi,[ebp+8]
pomjerajprvi:
lodsd
inc ebx
cmp ebx,1000
je dalje
sub ecx,ebx
mov edi, esi ; <-
prviiostali:
scasd
jle nijeispunjeno ; "jl" swaps if they're equal - pointless!
mov edx,[edi - 4] ; <-
xchg edx,[esi - 4] ; <-
mov [edi - 4],edx ; <-
nijeispunjeno:
...
With those changes, it "works for me".
Not a very optimal sort routine. Could perhaps be improved by passing the size of the array as a second parameter, instead of hard-coding 1000. Might be better to do "sort array" and "print array" as two separate routines instead of the combined "sort and print". But with those minor changes, it "works". Good job!
Best,
Frank