X87 FPOP and FCOM Instructions - How Does It Work?

I was tasked with writing a simple application in mixed C / ASM that should use a mathematical coprocessor.

Here a cylinder functions (float x, float y, float z), which returns 1 if this point is inside the cylinder (the cylinder has a base at x = 0, y = 0, radius = 5 and height = 10) and 0 if it not this way.

So it looks simple. Check if z is within <0.10>, and then check if x ^ 2 + y ^ 2 <25.

But my knowledge of x87 is zero.

Everything that I wrote there.

_cylinder PROC

push ebp
mov ebp, esp
sub esp,8 ; I can't use .data in the application, so I reserve some space on the stack for numbers 10 and 25
mov [esp],10
mov [esp+4],25

finit
fldz
fld [ebp+8]

    ;here i get stuck 

add esp, 8
pop ebp
_cylinder ENDP

So I'm stuck. So, I'm trying to find what instructions I can use in the application. And I'm stuck there, because every list of textbooks / instructions that I find on the web is written so poorly that I can't understand anything.

, , - ? ? 80- 32- ( , ) : FCOM (FCOMP -)? , ( st0 st1 st1 st0?), , /?

!

+5
1

- . FPU, - , ​​CPU, , , .

, , , z >= 0.0 :

fldz
fcomp z
fnstsw ax
test ah, 041h; I *think* I've got the right flags there...
jp good
+5

All Articles