Assembly code snippets

Back to the snippets overview

Details

TitleInline FP Constants (macro)
AuthorbitRAKE
Submitted by:bitRAKE
Date added:2002-02-17 21:24:07
Date modified:2002-02-23 19:12:16

Comments

This macro provides a method to use floating point constants inline without explicitly declaring them in the CONST segment. Additionally, the macro works to reduce the data by reusing already defined constants, and groups all the constants together into their own sub-segment CONST$fp, which will be combined with the CONST segment at link time.

dxantos provided a fix to allow negitive numbers.

Snippet

; Examples:
;   fmul fpc(10)
;   fld fpc(<REAL8 -8>)


fpc MACRO val:REQ
    LOCAL w,x,y,z

    ;; split type and value, defaulting to REAL4
    z INSTR 1,<&val>,<! > ;; TAB doesn't work!
    IF z EQ 0
        y TEXTEQU <REAL4>
        x TEXTEQU <&val>
    ELSE
        ;; REAL4 REAL8 or TBYTE
        y TEXTEQU @SubStr(<&val>,1,z-1) ;; Type
        x TEXTEQU @SubStr(<&val>,z+1,)  ;; Value
    ENDIF

    ;; replace . with _
    z INSTR 1,x,<!.>
    IF z EQ 0
        w TEXTEQU x
        x CATSTR x,<.0> ;; prevent error message
    ELSE
        w CATSTR @SubStr(%x,1,z-1),<_>,@SubStr(%x,z+1,)
    ENDIF

    ;; replace - with _
    z INSTR 1,w,<!->
    IF z NE 0
        w CATSTR @SubStr(%w,1,z-1),<_>,@SubStr(%w,z+1,)
    ENDIF

    ;; figure out global name for constant
    z SIZESTR y ;; use last char for size distiction
    w CATSTR <__>,w,<r>,@SubStr(%y,z,1)

    IF (OPATTR(w)) EQ 0 ;; not defined
        CONST$fp SEGMENT
            w y x
        CONST$fp ENDS
    ENDIF
    EXITM w
ENDM