Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>what am I doing wrong?</p> </blockquote> <p><strong>First</strong>: make sure you are using the right calling convention (stack, registers, left to right, right to left, etc.). If your program indeed prints a floating point number, although it is not the one you required, then at least the format string is being passed correctly (or you are having a lot of luck and <code>printf</code> found the address of the format string at the right place even if you didn't put its address there).</p> <p><strong>Second</strong>: the number you are trying to print... is it a float or a double? <code>rs</code> is defined to hold a quadword value (64 bits), but floats are 32 bits. So, if the first point has been checked and it's ok, I suggest you to use <code>"%lf"</code> as format, instead of <code>"%f"</code>.</p> <p>BTW: why do you put <code>RAX = 0</code>? What does it mean regarding the call to <code>printf</code>?</p> <p>UPDATE: This may help you. A disassembly of a silly program (<code>f.c</code>):</p> <pre><code>#include &lt;stdio.h&gt; main() { float x; x = 1.6; printf ("%f\n", x); } </code></pre> <p><code>$ gcc -c -S f.c</code></p> <p><code>$ less f.s</code></p> <pre><code> .file "f.c" .section .rodata .LC1: .string "%f\n" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 movq %rsp, %rbp .cfi_offset 6, -16 .cfi_def_cfa_register 6 subq $16, %rsp movl $0x3fcccccd, %eax movl %eax, -4(%rbp) movss -4(%rbp), %xmm0 cvtps2pd %xmm0, %xmm0 movl $.LC1, %eax movq %rax, %rdi movl $1, %eax call printf leave </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload