gpt4 book ai didi

c++ - 组装:JA 和 JB 工作不正确

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:25:11 25 4
gpt4 key购买 nike

由于我的主要操作系统是linux并且在visual studio上有项目,所以我决定使用在线编译器来实现它。我找到了 this这是许多人建议的。所以这是我的代码:

#include <iostream>

using namespace std;
int main(void) {
float a = 1;
float b = 20.2;
float res = 0;
float res1 = 0;

_asm {

FLD a
FCOM b
JA midi
JMP modi

midi:
FST res
JMP OUT

modi:
FST res1
JMP OUT


}
OUT:
cout << "res = " << res << endl;
cout << "res1 = " << res1 << endl;
return 0;
}

我的目标很简单,如果 a 大于 b,则将 a 放入 res,否则放入res1。但似乎无论我在变量 a 中有什么,它总是跳到 midi 上,结果总是 res = whatever is in a。希望你能帮忙。对不起,如果我的问题很愚蠢,我才刚刚开始学习组装。谢谢 :)

附言
JB 也是如此,但恰恰相反。它总是打印 res1 = whatever is in b

最佳答案

来自 this page :

FCOM compares ST0 with the given operand, and sets the FPU flags accordingly.

但是您的 JA midi 正在测试 CPU 标志。

继续:

FCOMI and FCOMIP work like the corresponding forms of FCOM and FCOMP, but write their results directly to the CPU flags register rather than the FPU status word, so they can be immediately followed by conditional jump or conditional move instructions.

关于c++ - 组装:JA 和 JB 工作不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41334026/

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