Page 1 of 1

learning asm

Posted: Sat Aug 02, 2014 4:56 pm
by spacebuddy
I am trying to learn asm and have these instructions.

x.d=1
y.d=2
!fld qword [v_x]
!fld qword [v_y]
!cmp st0,st1

I want to compare st0,st1 to see if it is greater than, but I get an error on the cpm instructions.

I am trying to do an if statement, if x>y :D

Re: learning asm

Posted: Sat Aug 02, 2014 5:14 pm
by wilbert
You need the fcomi instruction to compare when using x87 fpu.
http://x86.renejeschke.de/html/file_mod ... id_88.html

If you don't mind using SSE2, you can use xmm registers and use comisd to compare.
The advantage of SSE2 is that you don't have to consider the fpu stack.

Re: learning asm

Posted: Sat Aug 02, 2014 5:46 pm
by spacebuddy
Thanks Wilbert :D

I got this working now, but how would I use SSE2 instructions for this?

Re: learning asm

Posted: Sat Sep 13, 2014 6:24 am
by wilbert
Sorry I didn't notice your question spacebuddy.

Here's how to do it with SSE2 in case you are still interested.

Code: Select all

x.d=1
y.d=-2

!movsd xmm0, [v_x]
!movsd xmm1, [v_y]
!comisd xmm0, xmm1
!ja x_greater_than_y
End
!x_greater_than_y:
Debug "x > y"
or a little bit shorter

Code: Select all

x.d=1
y.d=-2

!movsd xmm0, [v_x]
!comisd xmm0, [v_y]
!ja x_greater_than_y
End
!x_greater_than_y:
Debug "x > y"