learning asm

Bare metal programming in PureBasic, for experienced users
spacebuddy
Enthusiast
Enthusiast
Posts: 346
Joined: Thu Jul 02, 2009 5:42 am

learning asm

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: learning asm

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
spacebuddy
Enthusiast
Enthusiast
Posts: 346
Joined: Thu Jul 02, 2009 5:42 am

Re: learning asm

Post by spacebuddy »

Thanks Wilbert :D

I got this working now, but how would I use SSE2 instructions for this?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: learning asm

Post 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"
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply