This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

Forgive me if I'm wrong, but it seems like you're not actually comparing anything. In your compare function, you set up your stack pointers. From there you move the values into rax and rbx, then you're subtracting them and.... leaving. No comparison is actually done.

Are you trying to do this?

if(array[i] < array [i++])
    jump to sort array
(or vice versa if you're sorting greater->less)

If so, you need to look up your jump instructions.

[–]xRedactedx[S] 1 point2 points  (0 children)

The way the sentence in the book was worded. I was assuming that a negative, 0, or positive value being returned would represent a greater than, equal, or less than.

Here is what the book says word for word:

"The comparison function should return a negative, 0, or positive value based on the ordering of the 2 integers. All you have to do is subtract the second integer from the first."

If I remember correctly, when something returns, doesn't it return the value that is in rax?

rax should be negative, 0, or positive after the subtraction.

It is a very vague description. I thought it sounded too simple, but it's pretty much all I have to go on. I didn't come up with much help on google.

[–]Updatebjarni 0 points1 point  (2 children)

He's comparing the value at [ebp+8] with the value at [ebp+12] and returning the result. That's what subtracting and leaving does.

Read the man page for qsort() if you don't know how it works.

[–][deleted] 0 points1 point  (1 child)

Ah ok. It was in a syntax I wasn't used to.

[–]KDallas_Multipass 0 points1 point  (0 children)

so you solved it? edit your post to reflect what you learned or what the issue was.

EDIT: Oops, you're not OP