首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >释放x87 FPU堆栈(ia32)

释放x87 FPU堆栈(ia32)
EN

Stack Overflow用户
提问于 2013-11-10 16:39:08
回答 4查看 2.9K关注 0票数 9

在我的大学里,我们刚被介绍到IA32 x87 FPU。但是我们没有被告知如何清除FPU-堆栈中不再需要的元素。

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

代码语言:javascript
复制
.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的顶部元素后的。如何将FPU的堆栈从保存(5.6*2.4)的结果的新顶部元素中释放出来。

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

有直接操作顶部指针的方法吗?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-11-10 16:59:07

要做到这一点,您需要使用FADDPFMULP以及类似的说明。

票数 7
EN

Stack Overflow用户

发布于 2015-11-06 21:18:15

如果像我这样的人来这里寻找清理堆栈的最佳方法,我发现这个简单的解决方案是最好的:

代码语言:javascript
复制
fstp ST(0) ; just pops top of the stack
票数 7
EN

Stack Overflow用户

发布于 2017-06-24 16:12:29

emms也可以用来标记f.p的每个成员。一堆免费的。这与finit相比有一个优点,即它不改变f.p中的任何标志。控件或状态词(异常掩码等)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19892215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档