gpt4 book ai didi

assembly - 释放 x87 FPU 堆栈 (ia32)

转载 作者:行者123 更新时间:2023-12-02 20:16:18 24 4
gpt4 key购买 nike

在我的大学里,我们刚刚了解到 IA32 x87 FPU。但我们不知道如何清除 FPU 堆栈中不再需要的元素。

假设我们正在执行一个简单的计算,例如 (5.6 * 2.4) + (3.9 * 10.3)。

.data
value1: .float 5.6
value2: .float 2.4
value3: .float 3.8
value4: .float 10.3

output: .string "The result is: %f\n"

.text
.global main

main:
fld value1 # Load / Push 5.6 into FPU
fmul value2 # Multiply FPU's top (5.6) with 2.4
fld value3 # Load / Push 3.8 into FPU
fmul value4 # Multiply the top element of the FPU's Stacks with 10.3
fadd %st(1) # Add the value under the top element to the top elements value

.output:
# Reserve memory for a float (64 Bit)
subl $8, %esp
# Pop the FPU's top element to the program's Stack
fstpl (%esp)
# Push the string to the stack
pushl $output
# Call printf function with the both parameters above
call printf
# Free the programs stack from the parameters for printf
addl $12, %esp

.exit:
movl $1, %eax
int $0x80

问题是:弹出保存计算结果的 FPU 顶部元素后。如何从保存 (5.6*2.4) 结果的现在剩余的新顶部元素中释放 FPU 堆栈。

我能想到的唯一方法是释放更多程序堆栈并从 FPU 堆栈中弹出元素,直到删除所有不再需要的元素。

有没有办法直接操作顶部指针?

最佳答案

要实现堆栈上没有任何垃圾,您需要使用 FADDPFMULP 以及类似的指令。

关于assembly - 释放 x87 FPU 堆栈 (ia32),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19892215/

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