Shop OBEX P1 Docs P2 Docs Learn Events
Binary Division and Multiplication — Parallax Forums

Binary Division and Multiplication

SailerManSailerMan Posts: 337
edited 2011-05-12 06:08 in Propeller 1
I'm trying to wrap my head around Binary Division and Multiplication.

I know that these functions exist in spin as Pasm Blocks. I'm just curious if anyone has code in spin that illustrates this.

I mean how bits get shifted and stuff like that?

This is just a learning thing for me so any help would be greatly appreciated.

Thanks,
Eric

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2011-05-11 19:57
    There are some sample routines (multiply/divide/square-root) in Appendix B of the Propeller Manual (1.1), but only in PASM - I think you want something more friendly??
  • tonyp12tonyp12 Posts: 1,951
    edited 2011-05-11 22:52
    Like fast Multiplication using shift-left and additions?

    Here is a fast *10

    Value2=Value (example 5)
    Value2<<3 (multi by 8, result 40)
    Value2=+Value (result 45)
    Value2=+Value (result 50)
  • SailerManSailerMan Posts: 337
    edited 2011-05-12 04:35
    @Mark, Yeah I've seen those examples, I know taking it from Pasm to Spin sounds like a ridiculous exercise but I'd love to be able to break this down and watch it operate.

    @Tony Hey thanks that pretty cool! ... Now how to make this for any Number.

    Thanks! :)

    Eric
  • prof_brainoprof_braino Posts: 4,313
    edited 2011-05-12 06:08
    SailerMan wrote: »
    taking it from Pasm to Spin sounds like a ridiculous exercise but I'd love to be able to break this down and watch it operate.

    Another example is coded in Propforth.spin

    * trims the results of um*, which calls the assembler function a_umstar
    ( The high level multiplication function * is coded in forth in Propforthkernel.f)

    This code expects the numerator and denominator on the stack, and leave the results on the stack. Since there are no initial, intermediate, or result variables, its a bit faster and shorter than working from values fetched and stored to main memory.
Sign In or Register to comment.