Author Topic: Printing floating point not working.  (Read 533 times)

Chris.

  • Regular Member
  • *
  • Posts: 12
Re: Printing floating point not working.
« Reply #15 on: August 17, 2017, 10:07:02 PM »
I added whole code if it helps

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: Printing floating point not working.
« Reply #16 on: August 17, 2017, 11:12:16 PM »
I added whole code if it helps

It helps:
Code: [Select]
Finished:
   fstp squareroot
   if 1
    .DATA
$interm8 db "%0.20f",13,10,0
    .CODE
invoke sprintf, addr szBuf, offset $interm8, squareroot
   else
; $interm db "%0.4f + %0.4f",13,10,0
mov eax, dword ptr squareroot
mov edx, dword ptr [squareroot+4]
invoke sprintf, addr szBuf, offset $interm, eax, edx
   endif

If I guessed right, you want to print the squareroot, which you declared inconsistently as dq. Assemblers are tolerant, but they should shout foul instead. QWORD is an integer, you want an 8-byte float. They are commonly called "double" in C land, or REAL8 in assembly. As a matter of fact, the invoke macro knows how to handle them.

P.S.: The if 1 ... else ... endif part is called conditional assembly: just put if 0 to build your old version.

raymond

  • Member
  • **
  • Posts: 174
    • Raymond's page
Re: Printing floating point not working.
« Reply #17 on: August 18, 2017, 05:10:24 AM »
Chris,
To answer your very first question, the answer is YES. Floating point numbers CAN be printed directly from an fpu register. However, if you don't know how to do it, you can use some other external procedures until you have learned how to use assembly, including fpu mnemonics, to do it yourself. One such procedure is included in the Fpulib available on the same site where you read (but did not understand) the description of the 'fist' instruction. If you are really interested, that library also comes with the code for each of the procedures.

Quote
I thought the "fist" instruction allows you to store fpu numbers into memory or variables.
It does allow you to store it into a memory variable but as its ROUNDED INTEGER, rounded according to the content of the fpu's Control Word (http://www.ray.masmcode.com/tutorial/fpuchap1.htm#cword). Once rounded, that integer CANNOT be converted back to the original float; and trying to print that as a float would only yield garbage.

As for your recent question
Quote
What if i want two different variables in one string?
, whether you have two, three, or 100+, the only way in assembly is to build the string one variable at a time yourself in a buffer before printing it.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

RuiLoureiro

  • Member
  • ****
  • Posts: 671
Re: Printing floating point not working.
« Reply #18 on: August 18, 2017, 08:24:43 AM »
Hi
    Here how to convert to string to print
    or string to real10

    http://masm32.com/board/index.php?topic=1852.0
    http://masm32.com/board/index.php?topic=1914.msg19899#msg19899