I am learning assembler for a few days now (I usually program with VB.net or Java)
and wanted to do some basic calculations with floating-point numbers to understand the logic of the FPU.
finit
fld dword ptr [value1]
fld dword ptr [value2]
fadd
fstp dword ptr [sum]
My problem is that I am not sure how to convert my result in [sum] to the screen.
With unsigned integers I usually use:
print str$(sum)
But that doesn't work! I know that this is basic stuff, but I'm really frustrated. :sad:
I hope that you can help me. Thank you already in advance. :biggrin:
I am working in 64 bit these days but see if one of the MSVCRT functions like "_sprintf" will work for you. In 32 bit MASM32 there is the C runtime function "crt_sprintf". Check the Microsoft documentation to see if it works.
Welcome to the forum!
If you have declared:value1 real4 0.0
value2 real4 0.0
sum real4 0.0
you can use:print real4$(sum)
Same thing with real8:.data
value1 real8 2.0
value2 real8 5.0
sum real8 0.0
.code
finit
fld value1
fld value2
fadd
fstp sum
print real8$(sum)
You also can use FPU for integers width Fild,,fistp and str$.
Thanks, that helped very much. :biggrin: :thup:
Quote from: HSE on July 17, 2020, 12:14:47 AM
Welcome to the forum!
If you have declared:value1 real4 0.0
value2 real4 0.0
sum real4 0.0
you can use:print real4$(sum)
Same thing with real8:.data
value1 real8 2.0
value2 real8 5.0
sum real8 0.0
.code
finit
fld value1
fld value2
fadd
fstp sum
print real8$(sum)
You also can use FPU for integers width Fild,,fistp and str$.
Warm welcome to this forum.
Quotewanted to do some basic calculations with floating-point numbers to understand the logic of the FPU
Did you have a look at this (which is really a part of this site): http://www.ray.masmcode.com/fpu.html
Yeah, that's the page where I learned the basic mnemonics for the FPU. :smiley:
You can also use the available library to perform a number of functions, and to also learn how those can be coded to avoid the overhead (and improve speed); the algo for all the functions is provided.