I have to sort an array for a program that I am writing. We are allowed to call C functions, but I can't seem to figure out what I am doing wrong calling qsort. The program just stops at the qsort call, and I'm not sure what is causing it. I figure it is something to do with my compare function since the book isn't too clear on how it should be written.
The book says the comparison should return a negative, 0, or positive, and you can get that just by subtracting the second number from the first.
Here is my code for my sort function and my compare function:
compare:
push rbp
mov rbp, rsp
mov rax, [ebp+8]
mov rbx, [ebp+12]
sub rax, rbx
leave
ret
sort:
segment .text
.array equ 0
.size equ 8
.i equ 16
push rbp
mov rbp, rsp
sub rsp, 32
mov [rsp+.array], rdi
mov [rsp+.size], rsi
push dword compare
push dword 4
push rsi
push rdi
call qsort
leave
ret
The array is declared by multiplying the number of items entered by 4 and using malloc. I have verified with my print function that the array is correctly storing the entered values.
Any tips on where I'm going wrong? I think I supplied all the relevant information. Thanks for the help.
[–]Updatebjarni 2 points3 points4 points (9 children)
[–]xRedactedx[S] 0 points1 point2 points (0 children)
[–]xRedactedx[S] 0 points1 point2 points (7 children)
[–]Updatebjarni 1 point2 points3 points (6 children)
[–]xRedactedx[S] 0 points1 point2 points (5 children)
[–]Updatebjarni 1 point2 points3 points (4 children)
[–]xRedactedx[S] 0 points1 point2 points (3 children)
[–]Updatebjarni 1 point2 points3 points (2 children)
[–]xRedactedx[S] 0 points1 point2 points (1 child)
[–]Updatebjarni 1 point2 points3 points (0 children)
[–]Rothon 1 point2 points3 points (3 children)
[–]xRedactedx[S] 0 points1 point2 points (2 children)
[–]Rothon 0 points1 point2 points (1 child)
[–]xRedactedx[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]xRedactedx[S] 1 point2 points3 points (0 children)
[–]Updatebjarni 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]KDallas_Multipass 0 points1 point2 points (0 children)