basic pasm
pilot0315
Posts: 910
in Propeller 1
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
Thanks
Comments
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).
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
https://forums.parallax.com/discussion/94027/assembly-step-by-step/p1
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
Thanks for this information - I had not heard of this book.
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 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
BTW Alles ist in orgnung!
-Phil
This led to obvious problems when calling sub-routines from the background and an interrupt (or from multiple interrupts). You had to
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.