what am I doing wrong?
First : make sure that you are using the correct calling convention (stack, registers, left to right, right to left, etc.). If your program really prints a floating-point number, although this is not the one you need, then at least the format string is transmitted correctly (or you are very lucky, and printf found the address of the format string in the right place, even if you donβt indicated his address).
Second : the number you are trying to print ... is it floating or double? rs defined as the value of the square (64 bits), but floats are 32 bits. So, if the first point was checked, and thatβs fine, I suggest you use "%lf" as the format instead of "%f" .
By the way: why do you put RAX = 0 ? What does this mean for calling printf ?
UPDATE: This may help you. Disassembling a stupid program ( fc ):
#include <stdio.h> main() { float x; x = 1.6; printf ("%f\n", x); }
$ gcc -c -S fc
$ less fs
.file "fc" .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
source share