Reputation: 17
The code below always returns 0.0000000. I don't know why it is doing this.
here is the code
SECTION .data
flt1: dq 5.327
formatin: db "%f", 0
SECTION .bss
SECTION .text
global _main
extern _scanf
extern _printf
_main:
push ebp
mov ebp, esp
push dword[flt1]
push formatin
call _printf
add esp, 8
mov esp, ebp
pop ebp
ret
can you help me fix this problem so I can display numbers with a decimal point
Upvotes: 1
Views: 2312
Reputation: 480
In c function calls, float
is promoted to double
. You also declared flt1
as dq
, a double. So regardless, you need to pass a 64-bit type. If you are on a 64-bit system, simply use push qword[flt1]
. If you are on a 32-bit system, you will have to instead use fld
. Because your parameter sizes are different, you will then have to use add esp, 12
rather than add esp, 8
Upvotes: 1