Hi all. I want to modify FloatToStr so it expects input in st(0). It seemed like such a simple thing, yet I cannot get it to work. It involves changing the initial tests for "zero" and "negative" to operate on st(0) instead of the qword input. I can't find the right combination of fp ops to make the tests correctly.

I'm really anxious to get this working cus I can make a macro str$() which will know how to convert any numeric variable to string output. Could someone show me the correct code to test st(0) for zero & negative?

pseudo code

if st(0) == 0
mov word ptr outstr, "0"
ret
elseif st(0) < 0
compliment st(0)
set signflag
endif

Thanks
Posted on 2002-07-09 13:24:01 by gfalen
Well here's code which should work.

ftst
fstsw ax
sahf
je zero
ja negt

Or if you'd like to use the faster fcomi instructions

fldz
fcomip st,st(1)
je zero
jb negt

Such a MACRO sounds very useful, I'd love to see it.
Posted on 2002-07-09 17:27:09 by Eóin
Hey eoin. Im still gettin garbage out. Maybe you could tae a look at the original code and come up with a definate modfication that works. I just dont get what I'm doin wrong. Here's what I have...



_ftoa2 proc szdbl:ptr byte ; convert st(0) to string
local iexp, stat:word, mystat:word

mov edi, szdbl
fldz
fcomip st,st(1)
jne @f ;je zero
mov .w[edi], "0"
return edi

@@:
jae @f ;jb negt
fchs
mov .b [edi], '-' ; store a minus sign
inc edi

@@: ; and we pick up the origonal routine from here...
Posted on 2002-07-09 17:57:32 by gfalen
I think I may have had the jb/ja mixed up above, anyway this seem to work for me.
TosToStr	PROC	stdcall public USES esi edi,  

szDbl: PTR CHAR

LOCAL iExp: DWORD
LOCAL stat: WORD
LOCAL mystat: WORD

; Special case zero. fxtract fails for zero.

mov edi, [szDbl]

fldz
fcomip st,st(1)
jne @F

mov byte ptr [edi], '0'
mov byte ptr [edi][1], 0
ret

@@:
jb @F
; Check for a negative number.

fchs ; change to positive
mov byte ptr [edi], '-' ; store a minus sign
inc edi
@@:

; Initialize the floating point unit and load our value onto the stack.

fclex
fstcw [stat]
mov [mystat], 027fh
fldcw [mystat]

fld st(0)
Everything else is the same as for FloatToStr
Posted on 2002-07-10 10:23:53 by Eóin