Shop OBEX P1 Docs P2 Docs Learn Events
Passing PAR to assembly — Parallax Forums

Passing PAR to assembly

Hack SawHack Saw Posts: 3
edited 2008-10-15 13:22 in Propeller 1
Hello Everyone,

I am new to the propeller. I am quite proficient with the SX stuff, but my program has outgrown the space available in the SX so I am "upgrading" to the propeller.

Here is my question....

Runing spin is waaay to slow for my application. I have managed to get my high speed requirements to run in prop assembly, and my intention· is to let the slower less critical functions (vfd display,·some buttons, etc.)·run in spin on a different cog. I need to have my assembly code share main memory with my spin code.·I have been able to pass the address of a long to assembly using the PAR register as described in the manual on page 283. But, I need several words in my assembly code. I am using 1 long as 2 words now, but I would like to address thm seperately, and ultimately have more main memory available to be shared·between spin and·assembly.·I am sure this is easy, but I can't find anything in the manual about it.

Please help.

Comments

  • tpw_mantpw_man Posts: 276
    edited 2008-10-14 20:01
    What you can do is pass the address of a series of longs, and then increment the par register to sequentially access all the longs.

    var
    long data1, data2, data3
    
    pub main
    cognew(@asm, @data1)
    
    dat
    asm
    mov temp, par
    mov data1addr, temp
    add temp, #4
    <etc>
    wrlong mydata, data1addr
    <etc>
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
  • AleAle Posts: 2,363
    edited 2008-10-14 20:17
    Remember that words should be aligned to word boundaries (addresses divisible by 2) and long at long boundaries (addresses divisible by 4) wzhen reading or writing using either rd/wrword or long.
  • Hack SawHack Saw Posts: 3
    edited 2008-10-14 20:27
    Wow, it has suddendly become clear. I tried something like this last night, but where I failed was that I added #1 to the address passed by PAR and not #4. Thank you both for your quick and useful replies.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-15 01:20
    Remember that PAR is read-only. You can't really increment it. When PAR is used in the source field of an instruction, you get the register contents. When you use PAR in the destination field, you actually get the "shadow memory" location, the actual memory underlying that address rather than the PAR register itself.

    Typically, you move PAR to some other location and increment it there as needed.
  • potatoheadpotatohead Posts: 10,261
    edited 2008-10-15 05:00
    Also remember COG addressing is always in longs.

    First COG address is 0, second is 1, third is 2, etc...

    In the HUB, each atomic address is a byte!

    So,

    Say you've got a word, a long and two bytes, stored sequentially in the HUB. Pass the address of the word to PAR in the cognew.

    Then do:

    mov temp, PAR

    rdlong A, temp

    add temp, #4

    rdword B, temp

    add temp, #2

    rdbyte C, temp

    add temp, #1

    rdbyte D, temp.

    A,B,C,D are all longs in the COG, addressed sequentially thus:

    DAT

    A long 0 'holds a long
    B long 0 'long holds a word
    C long 0 'long holds a byte
    D long 0 'long holds another byte.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
  • Hack SawHack Saw Posts: 3
    edited 2008-10-15 12:47
    Thanks,

    So does this mean that in the case of 'C long holds a byte' that the byteis represented by the least significant 8 bits of C long and that the upper 24 bits are just wasted space?
  • BaggersBaggers Posts: 3,019
    edited 2008-10-15 13:22
    Yes, that's right, C is still a long but only had a byte ( least significant 8 bits ) read into it.
    Also if you want it to be signed, you'd have to then do the following to it, before doing anything to it.
       SHL C,#24
       SAR C,#24
    
    


    or for words
       SHL C,#16
       SAR C,#16
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
Sign In or Register to comment.