floating point comparison

Discussions related to using the integrated assembler
Ric
Posts: 200
Joined: Tue 17 Apr 2018, 21:03

floating point comparison

Post by Ric »

Evening all,
Could someone with a higher knowledge than mine please explain why this code snippet doesn't work?

Code: Select all

      MODE 1

      DIM Deax      3
      DIM primary   7
      DIM secondary 7
      DIM answer    3
      DIM code% 1024

      FOR I% = 0 TO 2 STEP 2
        P% = code%
        [
        OPT I%
        .calculate
        fninit
        mov eax, 0
        mov DWORD [Deax], 0
        fld QWORD [secondary]
        fld QWORD [primary]
        fcompp
        wait
        fstsw ax
        mov [Deax], eax
        sahf
        je equal
        jg greater
        jl lower
        ret
        .equal
        mov DWORD [answer], 0
        ret
        .greater
        mov DWORD [answer], 1
        ret
        .lower
        mov DWORD [answer], 2
        ret
  
        ]
      NEXT I%

      CLS
      INPUT"Number 1 ";num1
      INPUT"Number 2 ";num2
      |primary   = num1
      |secondary = num2
      CALL calculate
      PRINT "0 = Numbers are equal"
      PRINT "1 = Number 1 is greater"
      PRINT "2 = Number 2 is greater"
      PRINT
      PRINT "Answer = ";!answer
      PRINT "Value in eax ";!Deax
      END
I have taken the bulk of the floating point stuff straight from the manual.
The results is eax are always the same for the same comparison so i could use that but it would be nice to use the correct code.

Regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
David Williams

Re: floating point comparison

Post by David Williams »

Replace

Code: Select all

        je equal
        jg greater
        jl lower
with

Code: Select all

        jz equal
        ja greater
        jb lower
I'm so rusty with this FPU stuff that I had to consult this old web page:

https://www.website.masmforum.com/tutor ... uchap7.htm
Ric
Posts: 200
Joined: Tue 17 Apr 2018, 21:03

Re: floating point comparison

Post by Ric »

Thanks David,
I did not realise that the conditional branches were different.
Ho hum
Regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023