gpt4 book ai didi

从程序集中调用 expf

转载 作者:行者123 更新时间:2023-11-30 19:34:05 25 4
gpt4 key购买 nike

我有一个小问题。我有一个 C 文件和一个汇编文件。 C 代码如下:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <xmmintrin.h>

void powAss();

int main(int argc,char **argv){
powAss();
printf("Finito\n");
}

其中 powAss() 函数在后续汇编文件中定义:

global powAss

section .data

section .text
extern expf

powAss:
push ebp ; salva il Base Pointer
mov ebp, esp ;il Base Pointer punta al Record di Attivazione corrente
push ebx ; salva i registri da preservare
push esi
push edi
mov ecx,0
push ecx
call expf
pop edi ; ripristina i registri da preservare
pop esi
pop ebx
mov esp, ebp ; ripristina lo Stack Pointer
pop ebp ; ripristina il Base Pointer
ret

我想将 ecx 寄存器中的值写入 expf 函数。现在的问题是:如何在汇编中获取 expf 函数的结果?

最佳答案

浮点返回值在 FPU 堆栈顶部传递 (st0)。

您需要像这样定义powAss

float powAss();

然后照常使用它。

这是因为您的程序集正在调用 expf,然后它将其返回值放入 st0,然后您直到函数结束才触及它,并且编译器将假定 st0 具有函数的返回值。

关于从程序集中调用 expf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44344007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com