The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: ToutEnMasm on November 14, 2006, 05:31:08 PM

Title: ascii to real translation
Post by: ToutEnMasm on November 14, 2006, 05:31:08 PM

Hello,
I have a lot of real numbers to put on a structure and
fld 0.5  ;error A2050: real or BCD number not allowed

Is there an ascii to real function somewhere ?
                        ToutEnMasm
Title: Re: ascii to real translation
Post by: Draakie on November 15, 2006, 06:09:33 AM
There's one in the MASM32 - see FpuLIB by Raymond.


Title: Re: ascii to real translation
Post by: sinsi on November 15, 2006, 06:38:20 AM
FLD needs the source to be a memory address, so to use "fld 0.5" try
.const
half REAL4 0.5   ;can be REAL8 or REAL10
.code
...
fld half


That error should say "immediate value not allowed"... ::)
Title: Re: ascii to real translation
Post by: ToutEnMasm on November 15, 2006, 06:46:12 AM
Thanks at all,

It's the method i have first used

TREAL4 MACRO pvalue:REQ,text:REQ
invoke StrToFloat,SADR(text),addr ChargeReal
fld real8 ptr ChargeReal
  fstp real4 ptr pvalue
ENDM


But zooba have posted a macro in the masm forum that solve the problem using the definition of a real4.

movr4 MACRO dest, src
mov dest, 0BADF00Dh ; make sure it's using a full DWORD move
ORG $-4
REAL4 src ; now overwrite with our real number
ENDM


The two give the same result ,but the movr4 used less time of the processor.

and the method with defined constants give another useful
                                      ToutEnMasm






                                         ToutEnMasm

Title: Re: ascii to real translation
Post by: ToutEnMasm on November 15, 2006, 07:19:22 AM

Ok,it seems that i have learn something this time.I have write a very simple method
I have verified it with the debugger,the result is correct.
                                   ToutEnMasm


R4MOV MACRO dest,src
     local reel
    .const
reel REAL4 src
     .code
PUSH reel
POP dest
ENDM