我不知道问题是什么,因为这对于 SIN 和 COS 非常有效。对于 TAN,它返回 0.0000 表示 50.0 弧度。但如果我启用注释行,它就会按预期工作。这很奇怪,因为 TAN 应该在 XMM0 中返回 double 值,而不是 RAX。
;./fasm testing.asm
;gcc -s testing.o -o testing -lm
format elf64
extrn printf
extrn tan
section '.data' writeable align 16
rad dq 50.0
fmt db "%.5lf",0ah,0
section '.text' executable align 16
public main
main:
push rbp
mov rbp,rsp
pxor xmm0,xmm0
movq xmm0,[rad]
call tan
;movq rax,xmm0 ;works if I enable this. but SIN and COS don't need this
mov rdi,fmt
call printf
mov rsp,rbp
pop rbp
ret
这可能是什么问题?
最佳答案
在 x86-64 汇编中调用任何函数时,AL
必须包含所使用的寄存器数量。这是惯例,你无法回避。
Variable-argument subroutines require a value in
RAX
for the number of vector registers used.
RAX
is a temporary register; with variable arguments passes information about the number of vector registers used; 1st return register.
您可以咨询System V Application Binary Interface ,章节3.2.3 参数传递。
因此,您需要指定在rax
中使用的参数数量。
movq rax, 1
应该足够了。
关于gcc - FASM:从 GCC 调用切线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30693007/