News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GL command with float data type

Started by lincolnzzy, August 11, 2006, 03:22:36 PM

Previous topic - Next topic

lincolnzzy

If programming with c/c++,I can write code like this: "glNormal3f(0.0f,1.0f,0.0f)" .
and replace to asm ,I need write to:
[
x    dword 0.0
y   dword  1.0
z   dword  0.0
    invoke glNormal3f,x,y,z
]

look,some statement west my time,i wish to write like this: "invoke glNormal3f,0.0,1.0,0.0",
but,assembling failed ,because 0.0(imm data type )can't support float in masm.
so,how to solve this problem? I want directly to use float data type 0.0 in op,how can't I do?

Mark Jones

Hello Lincolnzzy,

One way to accomplish this is with a macro. Try this:


include Framework.asm
.code
    invoke glNormal3f,CFLT(0.0),CFLT(1.0),CFLT(0.0)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

lincolnzzy


lincolnzzy

But ,another problem,where is the Framework.asm?? I can't find it in masm32 packge.so ,tell me!!!

Boucly

QuoteBut ,another problem,where is the Framework.asm?? I can't find it in masm32 packge.so ,tell me!!!

Examples archives content and urls by hitchhikr

Boucly

savage

I made my own group of macros for defining constant floats and doubles on the fly, and they are good in that they will not use more memory if you define the same number twice, (i.e. the constant "1.0" will only exist once in memory even if you attempt to define it 100 times in your program).



     ;---------------------------------------
     ;          Savage's Macros
     ;---------------------------------------
     ; <$String>
     ; <$fConst>
     ; <$dConst>
     ; <$float>
     ; <$double>
     ;---------------------------------------

