Author Topic: Float to ASCII  (Read 136 times)

JK

  • Regular Member
  • *
  • Posts: 44
Float to ASCII
« on: June 04, 2020, 02:25:47 AM »
I want to display floating point numbers, but my code doesn´t work. What am i doing wrong?

Code: [Select]

.386
.model flat, stdcall

include <windows.inc>
include <c:\masm32\include\msvcrt.inc>


includelib kernel32.lib
includelib user32.lib
includelib <C:\masm32\lib\msvcrt.lib>


.data
  r8fmt   BYTE "%F", 0
  r8value REAL8 2.0

.code


start proc
;***************************************************************************
;
;***************************************************************************
local buffer[100]:byte


  lea eax, buffer
  mov byte ptr [eax], "F"
  add eax, 1
  mov byte ptr [eax], ":"
  add eax, 1
  mov byte ptr [eax], " "
  add eax, 1


  invoke crt__snprintf, eax, 96, ADDR r8fmt, r8value ;output float
  invoke MessageBoxA, 0, ADDR buffer, CSTR("Float"), 0

  invoke ExitProcess, 0
  ret

   
start endp


end start



Thanks


JK

jj2007

  • Member
  • *****
  • Posts: 10438
  • Assembler is fun ;-)
    • MasmBasic
Re: Float to ASCII
« Reply #1 on: June 04, 2020, 03:37:17 AM »
Use lowercase %f

JK

  • Regular Member
  • *
  • Posts: 44
Re: Float to ASCII
« Reply #2 on: June 04, 2020, 06:02:28 AM »
Thanks a lot - this one cost me quite some time!

I´m asking myself why the uppercase version just doesn´t work. According to here (https://en.cppreference.com/w/c/io/fprintf) and here (http://www.cplusplus.com/reference/cstdio/printf/) it definitely should.


JK