BBC BASIC
Programming >> Assembly Language >> floating point comparison
http://bbcbasic.conforums.com/index.cgi?board=assembly&action=display&num=1518127371

floating point comparison
Post by Ric on Feb 8th, 2018, 9:02pm

Evening all, can anyone tell me why this code doesn't work? On the face of it, it gives the right result, but if you change the values of [result] and [result+8] it simply fails!

Help, anyone
Code:
      MODE 7
      DIM code% NOTEND AND 2047, code% 2047
      DIM result 27
      |result      = 11.87655
      |(result+8)  = 17.87655
      |(result+16) = 0.1
      FOR opt% = 0 TO 2 STEP 2
        P% = code%
        [
        OPT opt%
        .start
  
        mov                    eax,                       0
        mov              DWORD [result+24],               0
  
        fld              QWORD [result]
        fld              QWORD [result+16]
        faddp                  ST1,                       ST0
        fcomp            QWORD [result+8]
        fstsw                  ax
        wait
        sahf
        ja                     next_calc
        mov              DWORD [result+24],               2
        ret
  
        .next_calc
  
        mov                    eax,                       0
        fld              QWORD [result]
        fld              QWORD [result+16]
        fsubp                  ST1,                       ST0
        fcomp            QWORD [result+8]
        mov                    eax,                       0
        fstsw                  ax
        wait
        sahf
        jb                     end
        mov              DWORD [result+24],               3
        ret
  
        .end
        mov              DWORD [result+24],               1
        ret
        ]
      NEXT

      CALL start
      PRINT !(result+24)
 



Regards Ric
Re: floating point comparison
Post by Richard Russell on Feb 8th, 2018, 9:24pm

on Feb 8th, 2018, 9:02pm, Ric wrote:
Evening all, can anyone tell me why this code doesn't work?

The code requires a *FLOAT 64 but as listed there isn't one. Of course it might simply have been lost in copying the listing into the forum, but it's the first thing I would check.

Richard.

Re: floating point comparison
Post by Ric on Feb 11th, 2018, 08:31am

Thanks for the swift response Richard, you're right that the *FLOAT command is missing because of transposing into the forum. It turns out as you probably know there is nothing wrong with the code, it was the test on return from the routine that was at fault.

Regards Ric