0
我想了解如何使用xmm寄存器比较两个浮点数(32位)。 为了测试我用C编写的代码(它调用了汇编代码):xmm,cmp两个32位浮点数
#include "stdio.h"
extern int compare();
int main()
{
printf("Result: %d\n", compare());
return 0;
}
这里是国内组装,我想测试。如果B <℃,在这种情况下,它确实 和代码应该返回1,但它返回0:
section .data
a: dd 5.5555
b: dd 1.1111
c: dd 5.5555
section .text
global compare
compare:
; -------------------------------------------
; Entrace sequence
; -------------------------------------------
push ebp ; save base pointer
mov ebp, esp ; point to current stack frame
push ebx ; save general registers
push ecx
push edx
push esi
push edi
movss xmm0, [b]
movss xmm1, [c]
comiss xmm0, xmm1
jl change
mov eax, 0
jmp end
change:
mov eax, 1
end:
; ------------------------------------------
; Exit sequence
; ------------------------------------------
pop edi
pop esi
pop edx
pop ecx
pop ebx
mov esp, ebp
pop ebp
ret
如果我尝试JG返回1使用,但我认为它应该是相反的,XMM0小于XMM1。
如果我写
movss xmm0, [b]
comiss xmm0, [b]
je change
它返回1,符合市场预期。 有人知道它为什么这样表现吗?也许我没有使用正确的跳转说明。
JE和JNE应该工作得过.. ..? – AR89
@ AR89是。 ZF标志在相等时设置。 –