Stumped by instruction in PASM
AGCB
Posts: 344
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?
movs :inline,data ' have to use instruction modification nop ' need pause here for pipelining :inline mov data, 0-0I 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.
DAT org 0 test mov ptr,#2 ' for an example, get third value call #look ' note table indices are 0 to n-1 :stop jmp #:stop ' no checking for out of range look mov data,ptr ' ptr is a table index (0 to n-1) shr data,#1 ' divide input value by 2 to get (*) add data,#table ' long word index, add table address movs :inline,data ' have to use instruction modification nop ' need pause here for pipelining :inline mov data,0-0 ' get long value from table test ptr,#1 wz ' do we want odd or even half (*) if_z and data,mask ' if even, take lower 16 bits (*) if_nz shr data,#16 ' if odd, take upper 16 bits (*) look_ret ret table word $0000 word $C0C1 word $C181 word $0140 word $C301 word $03C0 word $0280 mask long $FFFF data res 1 ptr res 1I 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
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ tv : "tv_text" VAR long _data PUB go tv.start(0) tv.str(string($A,1,$B,1)) tv.hex(_data,4) cognew(@test1,@_data) DAT org 0 test1 rdlong p, par 'get hub address into p mov ptr, #2 ' for an example, get third value call #look ' note table indices are 0 to n-1' ':stop jmp #:stop ' no checking for out of range wrlong data, par jmp test1 look mov data, ptr ' ptr is a table index (0 to n-1) shr data,#1 ' divide input value by 2 to get (*) add data, #table ' long word index, add table address movs :inline,data ' have to use instruction modification nop ' need pause here for pipelining :inline mov data, 0-0 ' get long value from table test ptr,#1 wz ' do we want odd or even half (*) if_z and data,mask ' if even, take lower 16 bits (*) ' if_nz shr data,#16 ' if odd, take upper 16 bits (*) look_ret ret table long $0000 long $C0C1 long $C181 long $0140 long $C301 long $03C0 long $0280 mask word $FFFF data res 1 ptr res 1 p res 1A 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
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ tv : "tv_text" VAR long _data PUB go tv.start(0) cognew(@test1,@_data) repeat tv.str(string($A,1,$B,1)) tv.hex(_data,4) DAT org 0 test1 mov p2, #0 'initialize pointer counter mov t, cnt 'set up delay add t, #9 ' " :loop waitcnt t, delay mov ptr, p2 ' add p2, #1 ' note table indices are 0 to n-1 call #look 'add p2, #1 test p2, #6 wz 'done w/ all table entries? if_z mov p2, #1 'start over jmp #:loop look mov data, ptr ' ptr is a table index (0 to n-1) 'shr data,#1 ' divide input value by 2 to get (*) add data, #table ' long word index, add table address movs :inline,data ' move data to source field at :inline nop ' need pause here for pipelining :inline mov data, 0-0 ' get long value from table ' test ptr,#1 wz ' do we want odd or even half (*) 'if_z and data,mask ' if even, take lower 16 bits (*) 'if_nz shr data,#16 ' if odd, take upper 16 bits (*) wrlong data, par look_ret ret table long $0001 ' !!!! can't seem to read this entry !!!! long $C0C1 ' after 1st time long $C181 long $0140 long $C301 long $03C0 long $0280 long $0007 'mask long $FFFF delay long 160_000_000 data res 1 ptr res 1 p2 res 1 'for cycling through table t res 1 'for waitcnt instThanks
Aaron
mov ptr, p2 call #look add p2, #1 cmpsub p2, #number_of_table_entries jmp #:loopIf 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.