Shop OBEX P1 Docs P2 Docs Learn Events
basic pasm — Parallax Forums

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?

Thanks

Comments

  • 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...

    Mike
  • 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.
    https://forums.parallax.com/discussion/94027/assembly-step-by-step/p1
  • frank freedmanfrank freedman Posts: 1,983
    edited 2018-08-12 14:55
    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.
  • 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!!!

    Thanks
  • WhitWhit Posts: 4,191
    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.
  • Sridhar's book does not really start at the very beginning.

    He assumes like many others that they are talking to engineers who have had experience in ASSEMBLY like IBM. I took that class 30 years ago plus. So I have to start over.
  • I would agree to a point. I don't have a CS degree and have played with various assemblers over the years, from 8080/Z80, AN/UYK7 and 20 as well as 370 assembler and all the fun stuff that goes along with that. The subject of data compression is not really a trivial subject either. I think his main reach will be those with enough spin under them to realize there are things that need to be faster or more compact. Also, he touches (ok, lightly evangelizes) for a method called test driven development.

    I have found the book to be very useful, but if someone does not have a bit of pasm, they can still gain a lot from this book as a tutorial AND a guide to what you may need to research in the forums or parallax documents. There was a rather fiery thread a few years ago that if you filter the slag, has quite a bit of gold in it from the best of the best at that time. But then again, assembler is not for the novice. In any hardware. As someone else said on the forums, they have never seen a CS101 using assembler. If someone wants a skill bad enough, they will do what they need to acquire said skill..........IM(not so)HO
  • I go back to the IBM 1130 and 360/370 days. Plus the HP 200C. That's a long time ago in a galaxy far, far away.

    BTW Alles ist in orgnung!
  • Don't know about this one The IBM strong in him it is. To look back on JCL without an allergic reaction .......
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2018-08-19 23:43
    pilot0315 wrote:
    I go back to the IBM 1130 ...
    Then you're in luck! Calling subroutines in PASM is very much like it was done in the 1130. A return address is stuffed into the code when the call is executed. A jump to that address performs the return. The only significant difference is that, in the 1130, the return address was stuffed into the first word of the subroutine, and execution proceeded beginning with the next word. In the Propeller a call to subr stuffs the return address into the ret instruction (just another jmp #) at location subr_ret.

    -Phil
  • The SDS 900 series (and big brother 9300) stored the return address (and the overflow bit) in the first word of the subroutine.

    This led to obvious problems when calling sub-routines from the background and an interrupt (or from multiple interrupts). You had to
    Int   LDA  Sub      save return
              STA  MySave 
              BRM  Sub
              LDA  MySave   restore
              STA  Sub
    

    Of course, this isn't a problem with Prop PASM since it does't have interrupts.
  • .
  • kwinnkwinn Posts: 8,697
    The SDS 900 series (and big brother 9300) stored the return address (and the overflow bit) in the first word of the subroutine.

    This led to obvious problems when calling sub-routines from the background and an interrupt (or from multiple interrupts). You had to
    Int   LDA  Sub      save return
              STA  MySave 
              BRM  Sub
              LDA  MySave   restore
              STA  Sub
    

    Of course, this isn't a problem with Prop PASM since it does't have interrupts.

    IIRC the IBM1401 SPS did the same thing, although I am basing that on using a 1401 emulator that was running on a Collins 8400 system.
Sign In or Register to comment.