flat assembler
Message board for the users of flat assembler.
Index
> Windows > How to print a float value? |
Author |
|
Tommy 30 Jun 2005, 16:31
change dq 6.6 (qword) to dd 6.6 (dword)
|
|||
30 Jun 2005, 16:31 |
|
MikeHart 30 Jun 2005, 18:11
Nope, that didn't help, still get that huge number that has nothing to do with 6.6
|
|||
30 Jun 2005, 18:11 |
|
Tomasz Grysztar 30 Jun 2005, 18:14
It should be qword, but you didn't pass the whole quad word to the "printf", only the lower half. To pass the whole quad word, do it like:
Code: cinvoke printf,szEnv, string, dword [valu], dword [valu+4] |
|||
30 Jun 2005, 18:14 |
|
MikeHart 30 Jun 2005, 18:25
Thanks Tomasz very much. That worked. I have to learn a lot but I wanna thank you for building such a great assembler!!!
Michael Hartlef |
|||
30 Jun 2005, 18:25 |
|
MikeHart 24 Dec 2006, 19:50
Ok, how do I display a float value that is stored inside EAX?
Code: format PE CONSOLE 4.0 entry start Include 'win32a.inc' section ".code" code readable writeable executable string db "Float value:",0 szEnv db "%s %4.2f",13,10,0 valu dq 6.6 start: cinvoke printf,szEnv, string, dword [valu], dword [valu+4] mov eax , dword [valu] cinvoke printf,szEnv, string, eax cinvoke getchar invoke ExitProcess,0 section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ msvcrt,'msvcrt.dll' import kernel32,\ ExitProcess,'ExitProcess' import msvcrt,\ getchar,'getchar',\ printf,'printf' |
|||
24 Dec 2006, 19:50 |
|
gunblade 25 Dec 2006, 11:39
You'll have to use 2 registers:
Code: mov eax , dword [valu] mov ebx, dword [valu+4] cinvoke printf,szEnv, string, eax, ebx Otherwise you have the same problem as before, where you were only passing 4 of the 8 bytes in the quadword. |
|||
25 Dec 2006, 11:39 |
|
MikeHart 25 Dec 2006, 17:39
Thank you gunblade and merry chrismas to you!
|
|||
25 Dec 2006, 17:39 |
|
Garthower 07 Feb 2007, 20:51
And how about manual converting float number to string? Somebody has examples? Or ideas?
|
|||
07 Feb 2007, 20:51 |
|
vid 07 Feb 2007, 21:26
tomasz told to work on it for FASMLIB .... no idea how far it is
|
|||
07 Feb 2007, 21:26 |
|
cod3b453 07 Feb 2007, 21:56
Garthower wrote: And how about manual converting float number to string? Somebody has examples? Or ideas? This is something I'm still trying to finish, but it goes like this: (If anything looks wrong please tell me ) Code: ;Let D = double (qword) ; ;1) Is D < 0 ? Yes: bMinus = True ;2) D = |D| (Abs) ;3) E10 = Floor(Log10(D)) ;4) Is E10 < 0: Yes: bEMinus = True ;5) P10 = 10 ^ -E10 ;6) E10 = |E10| (Abs) ;7) D2 = D × P10 (Exponent = 0) ; rbx = D2 ;9) rbx --> dst ASCII fstp qword [value] ;-Part 8 mov rbx,[value] ;/ mov rsi,[Dst] @@: mov rax,rbx mov rcx,0x199999999999999A mul rcx ; rdx = rax / 10 mov rax,rbx ; restore rax mov ebx,rdx ; Required for loop mov rcx,rdx shl rcx,1 ;\ shl rdx,3 ; rdx = rdx * 10 add rdx,rcx ;/ sub rax,rdx ; rax = last decimal digit value add al,'0' ; ASCII digit base mov [rsi],al inc rsi jif rbx,ne,0,@b ; Done? ; Swap digits back mov rax,rsi mov rdi,[dst] sub rax,rdi mov rcx,rax shr rax,1 dec rcx @@: dec rsi mov dh,[rsi] mov dl,[rdi] mov [rsi],dl mov [rdi],dh inc rdi dec rax jif rax,ne,0,@b ;10) Subtract rcx from E10 ;11) Do same as 8 & 9 for E10 into dstE ;12) If bMinus = True print "-" ; print dst ; print "E" ; If bEMinus = True print "-" ; print dstE Maybe I should try finishing it and let a 64bitter try it |
|||
07 Feb 2007, 21:56 |
|
Reverend 08 Feb 2007, 20:26
http://board.flatassembler.net/topic.php?t=4377&start=53
There are my converting routines. Just convert float value and save it as a string in buffer, then display it. |
|||
08 Feb 2007, 20:26 |
|
3D_FASM 25 May 2023, 13:10
Or use double prefix
Code: val dq 1234.56769 ... invoke sprintf, message, format, double [var] https://board.flatassembler.net/topic.php?t=11513 |
|||
25 May 2023, 13:10 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.