flat assembler
Message board for the users of flat assembler.
Index
> Main > printf ( "%f : %f\n", double_var1, double_var2) |
Author |
|
Picnic 05 Oct 2009, 20:26
Hi paule32, welcome on board.
This works on my system. Code: format PE console entry start include 'include\win32a.inc' section '.code' code readable executable start: ;push ebp ;mov ebp, esp ;fld qword [LC0] ;fld qword [LC1] ;faddp ;fstp qword [_var1] ;fld qword [LC2] ;fld qword [_var1] ;faddp ;fstp qword [_var2] fld qword [LC0] fadd qword [LC1] fadd qword [LC2] fstp qword [_var1] ;ccall [printf], user_str cinvoke printf, user_str, hello_msg, dword [_var1], dword [_var1+4] invoke ExitProcess, 0 ;ccall [printf], hello_msg ;ccall [getchar] ;stdcall [ExitProcess],0 ;leave ;ret section '.data' data readable writeable hello_msg db 'Hello, world!',0 LC0 dq 2.1000 LC1 dq 3.0500 LC2 dq 2.5000 _var1 dq 0.0 _var2 dq 0.0 user_str db "%s --> %.5f",13,10,0 section '.idata' import data readable library kernel,'kernel32.dll',\ msvcrt,'msvcrt.dll',\ user,'USER32.DLL',\ kbase,'kbase.dll' import kernel,\ ExitProcess,'ExitProcess' import msvcrt,\ printf,'printf',\ getchar,'_fgetchar' import user,\ wsprintf,'wsprintfA' |
|||
05 Oct 2009, 20:26 |
|
paule32 05 Oct 2009, 21:28
Hello Picnic!
Thanks for the fast reply and working application. |
|||
05 Oct 2009, 21:28 |
|
Picnic 30 Jan 2010, 12:22
Now it's my turn to ask.
I need to convert a buffer to a float, i tried msvcrt library fucntion sscanf with no success. Test program output is 0.0, it should be 12345.67 Code: format PE CONSOLE 4.0 include 'win32axp.inc' .data fmt db '%f',0 buffer db '12345.67',0 f dq 0.0 .code entry $ push f push fmt push buffer call [sscanf] add esp, 12 push DWORD [f+4] push DWORD [f] push fmt call [printf] add esp, 12 ret section '.idata' import data readable writeable library msvcrt, 'msvcrt.dll' import msvcrt,\ printf, 'printf',\ sscanf, 'sscanf' |
|||
30 Jan 2010, 12:22 |
|
revolution 30 Jan 2010, 13:32
It works for me if I convert the value to a double.
Code: format PE CONSOLE 4.0 include 'win32axp.inc' .data fmt db '%f',0 buffer db '12345.67',0 f dq 0.0 .code entry $ push f push fmt push buffer call [sscanf] add esp, 12 fld dword[f] fst qword[f] push DWORD [f+4] push DWORD [f] push fmt call [printf] add esp, 12 ret section '.idata' import data readable writeable library msvcrt, 'msvcrt.dll' import msvcrt,\ printf, 'printf',\ sscanf, 'sscanf' |
|||
30 Jan 2010, 13:32 |
|
baldr 30 Jan 2010, 13:32
Picnic,
For scanf "%f" format spec corresponds to float * argument. double * requires "%lf". |
|||
30 Jan 2010, 13:32 |
|
MHajduk 30 Jan 2010, 13:50
Hi Picnic!
Try this: Code: format PE CONSOLE 4.0 include 'win32axp.inc' .data InputFmt db '%lf', 0 OutputFmt db 'Scanned number = %f', 0 Buffer db '12345.67', 0 f dq 0.0 .code entry $ cinvoke sscanf, Buffer, InputFmt, f cinvoke printf, OutputFmt, dword [f], dword [f+4] cinvoke getchar ret section '.idata' import data readable writeable library msvcrt, 'msvcrt.dll' import msvcrt,\ getchar, 'getchar',\ printf, 'printf',\ sscanf, 'sscanf' |
|||
30 Jan 2010, 13:50 |
|
Picnic 30 Jan 2010, 14:17
Thanks for the feedback guys
|
|||
30 Jan 2010, 14:17 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.