I'm playing with some opengl, below is part of the code in question:

roty dd 1.0 ;y-axis - dwords hold float values too?
theta dd 0.5 ;angle=0.0 to 360.0


fld roty ;what the heck does this do
fadd theta ; add 0.5 to whatever is out there
fstp theta ; pop result into theta, overwriting and screwing it up

I'm just trying to do something like:

theta=theta+0.5

It won't let me do:

add theta,0.5 ; no real number or BCD allowed, I slap you hand

I guess I could compare it though, such as:

cmp theta,360 ; valid?
cmp theta,45.0 ; theta is a float?

any pointers would be appreciated. Thanks
Posted on 2003-10-10 02:18:17 by drarem
ok.. I got it going - it's not stopping like I expect it to.. the rotation is working but the comparison is not.




.data
tst dd 0.5
theta dd 0.0
:: ::


fld tst ; load global value tst onto ST0
fadd theta ; add theta to ST0
fcom lmt ; compare ST0 with lmt(45.0f)
jle skip ; jump if <= to skip
fsub tst ; else subtract it from itself to reset to 0?
skip:
fstp tst ; pop ST0 back into tst
Posted on 2003-10-10 02:55:09 by drarem
The fcom instruction does NOT change the CPU's flag register. Look at the following for the use of the FPU's comparison instructions.

http://www.masmforum.com/website/tutorials/fptute/fpuchap7.htm

Raymond
Posted on 2003-10-10 10:23:43 by Raymond
nice tutorials, thanks. I will study them.
Posted on 2003-10-10 12:16:30 by drarem
Below produces the expected results, thanks again.

Now if someone can explain what the heck I did.. maybe look over my comments and see what I am
missing.. is that a proper way of doing it? Seems like alot of work.



.data
theta dd 0.5 ; for fpu usage, determines rotation speed
tst dd 0.0 ; variable that will be used outside the fpu
lmt dd 45.0 ; limit to rotating angle, also for fpu usage only

:: :: :: ::
:: :: :: ::

.code
fld tst ;load ST(0) with global value of tst
fadd theta ;add global value of theta to tst
fcom lmt ;compare with global value of lmt, which is 45.0
fstsw ax ;copy to ax register
sahf ;and don't forgit the flags
jbe skip ; tst <= lmt? skip the rest
fsub tst ; else tst=0 and be the best
skip:
fstp tst
_glRotatef tst, 1.0f, 1.0f, 0.0f
Posted on 2003-10-10 23:47:48 by drarem
whenever I want to compare floats, I use the regular cmp :grin: :


mov eax,f2
cmp f1,eax
jge _somewhere ; if(f1>f2)

I think there was something catchy when comparing floats with different signs.
Posted on 2003-10-11 01:00:45 by Ultrano
You should use the fcomi instructions instead. Most chips in use today support them.
.data

theta dd 0.5 ; for fpu usage, determines rotation speed
tst dd 0.0 ; variable that will be used outside the fpu
lmt dd 45.0 ; limit to rotating angle, also for fpu usage only

:: :: :: ::
:: :: :: ::

.code
fld tst ;load ST(0) with global value of tst
fadd theta ;add global value of theta to tst
fcomi lmt ;compare with global value of lmt, which is 45.0
jbe skip ; tst <= lmt? skip the rest
fsub tst ; else tst=0 and be the best
skip:
fstp tst
_glRotatef tst, 1.0f, 1.0f, 0.0f
Posted on 2003-10-11 09:44:45 by Eóin
fsub tst ; else tst=0 and be the best
From the comment, I have to assume that you want tst to be rezeroed when you exceed 45. However, if you subtract tst from tst+0.5, the result is 0.5!

If you do decide to use the fcomi instruction as suggested by E?in, remember to use the .686 directive as indicated in that tutorial under the FCOMI instruction.

Raymond
Posted on 2003-10-11 11:27:01 by Raymond