The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: sonic on November 04, 2007, 03:56:24 AM

Title: Listview Sort Problem
Post by: sonic on November 04, 2007, 03:56:24 AM
I coded this after having some reading but it seems i have not understood it well. It crashes on clicking the column header. I m trying to sort floats and string. The string also seems to be sorted incorrectly?
Title: Re: Listview Sort Problem
Post by: zooba on November 04, 2007, 06:31:41 AM
You're not popping the floats off the stack after comparing them. This causes the string-to-float conversion to fail sometimes due to a stack overflow. It appears that this isn't causing the crash, but it will cause invalid sorting.

I couldn't see a reason for the strings to sort incorrectly, maybe someone else can see something?

Cheers,

Zooba :U
Title: Re: Listview Sort Problem
Post by: TNick on November 04, 2007, 02:09:30 PM
Shouldn't be finit there? Before any other floating point instructions? Sorry, no time to investigate...

Nick
Title: Re: Listview Sort Problem
Post by: MichaelW on November 04, 2007, 08:19:15 PM
To eliminate the crashes I substituted a CRT conversion function for StrToFloat. The problem was an access violation, but I didn’t attempt to determine exactly why or where it was occurring. To do the substitution I replaced everything from:

.486

To:

includelib masm32.lib

With:

include \masm32\include\masm32rt.inc

And replaced the two invoke StrToFloat statements with:

invoke crt_atof, ADDR TBUFFER1
fstp tdq
invoke crt_atof, ADDR TBUFFER2
fstp tdq1

In case it’s not apparent the CRT function returns a floating-point result on the FPU stack in the top data register, and the FSTP instruction copies the value to memory and then pops it from the FPU stack.

To get the code to sort the floating-point items correctly I substituted FCOMPP for FCOM, so the values pushed by FLD would be popped from the FPU stack, leaving it empty.

http://www.ray.masmcode.com/fpu.html

Also, although it does not appear to be causing a problem, an ASSUME dataregister:qualifiedtype should generally followed by a matching ASSUME dataregister:NOTHING.
Title: Re: Listview Sort Problem
Post by: sonic on November 05, 2007, 01:05:45 PM
Thanks for suggestions. Now i got the floats working but strings still seems being sorted as case insensitive. So "learn..." should be sorted to top or bottom?

Here is updated source incase anyone else having problems like me.

[attachment deleted by admin]