FPU_Examples ..
Loading on and retrieving from the FPU Stack
When you load a value it is pushed onto the Top of Stack (TOS). This is to say that ST0 holds the new value and all other records are moved one step down.
[MyFloat: F§ 12.34] [ MyInterger: 82]
fld F§MyFloat ; Load Float (mem > tos) ST0 = 12.34
fild D§MyInteger ; Load Integer (fmem > tos) ST0 = 82, ST1 = 12.34
fld F§MyFloat____________________
ST0: 12.34
ST1: xxx
...
ST9: xxx
fild D§MyInteger__________________
ST0: 82
ST1: 12.34
ST2: xxx
...
ST9: xxx
When a value is retrieved, the tos is read. If the instruction ends with a p, the TOS is popped and all other records are moved one step up.
________________________________
ST0: 82
ST1: 12.34
ST2: xxx
...
ST9: xxx
fstp F§MyFloat ; Store Float (from ST0 to mem) and pop tos
fistp D§MyInteger ; Store Integer (from ST0 to mem) and pop tos
fstp F§MyFloat____________________
ST0: 12.34 >>> F§MyFloat = 82 (real4)
ST1: xxx
...
ST9: xxx
fistp D§MyInteger__________________
ST0: xxx >>> F§MyInteger = 12 (dWord Integer)
ST1: xxx
ST2: xxx
...
ST9: xxx
Basic Math Instructions
Take care that, when translating from MASM to RosAsm, that MASM does *not* always encode what is written in the source file. MASM replaces, for example, fdiv, without parameter, by fdivp. So, before translating a MASM FPU source, make a disassembly of the source to get the true thing first.
RosAsm syntax allows you to omit the parameters of an instruction when they are ST0 (if one parameter), ST0 ST1 (if two parameters). You should not use this feature, as it is very confusing for several intructions, for which the default should be the reverse, and you should write all the parameters to conform with the standard syntax of NASM assembler and to ensure the higher readability.
fadd / faddp / fiadd
[Float1: RS 12.34 Float2: F§ 0.124]
fld R§Float1 ; Load Float1 on tos
fadd F§Float2 ; add Float2 to ST0. Result in ST0
fld F§Float2 ; loads Float2 on tos, pushing down
fadd ST1 ST0 ; add ST1 to ST0. Result in ST1
faddp ST0 ST1 ; add ST0 to ST1. Result in ST0
fld R§Float1 _____________________
ST0: 12.34
ST1: xxx
...
ST9: xxx
fadd F§Float2_____________________
ST0: 12.464
ST1: xxx
...
ST9: xxx
fld F§Float2______________________
ST0: 0.124
ST1: 12.464
ST2: xxx
...
ST9: xxx
fadd ST1 ST0_____________________
ST0: 0.124
ST1: 12.588
ST2: xxx
...
ST9: xxx
faddp ST0 ST1_____________________
ST0: 12.712
ST1: xxx
...
ST9: 0
fsub / fsubp / fisub // fmul / fmulp / fimul // fdic / fdivp / fidiv
Same availability as fadd
~~~~~~~