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

basic pasm

I am attempting to learn pasm. Does anyone have a good explanation outside of dasilva and other who do not teach basics, about multiplication and division in pasm with an easy explanation?



  • 8 Comments sorted by Date Added Votes
  • The entry and exit in the propeller manual is not intuitive
  • There are no multiply and divide instructions in Prop 1. If you need to multiply by a small constant, you can use shifts and adds like:
    Mult10  mov   Answer,X   ‘ Multiply X by 10
            shl   Answer,#2  ‘ First multiply Answer by 4
            add   Answer,X   ‘ Add X for multiply by 5
            shl   Answer,#1   ‘ Multiply by 2 for 10
    If you need to multiply by a variable, use a multiply subroutine. All division is done by subroutine.

    Yes, call and return are not intuitive, but they are simple and done with a jump/return (JMPRET) and jump (JMP) instruction. The assembler also has the CALL and RETURN “macros” to simplify the work.

    The JMPRET instruction sets the program counter to the source address of the instruction effectively doing a jump operation. As a “side effect”, it stores the old contents of the program counter (the “return address”) in the source address portion of the long/instruction at the destination address of the JMPRET. If that long/instruction is a JMP instruction, it works to provide a “return” to just after the CALL or JMPRET. If that long/instruction is a JMPRET instruction, you have a mechanism for doing coroutines (an advanced topic).
  • Hi Pilot0315,

    PASM is slightly different from normal assemblers, like everything on the P1 is slightly different form other MCs.

    DeSilva is very deep in the details, to begin with it might be better to just look thru the proptool examples.|

    But you asked for basics and I will try to explain some small hurdles you have to take, mentally.

    First of all, in opposite to other MCs your PASM program does NOT run in HUB ram, it gets just loaded from there into the COG and the copy in COG ram gets executed.

    Second concept to wrap your head around is that each COG ram location is also a register. So in opposite to other MCs you do not have some x registers and a ram for executing code, you are basically executing your code inside of your 512 registers.

    So every instruction in your source code ends up in a ram location you are able to access as a register also. That leads to interesting possibilities for self modifying code, often used to save space.

    The next hurdle is that the P1 does neither has a stack nor a stack-pointer-register.

    CALL and RET simulate a one level stack by effectively saving the return address at the ram/register of the RET instruction when the CALL gets executed. Works perfectly well but recursion is not supported and needs to be handled different.

    Like Mike Green said the JMPRET instruction does all the magic, but it is more easy to use CALL and RET until you have thee need to use JMPRET direct.

    I am not sure if this is what you called entry and exit, but there is some other concept to wrap your head around.

    In other MCs you call a assembler routine from say your basic program and then return to your program after the assembler routine finished.

    With the P1 one usually works completely different. You start a assembler-blob in a COG running in a endless loop, checking some HUB-address used as a Mailbox between parallel running processes.

    Your main program writes a command into the mailbox and does what it usually does or waits for a answer from the second process if needed.

    The PASM-Program in the second COG/process now reads the command in the mailbox, does what needs to be done and
    confirms via the mailbox the result.

    So the entry is basically starting the parallel running COG and the exit would be to stop that parallel running COG.

    Any 'call' to use the parallel running COG is usually done by using HUB addresses as Mailbox, known to caller and callee.

    Writing this down it seems to be very complicated, but in fact it is a very simple way to handle real parallel processes, compared to time-slices used with interrupts.

    One has just to - hmm - do things a little bit different on the Propeller, but then it shines...

    I am just another Code Monkey.
    A determined coder can write COBOL programs in any language. -- Author unknown.
    Press any key to continue, any other key to quit

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • I tried the above code and get zeros
  • I wrote my first PASM object with the help of Graham Stabler's tutorials. I had a tough time finding the link. There are more tutorials but this tutorial is a good start.

    If the grass is greener on the other's time to water your lawn.
  • frank freedmanfrank freedman Posts: 1,378
    edited August 12 Vote Up0Vote Down
    There is an excellent work by Sridhar Anandakrishnan called "Propeller Programming in Assembly, Spin and C. Was a lean pub originally, but that version is no longer available. The new version is from A press and amazon. Runs from Spin, pasm, then C. The C chapter also gets into inlining PASM in C and the other stuff. Very strong recommendation.
    Ordnung ist das halbe Leben
    I gave up on that half long ago.........
  • Thanks to lardom I found that link to be helpful.
    Frank, I have the Sridhar book found it online. Helpful but still complex for the beginning stuff.
    I am in in touch with Sridhar, he seems to be a nice guy and is trying to help.

    Trying to understand the basic math of multiply and division etc. If you or anyone has a good simple explanation of the add, sub shift methods that would be great.
    Bit shifting math was so long ago!!!

  • There is an excellent work by Sridhar Anandakrishnan called "Propeller Programming in Assembly, Spin and C.

    Thanks for this information - I had not heard of this book.

    "We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney
Sign In or Register to comment.