The MASM Forum

General => The Campus => Topic started by: JK on June 04, 2020, 02:25:47 AM

Title: Float to ASCII
Post by: JK 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?



.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
Title: Re: Float to ASCII
Post by: jj2007 on June 04, 2020, 03:37:17 AM
Use lowercase %f
Title: Re: Float to ASCII
Post by: JK 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