News:

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

MASM REAL8 Invoke

Started by Matthew, May 02, 2012, 11:53:54 PM

Previous topic - Next topic

Matthew

I am currently attempting to start working with REAL8 datatype for OpenGL functions.

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

After hitting the dreaded: error A2050: real or BCD number not allowed ...
e.g

local x:REAL8
mov x, 0.0


i did some googling to find that I cant just use floating point values like that with push and mov etc, at least in masm however people have mentioned some workarounds and talk about something called invoke2 ... which handles that kind of thing

I have also seen being used things like

mov x, R8(0.0)


Can anyone share any information on the above macros, and where i can get the .inc files for them...

It looks like im going to have to learn all about the FPU which is interesting, but im kind of stuck at the first hurdle...

Is there any better tutorials for FPU coding than this?
http://www.website.masmforum.com/tutorials/fptute/

Some

qWord

you can use the macros FP4(value) and FP8(value) which are part of MASM32 (macros.asm). However, MASM allows FP constants only for data declaration, thus the macros return a memory expression  (REAL4/8).

R4 macro value:req
LOCAL lbl
    .data
        lbl REAL4 value
    .code
    EXITM <lbl>
endm
...
mov eax,R4(1.2)
...
m2m x,R4(123.4)
invoke gluPerspective,R4(...),R4(...),...
FPU in a trice: SmplMath
It's that simple!

MichaelW

Quote from: Matthew on May 02, 2012, 11:53:54 PM
i did some googling to find that I cant just use floating point values like that with push and mov etc, at least in masm however people have mentioned some workarounds and talk about something called invoke2 ... which handles that kind of thing

Within limits you can use MOV, PUSH, POP. Basically, for FP values larger than a DWORD you need to manipulate the individual components, and indicate to MASM what you wish to do. Also, the normal INVOKE can readily handle REAL8 arguments.

;==============================================================================
include \masm32\include\masm32rt.inc
;==============================================================================
.data
    r4    REAL4 0.0
    r8_0  REAL8 0.0
    r8_1  REAL8 0.0
.code
;==============================================================================
start:
;==============================================================================
    mov eax, FP4(1.23)
    mov DWORD PTR r4, eax

    ;-------------------------------------------------------
    ; The CRT printf function expects FP args to be of type
    ; double (REAL8), so use the FPU to do the conversion.
    ;-------------------------------------------------------

    fld r4
    fstp r8_0

    printf("%f\n\n", r8_0)

    push DWORD PTR r8_0+4
    push DWORD PTR r8_0
    pop DWORD PTR r8_1
    pop DWORD PTR r8_1+4

    printf("%f\n\n", r8_1)

    invoke crt_printf, cfm$("%f\n\n"), r8_1

    inkey
    exit
;==============================================================================
end start


And the relevant macros are defined in \masm32\macros\macros.asm.
eschew obfuscation