Shop OBEX P1 Docs P2 Docs Learn Events
A very basic question about Arrays in Pasm (2nd edit) — Parallax Forums

A very basic question about Arrays in Pasm (2nd edit)

b.p.m.b.p.m. Posts: 59
edited 2009-06-05 05:47 in Propeller 1
hi everyone,
i've been searching the assembly tutorials, the forum and any
program that i've downloaded for a simple example of array
usage in pasm.
i have two small arrays as follows;

disp long $3f,$06,$5b,$4f,$66,$6d,$7d,$07,$7f,$6f
disp_g long $0e,$0d,$0b,$07

how do i go about using an offset register in pasm to recover
say " disp[noparse][[/noparse]pntr]" (spin syntax) where pntr is say 4 returning
"$66" ? i know this is simple and basic but until i find out how
to do it, i'm stuck.

do i use the following:

mov pntr,#4
mov temp,@disp
add temp,pntr
mov result,@temp


much thanks in advance,

blake

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Can't sleep, clown will eat me."
Bart Simpson

Post Edited (b.p.m.) : 6/5/2009 3:57:42 AM GMT

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-05 03:32
    As long as you have RAM left in the COG you should use longs. Because the Propeller is a pure 32 bit controller and does not support byte access in COG-RAM. So, when you really need bytes there things get more complicated. (Or you move the bytes to HUB-RAM - there you have the wrbyte/rdbyte instructions).In PASM we don't have indirect adressing. So, what you suggest (have the adress offset in a register) does not work in the propeller. You have to calculate the adress in a register and then inject the adress into the code. That's why we have the movs and movd instructions. Please remember: Self modified code should not be used immediately. You need at least one NOP (or an other useful instruction) between the movs/d and the instruction you modified.
  • David VossDavid Voss Posts: 1
    edited 2009-06-05 04:07
    Hello Blake,

    Here's an example of how to do the self-modifying code that Maji02 mentioned, together with the comment in my code that explains it. Hope this helps,

    Dave

    adc_loop        mov     t1, #ctra_data
                    add     t1, adc                 'ptr for ctra_data[noparse][[/noparse]adc]
                    mov     t2, #period
                    add     t2, adc                 'ptr for period[noparse][[/noparse]adc]
    
            { The propeller doesn't have indirect addressing, so a work-
              around is self-modifying code, putting the pointer address
              directly into the instructions below. The two accesses are
              interleaved because there must be at least one instruction
              between the self-modify and the execution, and I'd rather it
              not be a NOP. }
    
                    movs    :ctra_s, t1
                    movs    :cer_s, t2
    :ctra_s         mov     ctra, 0-0               'mov ctra, ctra_data[noparse][[/noparse]adc]
    :cper_s         mov     cper, 0-0               'mov cper, period[noparse][[/noparse]adc]
    
    
  • b.p.m.b.p.m. Posts: 59
    edited 2009-06-05 04:52
    hey MagIO2 and David,
    thanks for advice on using pointers. i didn't realize
    that indirect addressing wasn't supported in a
    otherwise powerful assembly. thanks David for
    your example code; it's just what i was needing.
    by the way, does anyone know any good tutorials
    on Prop assembly; i've read de Silva's and potatohead's
    tutorials,(which were good) but i need more in depth
    information. like the aforementioned problem i am
    getting stuck simply from lack of knowledge.

    thanks again

    blake

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Can't sleep, clown will eat me."
    Bart Simpson
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-05 05:47
    Thanks David, for the code.
    (I was in a hurry this morning, otherwise I'd have posted some code by myself.)

    I would not call the self-modifying code a workaround. It was a design decision to do indirection in that way! Indirection as used on other CPUs adds complexity to the execution unit of the CPU -> so it needs additional real estate on the die -> die would be to big for DIP package -> we would not have a hobbyist-friendly propeller ;o) And/Or it has impact on the pipeline.

    I have the feeling that the Hydra book would be a good read. But maybe someone who ows one can acknowledge this, because I don't have one yet. Besides the mentioned tutorials I don't know of any additional teaching papers. Did you see the Assembly for beginners link in the sticky?

    Simply ask your questions here.
Sign In or Register to comment.