Skip to main content
gamedev.net
🔒 Locked

Floating Assembly

Started by Last Attacker 3 replies 550+ views
Original Post
Last Attacker
Last Attacker
Hey, I discovered how to do floating point assembly but there are a few things that I still don''t get or understand. I know that the CPU has the interger processor and the floating processor but only the integer processor has registers that you can use like as if it was a variable. With float, I have to load something into the ST# stack (I think its better known as the floating point register) with the fld instruction. I know the add, subtract, multiply and divide instructions (and how to return a value from ST0 back to the pointed memory location). Here is something I don''t know how to do and I''m hoping you guys can help me out : How can I put a constant into the ST# stack equasion without using a memory location. For instance, if I where to divide by 2 I had to do this : float result = 4.0; float two = 2.0; __asm { fld dword ptr [result] fdiv dword ptr [two] fst dword ptr [result] } Another question : How can I put values into ST# (# > 0) and still use that with ST0 in calculations (like put that 2 to divide with in ST1 and result = ST0/ST1). Thanks ----------=Last Attacker=---------- ICQ: 120585863 E-mail: laextr@icqmail.com
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
tr0n
tr0n
Regarding constants: by and large, you can''t, with the following exceptions:

FLD1 will load 1 onto the stack.
FLDZ will load 0 onto the stack.
FLDPI will load pi..
FLDL2E will load log base 2 of e
FLDL2T will load log base 2 of 10
FLDLG2 will load log base 10 of 2
FLDLN2 will load natural log of 2.

Otherwise, you have to write your constant into memory & load that.

To load a value into ST(1):

fld [value]
fxch st(1)

will load it into st(0) and then exchange st(0) with st(1). Note that the fxch will pair with fld and execute in the same clock cycle, so slow-down isn''t a problem.

Last Attacker
Last Attacker
Instead of saying float two = 2.0;
Is there a way in assembly to do this,
like :

move dword ptr [esp +4], 2

or something?

I know it isn''t the correct way but if it is possible to do it like that, I don''t have to declare a variable all the time!

You know what I mean?

Anyway thanks tr0n!



----------=Last Attacker=----------

ICQ: 120585863
E-mail: laextr@icqmail.com
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
tr0n
tr0n
There is a way, but you won''t like it

Get out your pencil and paper, and work out what the bit pattern for 2.0 is going to be. You''re going to have to read up a bit on the IEEE representation of floats, though. Then convert that into a hex number, and put that into your asm code. AFAIK, that''s the only way to do it in asm, and it''s certainly the way VC++ does it.

2.0 is a fairly simple one, by the way.
Last Attacker
Last Attacker
Yeah, I read a bit on that floating to hex converting, I think I''ll be able to do it or something but thanks again tr0n!

----------=Last Attacker=----------

ICQ: 120585863
E-mail: laextr@icqmail.com
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.