flat assembler
Message board for the users of flat assembler.
Index
> Linux > How to print a float in 64-bit program? |
Author |
|
HaHaAnonymous 22 Jan 2014, 16:09
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 18:27; edited 2 times in total |
|||
22 Jan 2014, 16:09 |
|
Melissa 22 Jan 2014, 16:10
Stack has to be 16 byte aligned for printf (when float arguments
are used)... Code: format elf64 executable 3 include 'import64.inc' interpreter '/lib64/ld-linux-x86-64.so.2' needed 'libc.so.6' import printf,exit segment readable executable entry start start: push rbp mov rbp,rsp sub rsp,0x8 ; stack has to be 16 byte aligned for printf mov eax,0x3f8ccccd ; = 1.1 mov DWORD [rbp-0x4],eax movss xmm0,DWORD [rbp-0x4] cvtps2pd xmm0,xmm0 mov eax,pf mov rdi,rax mov eax,1 ; eax -> number of float arguments call [printf] xor edi,edi call [exit] segment readable writeable pf db '%lf',0xa,0 |
|||
22 Jan 2014, 16:10 |
|
revolution 22 Jan 2014, 16:21
You can also use the 1.1 value directly:
Code: mov eax,1.1 |
|||
22 Jan 2014, 16:21 |
|
HaHaAnonymous 22 Jan 2014, 16:24
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 18:27; edited 1 time in total |
|||
22 Jan 2014, 16:24 |
|
revolution 22 Jan 2014, 16:31
HaHaAnonymous wrote: Maybe he is just paranoid like me and want to be extremely sure the value is correct. |
|||
22 Jan 2014, 16:31 |
|
HaHaAnonymous 22 Jan 2014, 16:52
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 18:26; edited 1 time in total |
|||
22 Jan 2014, 16:52 |
|
gAr 22 Jan 2014, 16:52
Thanks everybody for your replies, both of the solutions worked great.
So, alignment was the problem. I was going mad about why the very same code by the compiler wasn't working with fasm! Quote:
I just translated the code to fasm as I said, wasn't sure whether 1.1 would work. Thanks for letting me know! |
|||
22 Jan 2014, 16:52 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.