;#################################################
;#                Macros
;#################################################


     ;---------------------------------------
     ; <$String>
     ;  Used to define a string (duh).
     ;---------------------------------------
     ; e.g.
     ;  mov eax, $String("hello")
     ;---------------------------------------
     $String MACRO sTEXT
          LOCAL szText
          .data
           szText db sTEXT, 0
          .code
          EXITM <Offset szText>
     ENDM
     
     
     ;---------------------------------------
     ; <$Const>
     ;  Used to define a DWORD constant.
     ;  It will be reused if you define
     ;   the same number again.
     ;---------------------------------------
     ; e.g.
     ;  mov eax, $Const(55)  ; (eax and ecx now point
     ;  mov ecx, $Const(55)  ;  to the same location
     ;                       ;  in memory.)
     ;---------------------------------------
     $Const MACRO Num
          result textequ @CatStr(<c_>,<%Num>)
          % IFNDEF result
            .const
              result dd Num
            .code
          ENDIF
          EXITM <result>
     ENDM
     
     ;---------------------------------------
     ; <$fConst>
     ;  Used to define a REAL4 constant.
     ;  It will be reused if you define
     ;   the same number again.
     ;---------------------------------------
     ; e.g.
     ;  mov eax, $fConst(3.14)  ; (eax and ecx now point
     ;  mov ecx, $fConst(3.14)  ;  to the same location
     ;                          ;  in memory.)
     ;---------------------------------------
     $fConst MACRO Num
           IFIDN @SubStr(<Num>,1,1),<->
                dotposition equ @InStr(2,<Num>,<.>)
               formatted textequ @CatStr(<c_REAL4__>,@SubStr(<Num>,1,dotposition-1),<_>,@SubStr(<Num>,dotposition+1))   
                sgnlocation equ @InStr(1,%formatted,<->)
                formatted textequ @CatStr(<_>,@SubStr(%formatted,1,sgnlocation-1),@SubStr(%formatted,sgnlocation+1))   
           ELSE
                dotposition equ @InStr(2,<Num>,<.>)
               formatted textequ @CatStr(<c_REAL4_>,@SubStr(<Num>,1,dotposition-1),<_>,@SubStr(<Num>,dotposition+1))   
           ENDIF
           %IFNDEF formatted
            .const
              formatted REAL4 Num
            .code
           ENDIF
          EXITM <formatted>
     ENDM
     
     ;---------------------------------------
     ; <$float>
     ;  This is an advanced form of fConst,
     ;  which will automatically append a ".00"
     ;  if an integer is typed; and will just
     ;  let registers and memory pass through.
     ;  This makes it easier to use in more
     ;  situations, indepedent of data type.
     ;---------------------------------------
     ; e.g.
     ;  mov eax, $float(3.0)  ; same as "$fConst(3.0)"
     ;  mov ecx, $float(3)    ; same as "$fConst(3.0)"
     ;  mov ebx, $float(ecx)  ; same as "ecx"
     ;  mov edx, $float(myVar); same as "myVar"
     ;---------------------------------------
     $float MACRO num
          OPVAL TEXTEQU %OPATTR (num)        ; "Op type"
          DECPT TEXTEQU %@InStr(1, num, <.>) ; "Decimal Point"
         
          IF     OPVAL AND 00010000y          ; Register
               exitm <num>
          ELSEIF OPVAL AND 00000100y          ; Immediate
               DUMMYSTR textequ @CatStr(num,<.0>)
               exitm $fConst(%DUMMYSTR)
          ELSEIF OPVAL AND 00000010y          ; Memory reference
               exitm <num>
          ELSEIF DECPT NE 0                    ; Float
               exitm <$fConst(num)>
          ELSE                                   ; Unknown
               .err <This is unknown: num -- OPATTR = OPVAL -- Not float>
          ENDIF
     ENDM
     
     
     ;---------------------------------------
     ; <$dConst>
     ;  Used to define a REAL8 constant.
     ;  It will be reused if you define
     ;   the same number again.
     ;---------------------------------------
     ; e.g.
     ;  mov eax, $dConst(2.718)  ; (eax and ecx now point
     ;  mov ecx, $dConst(2.718)  ;  to the same location
     ;                           ;  in memory.)
     ;---------------------------------------
     $dConst MACRO Num
           IFIDN @SubStr(<Num>,1,1),<->
                dotposition equ @InStr(2,<Num>,<.>)
               formatted textequ @CatStr(<c_REAL8__>,@SubStr(<Num>,1,dotposition-1),<_>,@SubStr(<Num>,dotposition+1))   
                sgnlocation equ @InStr(1,%formatted,<->)
                formatted textequ @CatStr(@SubStr(%formatted,1,sgnlocation-1),@SubStr(%formatted,sgnlocation+1))   
           ELSE
                dotposition equ @InStr(2,<Num>,<.>)
               formatted textequ @CatStr(<c_REAL8_>,@SubStr(<Num>,1,dotposition-1),<_>,@SubStr(<Num>,dotposition+1))   
           ENDIF
           %IFNDEF formatted
            .const
              formatted REAL8 Num
            .code
           ENDIF
          EXITM <formatted>
     ENDM
     
     ;---------------------------------------
     ; <$double>
     ;  This is an advanced form of dConst,
     ;  which will automatically append a ".00"
     ;  if an integer is typed; and will just
     ;  let registers and memory pass through.
     ;  This makes it easier to use in more
     ;  situations, indepedent of data type.
     ;---------------------------------------
     ; e.g.
     ;  mov eax, $double(3.0)  ; same as "$dConst(3.0)"
     ;  mov ecx, $double(3)    ; same as "$dConst(3.0)"
     ;  mov ebx, $double(ecx)  ; same as "ecx"
     ;  mov edx, $double(myVar); same as "myVar"
     ;---------------------------------------
     $double MACRO num
          OPVAL TEXTEQU %OPATTR (num)        ; "Op type"
          DECPT TEXTEQU %@InStr(1, num, <.>) ; "Decimal Point"
         
          IF     OPVAL AND 00010000y          ; Register
               exitm <num>
          ELSEIF OPVAL AND 00000100y          ; Immediate
               DUMMYSTR textequ @CatStr(num,<.0>)
               exitm $dConst(%DUMMYSTR)
          ELSEIF OPVAL AND 00000010y          ; Memory reference
               exitm <num>
          ELSEIF DECPT NE 0                    ; Float
               exitm <$dConst(num)>
          ELSE                                   ; Unknown
               .err <This is unknown: num -- OPATTR = OPVAL -- Not float>
          ENDIF
     ENDM




hitchhikr

The redundancy checking of the floating points variables is a good idea i wanted to implement since some times, i'll update the examples accordingly.