Forum Update - Announcement about May 10th, 2018 update and your password.

Performing modulus in PASM

escherescher Posts: 113
edited January 31 in Propeller 1 Vote Up0Vote Down
I have a dynamic value, n, that I need to perform modulus on within a cog's PASM code in order to calculate a hub RAM memory offset.

Is there a fast/low instruction count trick to performing this operation? Google and forum searches haven't helped.

Thank you!

Comments

  • 6 Comments sorted by Date Added Votes
  • I apologize, my re-attempt at Googling somehow was more helpful... I'm sure there's some Law out there that states "Any problem searched extensively for will be solved by a re-search performed immediately after posting on a forum about it"
  • Yes indeed. Internet or not, often as soon as you can form the question in your mind, your mind has the answer!

    As to the "modulus" thing. That is easy or hard depending if your modulus is a power of 2 or not.

  • Heater. wrote: »
    Yes indeed. Internet or not, often as soon as you can form the question in your mind, your mind has the answer!

    As to the "modulus" thing. That is easy or hard depending if your modulus is a power of 2 or not.

    Fortunately it was modulus-8, so I was in luck on that front!
  • Tracy AllenTracy Allen Posts: 6,262
    edited January 31 Vote Up0Vote Down
    For future reference then, modulus any number is just as easy, just a bit esoteric.
    cmpsub offset, modulus .  ' keeps offset in the range 0 to (modulus-1)
    

  • Of course that instruction assumes the value is already in the range 0 .. 2*modulus-1.
  • Tracy AllenTracy Allen Posts: 6,262
    edited February 1 Vote Up0Vote Down
    Good point. I was thinking of offset into a circular buffer or paged memory (as in data logging) where the address increments by one or by a small value less than the modulus. Quite a different thing, more complicated, for random access.

    I bookmarked the page that Escher linked to at Stanford.edu, bithacks. It reminds me of Hacker's Delight, wherein chapters 9 and 10 cover a lot of the same ground. A great reference.
Sign In or Register to comment.