Discussion:
sprintf in assembler ??
(too old to reply)
Erdemal
2005-12-03 12:49:58 UTC
Permalink
Under Windows in assembler, I would like to display *floating point*
values. So, I need to convert the dword, qword and tword to strings.
I tried many of the sprintf, snprintf, wsprintf, ... from Msvcrt.dll
and got no significant :) result.

My request is: help !

Thanks,

Jacques
robertwessel2@yahoo.com
2005-12-06 00:39:12 UTC
Permalink
Post by Erdemal
Under Windows in assembler, I would like to display *floating point*
values. So, I need to convert the dword, qword and tword to strings.
I tried many of the sprintf, snprintf, wsprintf, ... from Msvcrt.dll
and got no significant :) result.
First, the Windows wsprintf doesn't support floats at all.

And if you're not getting the right result from the CRT, you're
probably messing up the parameter passing conventions. Remember that
you'll need to use _cdecl, and you'll need to pass only doubles (long
doubles being basically unsupported by MS, and varargs calling
convention will require expanding singles to doubles).
randyhyde@earthlink.net
2005-12-07 04:40:56 UTC
Permalink
Post by Erdemal
Under Windows in assembler, I would like to display *floating point*
values. So, I need to convert the dword, qword and tword to strings.
I tried many of the sprintf, snprintf, wsprintf, ... from Msvcrt.dll
and got no significant :) result.
Check out the HLA Standard Library at http://webster.cs.ucr.edu.
It contains hundreds of routines that do things like what you're
requesting.
Cheers,
Randy Hyde
Erdemal
2005-12-07 21:14:58 UTC
Permalink
Post by ***@earthlink.net
Post by Erdemal
Under Windows in assembler, I would like to display *floating point*
values. So, I need to convert the dword, qword and tword to strings.
I tried many of the sprintf, snprintf, wsprintf, ... from Msvcrt.dll
and got no significant :) result.
Check out the HLA Standard Library at http://webster.cs.ucr.edu.
It contains hundreds of routines that do things like what you're
requesting.
Cheers,
Randy Hyde
I dreamt of an example :(.

Thanks to both of you,

Jacques
Tim Roberts
2005-12-08 06:09:18 UTC
Permalink
Post by Erdemal
Post by ***@earthlink.net
Post by Erdemal
Under Windows in assembler, I would like to display *floating point*
values. So, I need to convert the dword, qword and tword to strings.
I tried many of the sprintf, snprintf, wsprintf, ... from Msvcrt.dll
and got no significant :) result.
Check out the HLA Standard Library at http://webster.cs.ucr.edu.
It contains hundreds of routines that do things like what you're
requesting.
Cheers,
Randy Hyde
I dreamt of an example :(.
After that help, we figured you could do the example yourself. This
displays 1.5:

C:\Tmp>type x.asm
.586
.model flat, stdcall
.data
quotient qword 0
buffer byte 80 dup (0)
format byte 'Quotient: %f',0
titler byte 'Divide',0
.code
ExitProcess PROTO :DWORD
MessageBoxA PROTO :DWORD, :DWORD, :DWORD, :DWORD
extern C sprintf: proc

_Start proc public

push 3
fild dword ptr [esp]
mov dword ptr [esp], 2
fild dword ptr [esp]
add esp, 4
fdivp st(1),st(0)
fstp qword ptr [quotient]

push dword ptr [quotient+4]
push dword ptr [quotient]
push offset format
push offset buffer
call sprintf
add esp, 12

invoke MessageBoxA, 0, offset buffer, offset titler, 0
invoke ExitProcess, 0

_Start endp
end _Start


C:\Tmp>ml /c /coff x.asm
Microsoft (R) Macro Assembler Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: x.asm

C:\Tmp>link /out:x.exe /subsystem:console x.obj msvcrt.lib kernel32.lib
user32.lib
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Tmp>x.exe

C:\Tmp>
--
- Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Erdemal
2005-12-08 14:55:09 UTC
Permalink
Post by Tim Roberts
Post by Erdemal
Post by ***@earthlink.net
Post by Erdemal
Under Windows in assembler, I would like to display *floating point*
values. So, I need to convert the dword, qword and tword to strings.
I tried many of the sprintf, snprintf, wsprintf, ... from Msvcrt.dll
and got no significant :) result.
Check out the HLA Standard Library at http://webster.cs.ucr.edu.
It contains hundreds of routines that do things like what you're
requesting.
Cheers,
Randy Hyde
I dreamt of an example :(.
After that help, we figured you could do the example yourself. This
Wonderfull, it works. Thank you very much.

You can call me a nut or an idiot but not a lazy, I spent hours
on this :). There are very few/no things out there on that subject.

Thanks again,

Jacques

Continue reading on narkive:
Loading...