Shop OBEX P1 Docs P2 Docs Learn Events
Array stuff — Parallax Forums

Array stuff

doftdoft Posts: 4
edited 2011-07-13 07:15 in Propeller 1
Hello and thanks for reading this.

Sorry to post like this, I haven't been able to figure it out or find relevant postings. I'm open to either!

I have a simple program where I define what I believe is an array of longs eg (local_var res 90) and want to access the other elements of this array in asm. A cog will then fill the longs locally.

mov local_var, value
mov local_var<-Next long, next value. How to do this?
.....

I've been racking my brain figuring out how to do this and come up empty. The second part of this to send it to the hub. Under the var heading, I have defined (byte hub_var[360]))That 90 longs=360bytes is no accident.

I've been able to use wrlong to send one long and read out the bytes but thats it. How to do this like an array is my goal.

Again, thanks.

Doft

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-05 07:24
    I've attached a template that I used for myself; it includes PASM subroutines to read and write local arrays. This should get you going.
  • doftdoft Posts: 4
    edited 2011-07-05 16:02
    Thanks JonnyMac for the code. I have a few questions

    <code>
    write mov tmp1, basepntr
    add tmp1, idx
    movd wrval, tmp1
    nop
    wrval mov 0-0, value
    write_ret ret

    '

    PWM_NCO long %00100 << 26 ' for counters

    basepntr res 1 ' for tables r/w
    idx res 1
    value res 1

    tmp1 res 1 ' work vars
    tmp2 res 1

    fit 496
    </code>

    In write, the first thing that is done is copying the value of basepntr into tmp1. Then, adding to tmp1, what is in idx. Wouldn't you have want to set basepntr to the address of the array of variable you want to write to or is this assumed to already have happened? The definition of movd is to set the destination address of the variable in the first field to the value in the second. Is this how you are changing or re-defining the address of this variable?
    My next question is what mov 0-0, value is doing. I assume this means writing to wrval, but the syntax is a bit confusing. Can you do mov wrval,value instead?

    Thanks

    Doft
  • potatoheadpotatohead Posts: 10,261
    edited 2011-07-06 00:07
    idx would be initialized prior to entering the loop. tmp1 is a working copy, leaving baseptr undisturbed. One could choose to modify it, of course, requiring it be saved prior to entering the loop.

    idx is simply your value used to step through memory. Typically, this is 1 for a byte, 2 for a word, 4 to do a long at a time.

    0-0 stands for self-modifying code. movd writes the value of tmp1 to the instruction at label "wrval", so it's literally changed each time through the loop. We use 0-0 by convention, because it doesn't have any other impact on the program, and it sticks out because it doesn't make any other sense.
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-07-06 05:11
    I'm not sure who started using 0-0, but it seems like it would be better to just use 0 and add a comment to the end of the line. 0-0 is confusing to novices, and a comment would be much clearer.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-07-06 07:46
    I started the use of "0-0" for the Prop. It's something I learned from my mentors and I've used it for many years. The reason for it is that just "0" or any other simple value has a potential purpose all by itself while "0-0" is used for nothing else than a placeholder for a value calculated at execution time. Because few people program in assembly language these days and very few instruction sets require heavy use of instruction modification, this technique is not taught or used much.
  • Heater.Heater. Posts: 21,230
    edited 2011-07-06 07:57
    Dave Hein,
    0-0 is confusing to novices

    That's exactly why we use it:)

    I agree with Mike. This self modifying code is quite weird so putting a weird thing like "0-0" there to highlight the point is a good idea. Comments are sloppy and often neglected.

    As you see when novice sees "0-0" they immediately know something odd is afoot and come here asking what it is. This is a good thing although perhaps it should be described and used in the PASM documentation to save them having to ask.
  • potatoheadpotatohead Posts: 10,261
    edited 2011-07-07 21:42
    IMHO, both is a good choice too. If the comment gets neglected, the 0-0 is still there, still able to trigger that question, "WTH??"

    I really like a quick mention of it in the manual. Seconded.

    Have it titled "Self Modifying Code", and then have a brief description of why it happens, how the mechanics work, and a few examples, one with source modified, destination modified, both, and a final one with "#" literal addressing, as opposed to the usual indirect.

    That would cover the various forms possible, and a few nice use cases too.

    I'm adding that to the tutorial document I've got slowly building. Necessary, IMHO.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-07 22:24
    The notation 0-0, or something like it, is not unique to PASM. For example, the IBM 1130 used *-* for the same purpose: to denote a placeholder where something was to be written before the instruction was executed. The * in 1130 assembly denoted the "current address pointer" and *-*, like 0-0, was merely a stylistic device that evaluates to zero. The earliest version of PASM did not have a current address pointer, so 0-0 was adopted instead. (Mike and I apparently adopted it independently -- and probably for the same reasons, since we're from the same "computer generation." :) ) Had Chip included the $ notation early on, I would have started using $-$ in my programs instead of 0-0. But that notation was not available, 0-0 was the next best option, and it will likely live on as a result.

    -Phil
  • doftdoft Posts: 4
    edited 2011-07-08 00:48
    lol how do I close this thread?
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-07-08 06:54
    doft, were your questions answered, or are you still unsure how the Prop accesses an array in cog RAM?
  • potatoheadpotatohead Posts: 10,261
    edited 2011-07-08 07:41
    If you edit your first post, and "go advanced", you should see the GUI for editing the comment. Change it from unsolved to solved, or something else.

    Closing the thread just happens when nobody writes on it anymore. Or, in a extreme case, one of our moderators may lock it. If you want, you could ask.
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-07-08 08:00
    I think he was kidding about closing the thread.
  • potatoheadpotatohead Posts: 10,261
    edited 2011-07-08 08:14
    Oh, I think so too. Low post count though. Worth articulating the answer anyway.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-13 07:15
    Wouldn't you have want to set basepntr to the address of the array of variable you want to write to or is this assumed to already have happened?

    In Spin, you might do something like this:
    value := 128
      repeat idx from 0 to 9
        brightness[idx] := value
    

    where 'brightness' is the array and 'idx' is the element you want to write. In my PASM code you would specify the address of your array and the element you want to write -- like this:
    setmiddle               mov     value, #128                             ' set to midpoint 
                            mov     basepntr, #brightness                   ' use local brightness array
                            mov     idx, #0                                 ' start at beginning
    :loop                   call    #write                                  ' write value to brightness[idx]
                            add     idx, #1                                 ' increment idx
                            cmp     idx, #9                         wc, wz  ' done?
            if_be           jmp     #:loop                                  ' if 0 to 9, keep going
    

    As you can see, you need to set value, basepntr, and idx before calling write (only basepntr and idx for read).

    Hopefully, this clarifies that subroutine.
Sign In or Register to comment.