Shop OBEX P1 Docs P2 Docs Learn Events
Help with PASM Data Table — Parallax Forums

Help with PASM Data Table

DroneDrone Posts: 433
edited 2009-08-17 18:35 in Propeller 1
Hello,

Awhile back when perusing this forum I scraped a snippet of code by Mike Green (thanks Mike) on how to handle a data table in cog RAM with PASM. Something's coming up where I need to do just that. So I stuck Mike's code in a wrapper (see attached files), and took it for a "spin". It works fine.

The problem is I don't understand how it works. I'm really not good in PASM, but I'm trying. I don't understand how this part works:

              [b]add[/b]     Idx_,#table   'Long word index, add table address
              [b]movs[/b]    :inline,Idx_  'Use instruction modification
              [b]nop[/b]                   'Pause for pipelining
  :inline     [b]mov[/b]     Idx_,0-0      'Get long value from table
              [b]wrlong[/b]  Idx_,[b]par[/b]      'Return result to Idx_



Especially the mov idx_,0-0 line. This looks like re-entrant code. I searched the forum and manual, and I'm still not getting it. Can someone please explain what's going on here in plain language.

Thank You,
David

Comments

  • AleAle Posts: 2,363
    edited 2009-08-11 08:47
    Drone:

    movs fills the source (bits 8 to 0) of the destination with the value in the source (either literal or from memory).

    What you do is: you have a table in COG memory. To read it you need an address to the start and an index. table is your start address, top of the table. idx_ is your index. The resulting value is your source address to read from the table. So you move (using movs) this address to the instruction (@ :inline) that will actually read the table.

    See what happens, see the images in order from 9 to 13.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU

    Post Edited (Ale) : 8/11/2009 10:58:12 AM GMT
    931 x 557 - 111K
    931 x 555 - 110K
    930 x 555 - 109K
    932 x 555 - 110K
    930 x 554 - 110K
  • DroneDrone Posts: 433
    edited 2009-08-11 11:05
    Hi Again Ale,

    I think I understand your explanation. Allow me parrot - please point out any mistakes:

    'Cog table address is $10, idx_ is $05, the value in the table at
    'addr table+idx_=$10+$05=$15 is $20.
    
                [b]add[/b]     Idx_,#table   '$05+$10=$15>Idx_
                [b]movs[/b]    :inline,Idx_  'Replace 0-0 in :inline with Idx_=$15
                [b]nop[/b]                   'Pause for pipelining
    :inline     [b]mov[/b]     Idx_,0-0      'Table value at table addr $15=$20>Idx_
                [b]wrlong[/b]  Idx_,[b]par[/b]      'Return Idx_=$20
    
    


    Question: Where did Mike come up with the "0-0" in ":inline mov idx_, 0-0"? This is just a source place-holder that gets overwritten right? Why "0-0" and not something else? What else can be used in-place of 0-0.

    Thanks Ale, David
  • AleAle Posts: 2,363
    edited 2009-08-11 11:10
    0-0: As far as I know it is a nomenclature used since the days of the IBM 360 (maybe earlier?) to denote a field that is going to be replaced at run time, i.e. self-modifying code. Note that in the propeller's case it should be an address and not a literal (unless of course you need the value).

    Edit: your understanding is ok.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • DroneDrone Posts: 433
    edited 2009-08-11 11:25
    OK Ale, interesting lore! Thanks a lot for your help. David
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-11 17:59
    My own use of "0-0" derives from programming the IBM 1130/1800. It had a calling convention similar to that of the Prop, wherein the first word of a subroutine would receive the return address. That word was typically filled with "DC *-*", where "DC" stand for "define constant", and "*" is the "here" symbol, or current value of the program counter. The Propeller's first assembler did not have a "here" symbol, so I used "0-0" instead and have done so ever since. The assembler has a "here" symbol now: it's "$". Had it been available from the beginning, I would have used "$-$" instead of "0-0". But "0-0" is now so ingrained, I probably won't switch back.

    -Phil
  • DroneDrone Posts: 433
    edited 2009-08-15 10:41
    Hi Phil, Thanks for the clarification. It turns out V1.1 of the Propeller Manual states on page 44:
    Prop Manual V1.1 Pg. 44 said...
    $ Hexadecimal indicator, as in $1AF or assembly 'here' indicator; p 207.
    Unfortunately the referenced page 207 does not speak about PASM 'here' at all; that's the end of the subject. I tried $ and $-$ and even 0 in place of 0-0, all work. I think I'll use a single $ to match the manual and perhaps avoid possible confusion. Thanks again... David
  • BradCBradC Posts: 2,601
    edited 2009-08-15 11:11
    Drone said...
    Unfortunately the referenced page 207 does not speak about PASM 'here' at all; that's the end of the subject. I tried $ and $-$ and even 0 in place of 0-0, all work. I think I'll use a single $ to match the manual and perhaps avoid possible confusion. Thanks again... David

    I'd never given it any thought prior to this, and for what you are doing it probably does not matter, but
    $-$, 0_0, 0-0, 0 all equal zero (either as a constant - 0_0 - or evaluation - 0-0 / $-$), where $ is the current cog address.

    The PASM Here ($) was a late entry into the compiler and happened after the manual was written. In the 1.1 version it's documented on P298 in the last paragraph. Not the most logical place to find it as its not exclusive to the JMP instruction, but it's there.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lt's not particularly silly, is it?
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-08-15 11:18
    $-$ or 0-0 brings more attention to the fact that it is being set elsewhere and as Phil has said, this was a common method years ago. $ does not convey this fact as it could be meant to refer to the current location. I strongly suggest you adopt 0-0 or $-$. You will find 0-0 is quite common amongst the various objects posted.
    my 2 cents smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBladeProp, RamBlade, TwinBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80), MoCog (6809)
    · Search the Propeller forums (via Google)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • DroneDrone Posts: 433
    edited 2009-08-17 18:35
    BradC, Thanks for pointing out the further explanation in the V1.1 manual pg. 298. I would like $ vs. $-$, 0-0 to be documented further in the manual, but perhaps it is inappropriate (would've save me/us time though).

    Cluso99, Thanks for the reply. I agree with your approach. I will use 0-0 and document/comment in-detail what's going on if I release any PASM to the Wild.

    Phil, For what it's worth - I actually dealt with the IBM 1130 decades ago. I was asked to design and implement a parallel bus interface for the beast at a radio astronomy observatory. It wasn't too bad given the carts of excellent IBM hardware and software documentation at-hand. I implemented a discrete transistor design (really no other way back then). I seem to remember initially testing the interface by programming the 1130 in machine code via the switches on the front panel to ensure fastest bus speed; even though the 1130 had a keyboard/selectric ball-printer, removable HDD (8KB if memory serves), and huge page printer (stomper) plus card reader peripherals.

    Best Regards, David
Sign In or Register to comment.