Stumped by instruction in PASM
AGCB
Posts: 327
I'm learning PASM, tables at the moment and came across this instruction in a tutorial
MOV data, 0-0
I've searched all the normal documents but haven't been able to figure this out (the 0-0 part). Help needed!
Thanks
Aaron
MOV data, 0-0
I've searched all the normal documents but haven't been able to figure this out (the 0-0 part). Help needed!
Thanks
Aaron
Comments
With that info I'll study some more. May be back w/ another ?
Aaron
Just to be 100% clear, you don't need to use 0-0 in the address that will be modified by the program. When the program is assembled/compiled that probably ends up being an address of 0 initially, and gets changed to another address before the instruction is executed. It is used so it is apparent when looking at the source code that the address for this instruction is modified by the program.
100% correct. It is worth mentioning that two instructions are designed for the purpose of modifying another instruction's destination and source fields: MOVD and MOVS respectively; although you can also do things like ADD, OR, XOR, etc given a suitable mask for your purpose.
What the complier puts there is 0, as it actual do the math on zero-minus-zero
That codes run in ram allows you to self-modify it on the fly, you will need to know the address of it so you put a label in front of it (maybe already be one there for other loop purposes)
Adding and Subtraction can be done, and for D field you use ±1<<9 and it kind of auto-mask as you will not get overflow as you would normally never have values+values that would point outside 512 longs anyway..
Doing a reset of values have to be done with MOVS and MOVD (MOVI is not used often)
Why not put the first real value there instead of 0-0?
Self-modifying code is mostly inside a loop that is used many times so you have to reset it anyway and do it before the loop and not after it, so give yourself a visual cue with this 0-0 placecard
Like this?
I searched to find where I got this tutorial. It was from an old forum thread (2006) and a post by Mike Green #19. I've included it here
{'' Here's a simple example of table lookup in assembly.
'' This particular example takes a table index in "ptr"
'' and sets the "data" to the word value from the table.
'' There's no range checking. If you want long values,
'' just eliminate the shifts and masks (*). You can use
'' the same kind of logic for byte values.
I tried to put it in a complete program, had to change it slightly to compile. But all I get is $0000 on the display. Here is my code
A little more help is appreciated.
Aaron
edit; NOPE!
movs :inline,data
nop
:inline mov data,0-0
will become
:inline mov data,data
So you will be actually moving the value at data to data, which does nothing.
What you most likely are after is
movs :inline,#data
nop
:inline mov data,0-0
which becomes
:inline mov data,#data
which moves the address of data into data. Normally they would be different labels.
Hope this helps.
-Phil
Thanks
Aaron
If I put a 0 in there the code hangs up and stops working
And it has been one reason that I've been a bit shy of Spin PASM from the start.
It would be wonderful it a white paper was available. Or is this already mentioned somewhere in the PASM documents out there?
ah... Page 3 of this ===> forums.parallax.com/attachment.php?attachmentid=49618
(It is the Parallax Propeller Tips & Traps.pdf)
I was just headed out the door and didn't have time to absorb your entire post this morning. I'll look at it in detail this evening.
Aaron
Don't be so shy of PASM.
PASM must be the simplest assembly language I have ever used. I mean how is: any much more difficult than: On top of that, the way writing PASM is seamlessly integrated into Spin makes it really easy to get started and experiment with.
That little quirk about using self modifying code is not so hard and perhaps not even necessary for a lot of jobs.
PASM is fun. Jump in there.
The only reason I ever need to use self modifying code (for PASM) is to access tables in cog memory. Here's hoping that Prop II will have some indexing or indirect addressing capability.
PASM must be the simplest assembly language I have ever used[/QUOTE]
I don't know very much but I first used PICs and taught myself asm. If you want to see involvement Check out the pdf data sheet for a PIC18F43k20 (my favorite PIC)
I'm lov'n Propeller
Once you put together some forum posts and look at some other tutorials or whatever and then go back and read the manual "again for the very first time". It makes complete sense that you couldn't see before. Like a person born blind being told what a flower looks like. Even though the explanation is perfect, something else is needed.
Aaron
But I suspect the bottom line is that by understanding both alternatives, one really does master programing in a way that holding on to only one approach will never achieve.
I've never doubted the claims that once learned, PASM is simpler than other assembly languages as the Propeller architecture is simpler to manage.