如何在装配中比较2个浮点数

发布于 2024-11-06 05:52:18 字数 987 浏览 0 评论 0原文

我,在装配方面完全是新手。 我想比较两个变量(浮点数)并正确跳转到正确的函数; 这是一场乒乓球比赛 它是用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼波传意 2024-11-13 05:52:18

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 use fstsw 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 use FSTSW 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.

◇流星雨 2024-11-13 05:52:18

我很确定您在使用 FCOMIP 时需要 JAE/JBE,而不是 JLE/JGE 将浮点数与 EFLAGS(ZF、PF 和 CF)进行比较。

I'm pretty sure you want JAE/JBE, not JLE/JGE, when using FCOMIP to compare the floats with EFLAGS (ZF, PF and CF).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文