In last days I was playing with C++, ASM and inline ASM. I know how to access basic variables in memory and similar things. Now I’m trying to work with floating-point numbers in ASM.
I have disassembled this code:
float A = 0.058;
and I have this result:
fld dword ptr ds:[00415744h]
fstp dword ptr [ebp-8]
But I don’t understand this code. I was searching on google but I have not found anything usable for me. Can anybody explain me real numbers in ASM and can anybody explain me this code? Please help me.
The first line loads constant float value 0.058 to the FPU stack. The second line copies the top of FPU stack to the CPU stack, addressed by ebp-8.
You can read about FPU instructions here: http://maven.smith.edu/~thiebaut/ArtOfAssembly/CH14/CH14-4.html or in any other Assembly reference.
Edit.
dword ptr [ebp-8] copies the top of FPU stack to DWORD-size local variable on the stack. From Assembly reference, EBP (base pointer): Assembly function sets the base pointer equal to the stack pointer and then places its own internal variables on the stack. From that point on, the function refers to its parameters and variables relative to the base pointer rather than the stack pointer.