detect overflow of multiply/ div32 result


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    Hi guys,

    I hope i'm not hijacking this thread but...

    It's not complicated...
    C=A*/B is same as C=(A*B)/$FF
    C=A**B same as C=(A*B)/$FFFF
    Maybe my mind is set to work with decimal only and this might be a dumb question but i cant understand what we can get from these operations

    If A=1234 and B=5678 then

    A*B=7006652 ( which in bynary is 0110 1010 ... )

    I know that this operation keeps the higher 2 bytes 0110 1010 so
    A**B= 106

    Having said that, i know how they work... so my question is, when and why are these operations used?

    Thanks

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


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    its mainly about speed of execution and code size.

    eg miles to kilometre conversion k=m*1.609

    pbp has no floats so the 1.609 needs to be scaled up and then the result scaled back

    this will work :-
    you could do 1.609*1000=1609

    k=m*1609 /1000

    (k=m*1609
    div32 1000)


    this is better :-

    using 1.609 * 256 = 411
    so k=m*411/256 (eq to k=m*/411)

    and will give you smaller faster code
    and has a larger input range before overflowing also

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: detect overflow of multiply/ div32 result

    Thanks for the explanation Richard,

    It's crystal clear now

    Regards
    Rui

Similar Threads

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