fldpi ; Push "pi" onto floating-point stackThere are lots of useful floating-point instructions:
sub esp,8 ; Make room on the stack for an 8-byte double
fstp QWORD [esp]; Push printf's double parameter onto the stack
push my_string ; Push printf's string parameter (below)
extern printf
call printf ; Print string
add esp,12 ; Clean up stack
ret ; Done with function
my_string: db "Yo! Here's our float: %f",0xa,0
| Assembly |
Description |
| fld1 |
Pushes into the floating-point registers the constant 1.0 |
| fldz |
Pushes into the floating-point registers the constant 0.0 |
| fldpi |
Pushes the constant pi. (Try this in NetRun now!) |
| fld DWORD [eax] |
Pushes
into the floating-point registers the 4-byte "float" loaded from memory
at address eax. This is how most constants get loaded into the
program. (Try this in NetRun now!) |
| fild DWORD [eax] |
Pushes into the floating-point registers the 4-byte "int" loaded from memory at address eax. |
| fld QWORD [eax] |
Pushes an 8-byte "double" loaded from address eax. (Try this in NetRun now!) |
| fld st0 |
Duplicates the top float, so there are now two copes of it. (Try this in NetRun now!) |
| fstp DWORD [eax] | Pops the top floating-point value, and stores it as a "float" to address eax. |
| fst DWORD [eax] | Reads the top floating-point value and stores it as a "float" to address eax. This doesn't change the value stored on the floating-point stack. |
| fstp QWORD [eax] | Pops the top floating-point value, and stores it as a "double" to address eax. |
| faddp |
Add the top two values, pushes the result. (Try this in NetRun now!) |
| fsubp |
Subtract the two values, pushes the result. Note "fld A; fld B; fsubp;" computes A-B. (Try this in NetRun now!) There's also a "fsubrp" that subtracts in the opposite order (computing B-A). |
| fmulp |
Multiply the top two values. |
| fdivp |
Divide the top two values. Note "fld A; fld B; fdivp;" computes A/B. (Try this in NetRun now!) There's also a "fdivrp" that divides in the opposite order (computing B/A). |
| fabs |
Take the absolute value of the top floating-point value. |
| fsqrt |
Take the square root of the top floating-point value. |
| fsin |
Take the sin() of the top floating-point value, treated as radians. (Try this in NetRun now!) |
| F2XM1 |
2x - 1 |
| FYL2X |
y*log2(x), where x is on top of the floating-point stack. |
| FYL2XP1 | y*log2(x+1), where x is on top |
| FCHS |
-x |
| FSINCOS |
Computes *both* sin(x) and cos(x). cos(x) ends up on top. |
| FPATAN |
atan2(a/b), where b is on top |
| FPREM |
fmod(a,b), where b is on top |
| FRNDINT |
Round to the nearest integer |
| FXCH |
Swap the top two values on the floating-point stack |