While I was testing the graphics lib with MASM I ran into an interesting problem. In GoAsm 4 bytes is 4 bytes, doesn't matter what you put in it. So if you had a function that had a REAL4 parameter you can do this:

invoke Deg2Rad, 45.5

or

push 45.5
call Deg2Rad

And it will push the immediate value 42360000h onto the stack (45.5 in REAL4). But in MASM I could find no way to use an immediate for a REAL4 number, REAL4 PTR 45.5, DWORD PTR 45.5 etc... all failed. I eventually had to declare it in my data section and use the variable in an invoke (though PUSH works too). My question is does anyone know how to use REAL4 immediates in MASM ?
Posted on 2004-08-06 20:55:48 by donkey
GoAsm probably has a macro which is inserted in the code to convert immediate floats. If you disassemble the code generated by GoAsm, you should find how that assembler does it. OTOH, it may convert it at compile time without inserting extraneous code. MASM does not have any conversion feature within code instructions.

FYI, HLA also inserts code to convert immediate floats at run-time, and would blindly trash any valid data which may be in those FPU registers which are required for the conversion. GoAsm may/maynot be doing the same thing.

If trashing of valid data in FPU registers must be avoided, it's always safer to set those "immediate" floats in global variables, regardless of the assembler you are using.

Raymond
Posted on 2004-08-06 22:11:37 by Raymond
Hi Raymond,

No, GoAsm converts the float at compile time and pushes the immediate value.

push 45.5

compiles to

68 00 00 36 42 push 42360000

MASM obviously has the capacity to convert REAL4 numbers, after all you can declare

.data
blah REAL4 45.5

and it will convert it to 42360000h in the data section. There is no logical reason that MASM can't do it in code as well, 4 bytes is 4 bytes. This obviously has nothing to do with trashing the FPU, there are many calls especially with GDI+ that require a REAL4 parameter be pushed onto the stack. It seems like a useless waste if you have to declare each one in order to use it. But if it can't it can't, I use GoAsm and that can do it so I am not worried, I was just curious.
Posted on 2004-08-06 22:24:39 by donkey
You can do it like this

DB 68h
REAL4 45.5
CALL Deg2Rad

And it works perfectly.

A little macro for it:

pushr macro arg1

db 68h
REAL4 arg1
endm

pushr 45.5
Posted on 2004-08-07 00:17:15 by donkey