PASM question
Bobb Fwed
Posts: 1,119
I want to do this:
I want to do that (or similar) in PASM
example (probably wrong -- but it is what I was trying to do):
Is the plus (+) symbol the correct thing to use? Is there a better/correct way to address a block? The plus symbol seems to be doing something...but I don't know if it is the correct something.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
REPEAT idx FROM 0 TO 10 long[noparse][[/noparse]block + idx] := 5
I want to do that (or similar) in PASM
example (probably wrong -- but it is what I was trying to do):
entry MOV idx, #10 ' set index to 10 MOV ptr, #0 ' set pointer to 0 :set_five MOV block+ptr, #5 ' set block values to 5 ADD ptr, #4 ' move pointer one long DJNZ idx, #:set_five idx RES ptr RES block RES 10
Is the plus (+) symbol the correct thing to use? Is there a better/correct way to address a block? The plus symbol seems to be doing something...but I don't know if it is the correct something.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Comments
First, define a destination increment. I think it's:
dlsb long 1<<9
Then, before the loop do:
movd :Set_Five #block
nop
Then after the mov, do:
add :Set_Five dlsb
I think this is right, but I'm really tired!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
You are aware that your SPIN-code works in HUB-RAM whereas the PASM-code you provided works in COG-RAM? So, to do exactly the same you would have to use the wrlong instruction.·Just·wanted to·point it out.
So, assuming you know that:
Add #4 in COG-RAM context is wrong. In COG-RAM the memory has long-adresses. In HUB-RAM the memory has byte adresses. So, in HUB-RAM you have to add by 4 if you want the next long, in COG-RAM you have to add 1!
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
I will probably have figured it out by trying (right now) before you are able to reply.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
The first part is SPIN code to write the address of block[noparse][[/noparse]0] to the data which gets copied to HUB RAM.· This could also be done via coginit( @cogstart, @block), or by some kind of parameter block which gets passed by address via coginit.· This way is easy, but requires caution if you have multiple cogs/objects which may be setting the variable at the same time.
Next, the PASM code sets the idx (really a counter) to 11 since your REPEAT was 0 TO 10 which is 11 values.· Remember that DJNZ falls through when the counter is decremented to zero.· Also remember that DJNZ is a down counter if you are using it directly.· PTR is then set to the address of block[noparse][[/noparse]0]·and WRLONG is the equivalent of long[noparse][[/noparse]ptr] := 5.· Then PTR is advanced to the next long and the loop repeated.
Now, if block[noparse]/noparse is stored in COG RAM then the instructions are completely different.
The important instruction is :loop which writes the value 5 to register #block+0.· The +0 is there to remind me the value is changed.· Everything in PASM is evaluated at compile time to static values.· So MOV block+idx, #5 will be compiled to·"write value·5 to·register·#(register #block·+ register #idx)" which will write 5 to someplace in COG RAM.· But this is why PASM has instructions like MOVD.
Okay, so now start at the top.· MOVD·writes the register # for block·into the destination register of :loop.· Because the Propeller is lightly pipelined this needs to be done at least 2 instructions before the instruction modified.· The MOV idx, #11·provides the necessary·pipeline gap.· The next MOV writes the desired value, the ADD advances the destination register of :loop and then the DJNZ completes the loop (and adds the necessary pipeline delay).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: http://forums.parallax.com/showthread.php?p=800114
NTSC & PAL templates: http://forums.parallax.com/showthread.php?p=803904
That doesn't make sense as LONG[noparse][[/noparse]BaseAddress] expects BaseAddress to be long aligned, but your REPEAT is (implicitly) STEP 1.· What you probably wanted is
So block is the BaseAddress of a set of 11 longs.· If block is a VAR or DAT array, then you want
Note: my code assumes this last case.· If the second case is true then replace "block_addr = @block" with "block_addr = block" in the HUB RAM code and "MOVD· :loop, #block" with "MOVD· :loop, block" in the COG RAM code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: http://forums.parallax.com/showthread.php?p=800114
NTSC & PAL templates: http://forums.parallax.com/showthread.php?p=803904