detect overflow of multiply/ div32 result


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    You can using */ or **.
    ** will return byte 2 and byte 3 of result, ignoring byte 0 and byte 1.
    So you can do something like this:
    Code:
    Dummy = a ** b
    If dummy=0 then
        dummy = a*b
        result = div32 100
        multiplicator=1
    else
        dummy = a * b
        result = div32 1000
        multiplicator=10
    endif

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    perfect thanks for that

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    I don't know maximum value of that variables, but if it is $FFFF then maximum number is $FFFE0001, or 4,294,836,225.
    So maybe you need to divide with more 10000,100000 etc.
    Just use select case or ELSEIF to determine with what value you need to divide.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    I did this , not tested yet


    Code:
     
             mult=1
              ;remaining time in seconds =  (left * LAPSE )/100 
              
             REMTIMEHOU = left ** lapse 
             while  REMTIMEHOU 
             mult=mult*10
             
             if lapse >  left  then 
                 REMTIMESEC = lapse /mult
                 REMTIMEMIN = left
             else    
                 REMTIMESEC = left/mult
                 REMTIMEMIN = lapse
             endif
             REMTIMEHOU = REMTIMESEC ** REMTIMEMIN
             wend
            select case mult 
            case 1
                REMTIMEHOU = left * lapse 
                REMTIMESEC = div32 100
                REMTIMEHOU=REMTIMESEC//3600
                REMTIMESEC=REMTIMESEC/3600
            case 10
                REMTIMEHOU = left * lapse 
                REMTIMESEC = div32 1000
                REMTIMEHOU=REMTIMESEC//360
                REMTIMESEC=REMTIMESEC/360
            case 100
                REMTIMEHOU = left * lapse 
                REMTIMESEC = div32 10000
                REMTIMEHOU=REMTIMESEC//36
                REMTIMESEC=REMTIMESEC/36
            case else
                ; wtf  error
                
            end select
            
              
              
              
              
              
              REMTIMEMIN=REMTIMESEC//60
              REMTIMESEC=REMTIMESEC/60
              
              
              ARRAYWRITE buff,["REMAINING ",DEC2 REMTIMEHOU,":",DEC2 REMTIMEMIN,":",DEC2 REMTIMESEC,0] 
              GLCDSTR 25,80 ,buff
    Last edited by richard; - 15th September 2015 at 11:51. Reason: took out redundant if

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    I just noticed, that you can easily overflow variable mult after just 5 iteration.
    You can just store number of 0 in that variable, or something...

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    was hoping 3 iterations will be enough, but your right

    one day I'm going to write a python pbp calculator with
    pbp math functions including ** , */ and div32
    using unsigned bytes and words

    trial and error is tedious and I hate surprise results

  7. #7
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    It's not complicated...
    C=A*/B is same as C=(A*B)/$FF
    C=A**B same as C=(A*B)/$FFFF

Similar Threads

  1. multiply oscillators
    By ozzieB in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 7th April 2009, 09:41
  2. Retrieving 32bit Multiply Result
    By Darrel Taylor in forum Code Examples
    Replies: 42
    Last Post: - 28th January 2008, 16:15
  3. 18F4620 hardware multiply
    By eric180db in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2007, 13:54
  4. Replies: 3
    Last Post: - 13th August 2006, 06:16
  5. Can't multiply by 2!
    By jswayze in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th October 2004, 15:24

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts