I am still feeling my throug using floating points in MASM. In this particular case I am trying to negate a floating point number and then send it to a function. If I have interrpreted all this correctly you pretty much have to use the st register (which I can't seem to find in the MASM32 help anywhere) to store floats for operations. But to get a value in there it has to be popped off the stack as opposed to moved. I still can't seem to get the value back from st and into a register or variable that I can send a function. A little help please... LOCAL neg_one:REAL4 ;## Move 1.0 into the st register FLD gTB3DOneFloat FST st ;## change the sign on st to - FCHS mov neg_one,st invoke glVertex3f, neg_one, neg_one, 0
fld one fchs fstp negativeone
Yep, Kenny is right. You see fld can be seen as pushing a value onto the FPU stack so
Puts gTB3DOneFloat in st, and would have pushed anything in st previously to st(1), and st(1) to st(2), etc Fst stores the value in st into the location you specify,it can be memory or a laction on the FPU stack, eg st(1). your command however
is a redundant command as it put st into st, much like mov eax, eax. As you rightly guessed fchs only works on st and you did this correctly. To then store the value in st to neg_one you should use
. Note that if you want to empty st while you store the value use
instead as this then pops st off the stack moveing st(1) back to st, etc. I hate to always suggest my own site but if you go to it (link should be in signature) you'll find two FPU tutorials with accompanying code.
Thank you all for your replies, espeically Zad. I didn't realize that floats had their own seperate stack and that st was the pointer to that stack (I thought it was a register). Thank you!
Or, you can hard code it :) Just to confuse you more :) one EQU 1065353216 neg_one EQU -1082130432