装配:JA 和 JB 工作不正常 [英] Assembly: JA and JB work incorrectly
问题描述
由于我的主要操作系统是 linux 并且在 Visual Studio 上有项目,所以我决定使用在线编译器来实现它.我找到了许多人建议的 this.所以这是我的代码:
Since my main OS is linux and have project on visual studio, I decided to use online compilers to achieve it. I found this which was suggested by many. So here is my code:
#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 = what is in a
.希望你能帮忙.对不起,如果我的问题很愚蠢,我刚刚开始学习汇编.谢谢 :)
附注JB
也是一样,但正好相反.它总是打印 res1 = what is in b
.
My goal is simple, if a
is greater that b
than put a
in res
, otherwise in res1
. But it seems like whatever I have in variable a
it always jumps on midi
and result is always res = whatever is in a
. Hope you can help. Sorry if my questions is silly, I've just started to learn assembly. thanks :)
P.S
same thing goes with JB
but the opposite. It always prints res1 = whatever is in b
.
推荐答案
来自 本页:
FCOM 将 ST0 与给定的操作数进行比较,并设置 FPU 标志相应地.
FCOM compares ST0 with the given operand, and sets the FPU flags accordingly.
但是您的 JA midi
正在测试 CPU 标志.
But your JA midi
is testing the CPU flags.
继续:
FCOMI 和 FCOMIP 的工作方式类似于 FCOM 和 FCOMP 的相应形式,但将结果直接写入 CPU 标志寄存器而不是比 FPU 状态字,所以它们可以紧跟条件跳转或条件移动指令.
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.
这篇关于装配:JA 和 JB 工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!