Hi
Lately I was writing a lot of stuff for the FPU and I realized that I frequently had to load constants into the FPU stack to perform some calculations. Like some others I initialized a CONST value and loaded it from there.
The macro I wrote performs this, but it first checks if the desired value was already defined. If that is the case, it uses this previous value, avoiding a second instance.

Here is the macro

$CFloat macro FloatValue
    ifidn @SubStr(<FloatValue>, 1, 1), <->
      ??FloatName CatStr <CR4_m>, @SubStr(<FloatValue>, 2)
    else
      ifidn @SubStr(<FloatValue>, 1, 1), <+>
        ??FloatName CatStr <CR4_p>, @SubStr(<FloatValue>, 2)
      else
        ??FloatName CatStr <CR4_p>, <FloatValue>
      endif
    endif
    ??FloatDotPos InStr 1, ??FloatName, <.>
    ??FloatName CatStr @SubStr(%??FloatName, 1, ??FloatDotPos-1), <_>, @SubStr(%??FloatName, ??FloatDotPos+1)
%  ifndef ??FloatName
      CONST Segment
      ??FloatName real4 FloatValue
      CONST ends
    endif
    exitm <??FloatName>
endm


I attached a demo file to show how it works.

Regards,

Biterider
Attachments:
Posted on 2007-03-11 08:42:22 by Biterider