flat assembler
Message board for the users of flat assembler.
Index
> Main > Question about qsort |
Author |
|
Ton 20 Mar 2005, 19:47
If I take the qsort from http://board.flatassembler.net/topic.php?t=3048
format elf executable entry main main: push [lo] [hi] call quicksort mov eax, 1 mov ebx, 0 int 80h quicksort: mov eax,[lo] mov edx,[hi] etc I compile with fasm 1.60 (with FC2), but if I run the program I get a Segmentation fault. As far as I can oversee the code is correct. What do I oversee ? --- Best Regards, Ton |
|||
20 Mar 2005, 19:47 |
|
Ton 21 Mar 2005, 07:46
I too think it is a stack problem
I tried with a small data set. Here you can also see how lo and hi are set. align 4 a dd 3,6,1,8,2,5 lo dd 0 hi dd 5*4 I followed the sorting with ald, and indeed the data set is sorted. The problem occurs when the 'parent' qsort exits. I counted the pushes and pops and see no problem. Despite I also tried: main: mov edp, esp sub esp,20 ; whatever push [lo] [hi] call quicksort mov esp,edp all to no avail. -- Best Regards, Ton |
|||
21 Mar 2005, 07:46 |
|
revolution 25 Mar 2005, 01:10
Quote:
Paste the whole thing, I can't help if you only post small parts the don't show all definitions and code! |
|||
25 Mar 2005, 01:10 |
|
Ton 25 Mar 2005, 19:49
Fair enough. Here it is:
format elf executable entry main main: push [lo] [hi] call quicksort mov eax, 1 mov ebx, 0 int 80h quicksort: mov eax,[lo] mov edx,[hi] lea ecx,[eax+edx] shr ecx,3 shl ecx,2 mov ecx,[a+ecx] .qc1: cmp [a+eax],ecx jnc .qc2 add eax,4 jmp .qc1 .qc2: cmp ecx,[a+edx] jnc .qc3 sub edx,4 jmp .qc2 .qc3: cmp edx,eax jc .qc4 push [a+eax] [a+edx] pop [a+eax] [a+edx] add eax,4 sub edx,4 cmp edx,eax jnc .qc1 .qc4: cmp [esp+8],edx jnc .qc5 push dword [esp+8] push edx call quicksort pop edx pop dword [esp+12] .qc5: cmp eax,[esp+4] jnc .qc6 push eax push dword [esp+8] call quicksort pop dword [esp+12] pop eax .qc6: ret align 4 a dd 3,6,1,8,2,5 lo dd 0 hi dd 5*4 |
|||
25 Mar 2005, 19:49 |
|
revolution 28 Mar 2005, 01:23
There is a problem here
Code: mov eax,[lo] mov edx,[hi] change to: Code: mov eax,[esp+8] mov edx,[esp+4] |
|||
28 Mar 2005, 01:23 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.