我试图简单地读取一个浮点值,并使用汇编x8664打印它。所以,当我试图打印它时,我用作c函数scanf缓冲区的可变价格的值不会改变。
它会打印最初设置的值,所以在下面代码的情况下,它会打印0.0,所以scanf函数不会正确地更改价格值。
为了生成可执行文件,我使用以下命令
nasm -f elf64 test.asm && gcc -no-pie test.o -o test
。
我做错了什么?
section .data
price dq 0.0
fmt db "%.1f", 0
section .text
global main
extern printf, scanf
main:
push rbp
mov rbp, rsp
mov rdi, fmt ;scanf first arg, format string
mov rsi, price ;scanf second argument, this variable is supposed to change
mov rax, 0
call scanf
movq xmm0, [price] ;in float point mode xmm0 holds the value to be printed
mov rdi, fmt
mov rax, 1 ;rax has to be set 1 to float point mode
call printf
leave
ret