gcc - FASM:从 GCC 调用切线

标签 gcc assembly fasm

我不知道问题是什么,因为这对于 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/

相关文章:

c++ - Eclipse CDT 控制台输出未显示在带有路径的调试中,也未显示在没有路径的运行中

linux - 我怎样才能更改 gcc 在链接/bin/ld 时使用的库?

assembly - Mips 组装有帮助吗?特别是高/低

assembly - `Skipcond` 在 MARIE 汇编语言中是如何工作的?

assembly - 在堆栈中创建命名变量

assembly - 将 FASM 中的 80 位 float 与给定精度进行比较

c - 如何让我的程序使用 BSD 打印其 github 版本号?

assembly - 内部搬迁未解决

assembly - 无法在 FASM 语法中添加部分

c - ARM GCC 内联汇编