如何在装配中比较2个浮点数
我,在装配方面完全是新手。 我想比较两个变量(浮点数)并正确跳转到正确的函数; 这是一场乒乓球比赛 它是用 FASM 编写的,
;The right pad
P0x dd 0.9 ;
P0y dd 0.05 ;
P1x dd 0.95 ;
P1y dd -0.25 ;
;The left pad
P0x2 dd -0.9
P0y2 dd 0.05
P1x2 dd -0.95
P1y2 dd - 0.25
B0x GLfloat 0.01 ; Its the ball coordinate
...
BvelX GLfloat 0.02 ;Its the velocity that the ball move in x
...
我希望:如果球位置与垫位置相同或更大,则反转速度。 我所做的:
;right
fld [B0x]
fld [P0x]
fcomip st1
jge .changexEsq
;left
fld [B0x]
fld [P0x2]
fcomip st1
jle .changexDir
;Up
fld [B0y]
fld [TelaComecoY]
fcomip st1
jge .changeyBaixo
;Down
fld [B0y]
fld [TelaFimY]
fcomip st1
jge .changeyBaixo
....
.changexEsq:
mov edi,-0.02
mov [BvelX],edi
jmp .main
ret
.changexDir:
mov edi, 0.02
mov [BvelX],edi
jmp .main
ret
.changeyBaixo:
mov edi,-0.02
mov [BvelY],edi
jmp .main
ret
.changeyCima:
mov edi,-0.02
mov [BvelY],edi
jmp .main
ret
但是比较什么也没做!我怎样才能比较这些变量并正确跳转?
i´, completely novice in assembly.
I want to compare two variables (float) and jump correctly to the right function;
Its a Pong game
Its written in FASM
;The right pad
P0x dd 0.9 ;
P0y dd 0.05 ;
P1x dd 0.95 ;
P1y dd -0.25 ;
;The left pad
P0x2 dd -0.9
P0y2 dd 0.05
P1x2 dd -0.95
P1y2 dd - 0.25
B0x GLfloat 0.01 ; Its the ball coordinate
...
BvelX GLfloat 0.02 ;Its the velocity that the ball move in x
...
I want that: if the ball position is the same or more then the Pad position, then invert the velocity.
What i do:
;right
fld [B0x]
fld [P0x]
fcomip st1
jge .changexEsq
;left
fld [B0x]
fld [P0x2]
fcomip st1
jle .changexDir
;Up
fld [B0y]
fld [TelaComecoY]
fcomip st1
jge .changeyBaixo
;Down
fld [B0y]
fld [TelaFimY]
fcomip st1
jge .changeyBaixo
....
.changexEsq:
mov edi,-0.02
mov [BvelX],edi
jmp .main
ret
.changexDir:
mov edi, 0.02
mov [BvelX],edi
jmp .main
ret
.changeyBaixo:
mov edi,-0.02
mov [BvelY],edi
jmp .main
ret
.changeyCima:
mov edi,-0.02
mov [BvelY],edi
jmp .main
ret
But the comparation is doing nothing ! How could i compare those variables and jump correctly ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FCOM
和公司(FCOMP、FCOMPP、FICOM、FICOMP)将结果放入浮点状态字中,而不放入主 CPU 标志寄存器中。您可以使用fstsw
将浮点状态字存储在您可以获取并对其内容进行操作的地方(例如,要存储到AX,您可以使用FSTSW AX
)。请注意,这有点迂回。在某些情况下,您可能需要考虑将数字视为整数 - IEEE 754 经过精心设计,以便排序的整数比较大部分会产生浮点数的正确结果。
FCOM
and company (FCOMP, FCOMPP, FICOM, FICOMP) put results in the floating point status word, not in the main CPU flags register. You can usefstsw
to store the floating point status word somewhere you can get at it and act on its contents (e.g., to store to AX, you useFSTSW AX
).Note that this is somewhat roundabout. In some cases, you may want to consider treating the numbers as if they were integers -- IEEE 754 was carefully designed so that integer comparisons for ordering mostly yield correct results for floating point numbers.
我很确定您在使用 FCOMIP 时需要
JAE
/JBE
,而不是JLE
/JGE
将浮点数与 EFLAGS(ZF、PF 和 CF)进行比较。I'm pretty sure you want
JAE
/JBE
, notJLE
/JGE
, when usingFCOMIP
to compare the floats with EFLAGS (ZF, PF and CF).