News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

wsprintf float error :/

Started by LechooY, April 27, 2006, 02:51:52 PM

Previous topic - Next topic

LechooY


.386
.model flat, stdcall
option casemap :none
     
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib    

.DATA
FloatNumber real4 1.5
StrFormat DB 'Float is %f',0

Caption DB 'Float Message',0
Buff DB 50  dup (0)

.CODE

START:
push FloatNumber
push offset StrFormat
push offset Buff
call wsprintf

add esp, 12

push MB_OK
push offset Caption
push offset Buff
push 0
call MessageBox

push 0
call ExitProcess
END START


Hi.

What I do wrong?  ::)

I need help :)

Ratch

LechooY ,

     It would be nice if you told us what the problem or error is.  Ratch

arafel

LechooY, wsprintf doesn't support f  format value, hence it can't format floating point numbers.
You could use fpulib functions (it's located in MASM32 folder) to convert floating point numbers to ascii string.

LechooY


GregL

LechooY,

You can also use sprintf from the MSVCRT library.


.386
.MODEL FLAT, STDCALL
OPTION CASEMAP :NONE
     
INCLUDE c:\masm32\include\windows.inc
INCLUDE c:\masm32\include\user32.inc
INCLUDE c:\masm32\include\kernel32.inc
INCLUDE c:\masm32\include\msvcrt.inc

INCLUDELIB c:\masm32\lib\user32.lib
INCLUDELIB c:\masm32\lib\kernel32.lib   
INCLUDELIB c:\masm32\lib\msvcrt.lib

.DATA

    FloatNumber  REAL4  1.5
    DoubleNumber REAL8  0.0
   
    StrFormat    BYTE   'Float is %f',0

    Caption      BYTE   'Float Message',0
    Buff         BYTE   50  dup (0)

.CODE

START:

    ; sprintf expects a REAL8, so convert
    finit
    fld  FloatNumber
    fstp DoubleNumber
    fwait
   
    push DWORD PTR [DoubleNumber+4]
    push DWORD PTR [DoubleNumber+0]
    push OFFSET StrFormat
    push OFFSET Buff
    call crt_sprintf
    add esp, 16

    push MB_OK
    push OFFSET Caption
    push OFFSET Buff
    push 0
    call MessageBox

    push 0
    call ExitProcess
   
END START

seymour_glass

wouldnt exitProcess have to be defined up top?  or is my outdated asm just not like that?

Mark Jones

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

LechooY

Thanks All!

This forum is great  :U

MichaelW

Small correction, ExitProcess is defined in kernel32.inc as:

ExitProcess PROTO :DWORD
eschew obfuscation

Mark Jones

Quote from: MichaelW on April 27, 2006, 10:33:07 PM
Small correction, ExitProcess is defined in kernel32.inc as:

ExitProcess PROTO :DWORD

Oh whoops, yes you're right. :red I did a quick search using my Library Search tool and it showed windows.inc as having the text "ExitProcess" in it, but indeed the function is only defined in kernel32.inc.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08