The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: LechooY on April 27, 2006, 02:51:52 PM

Title: wsprintf float error :/
Post by: LechooY on April 27, 2006, 02:51:52 PM

.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 :)
Title: Re: wsprintf float error :/
Post by: Ratch on April 27, 2006, 03:20:23 PM
LechooY ,

     It would be nice if you told us what the problem or error is.  Ratch
Title: Re: wsprintf float error :/
Post by: arafel on April 27, 2006, 03:46:21 PM
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.
Title: Re: wsprintf float error :/
Post by: LechooY on April 27, 2006, 05:26:30 PM
Thanks arafel  :U
Title: Re: wsprintf float error :/
Post by: GregL on April 27, 2006, 06:29:05 PM
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
Title: Re: wsprintf float error :/
Post by: seymour_glass on April 27, 2006, 07:14:17 PM
wouldnt exitProcess have to be defined up top?  or is my outdated asm just not like that?
Title: Re: wsprintf float error :/
Post by: Mark Jones on April 27, 2006, 07:46:52 PM
ExitProcess should be defined in windows.inc.
Title: Re: wsprintf float error :/
Post by: LechooY on April 27, 2006, 09:56:15 PM
Thanks All!

This forum is great  :U
Title: Re: wsprintf float error :/
Post by: MichaelW on April 27, 2006, 10:33:07 PM
Small correction, ExitProcess is defined in kernel32.inc as:

ExitProcess PROTO :DWORD
Title: Re: wsprintf float error :/
Post by: Mark Jones on April 29, 2006, 07:12:20 PM
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 (http://www.masmforum.com/simple/index.php?topic=3863.0) and it showed windows.inc as having the text "ExitProcess" in it, but indeed the function is only defined in kernel32.inc.