Shop OBEX P1 Docs P2 Docs Learn Events
Optimising ASM code, to read 6 sequential HUB held parameters, to COG local reg — Parallax Forums

Optimising ASM code, to read 6 sequential HUB held parameters, to COG local reg

m.r.b.m.r.b. Posts: 36
edited 2007-09-12 17:00 in Propeller 1
I have some code that works OK, to read 6 sequential LONG registers (parameters for the ASM routine) in the HUB, into 6 sequential LONG registers·(cog local copies) in the·COG running the ASM program.

I am doing in the old fashioned way, using RDLONG, with each COG register specifically named, and updating a pointer, originally referenced to the address passed by PAR·.. then by adding 4 after each read, to 'look' into the next HUB register.. and writing to the next named cog resister etc..

That's great... and works... but can I optimise using a loop and self modifying code, so the code is shorter/ more readable and better structured...

I was thinking, is this nearly there...

mov asmtemp,#6· '6 longs to copy
mov srcindex, PAR 'Pointer for reading from HUB longs @PAR & upwards
mov destindex, #destination 'destination pointer

:loop· movs :rdpar,srcindex
nop
nop
:rdpar rdlong destindex, #0

add srcindex,#4
add destindex,#4

djnz asmtempa, :loop

would that work??

Regards MRB

Comments

  • Ken PetersonKen Peterson Posts: 806
    edited 2007-09-11 12:32
    fix your typo and it might wink.gif
    djnz asmtempa, :loop <- typo

    why are you doing rdlong in immediate mode? can you do the following?:

    :rdpar rdlong destindex, srcindex

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-11 20:27
    Ken was just kidding smile.gif

    I was very explicite about two common issues in my tutorial
    (1) # is a part of the opcode, not of the operand. When you write #0 this error will not be mended by MOVS!!
    (2) COG cells are numbered one by one! So don't increment destindex by 4!
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-09-11 20:42
    @deSilva: Perhaps you should back off on the "!!". Seems like you're shouting at everyone. wink.gif

    I'm not sure what you mean by your (1) point. Does m.r.b. need to be using immediate mode, or is my example valid?

    By the way, it's easy to forget that cog memory is addressed by long. I know sooner or later I'll probably forget that fact again while I'm in the middle of coding something. It's always good to think of cog memory as a bank of long registers rather than memory locations to help keep that in mind. However, most processors don't load instructions from registers, so that fact makes this also hard to think of them as registers all the time and one can easily slip back into thinking of it as memory.

    Ken

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-11 21:04
    @Ken,
    Well, I already reduced capitalizing my phrases - please leave me the exclamation marks smile.gif

    @1: Yes, your objection is absolutely valid! But I asked myself: Why the hell is MRB using immediate mode?
    My temporary answer was: He doesn't want to; he thought that this would be changed by MOVS.
    Am I right?
  • KaioKaio Posts: 253
    edited 2007-09-12 09:45
    MRB,

    beside the comments from Ken and deSilva your code would not work as expected. The destination on RDXXXX is used to store the value and not used to point to an address to store the value.

    A possible solution could look like the following code.
    DAT
                            org     0
                  
                            mov     asmtemp,#6      '6 longs to copy
                            mov     srcptr,PAR
                            movd    :rdpar,#destination
                            nop
    :loop                                           
    :rdpar                  rdlong  0-0,srcptr
                            add     :rdpar,IncDest
                            add     srcptr,#4
                            djnz    asmtemp,#:loop
    
    IncDest                 long    1 << 9
    asmtemp                 res     1
    srcptr                  res     1
    destination             res     6               'your copy area
    
    



    Please have a look at the following thread where an optimization of reading or writing the hub RAM is discussed.
    http://forums.parallax.com/showthread.php?p=656005

    Thomas
  • m.r.b.m.r.b. Posts: 36
    edited 2007-09-12 11:21
    @DeSilva, yes, you are absolutely correct as to the immediate move...

    Yes, I thought, that it would be changed by MOVS/ MOVD instructions, because I thought that they·modifyed the S·and D fields respectively of·the code.

    I·coping quite well with what I need and want to do in ASM so far.. (migrated from PIC, Z80, AVR etc, for many years previously!!)

    Your ASM guide is great in getting started with Prop. ASM..
    For me, its a new microcontroller... New core,with new instruction set·and new 'snares/traps' etc to get over... the guide did help in getting started... Thanks!

    It would be nice to have some clear-cut documentation, or guide somewhere like....
    "A·'MOVS, MOVD usage clarification· ... And Moving data·(blocks)·and·copying data (blocks) within·COG memory etc' for dummies"
    it appears that I fell into one of those 'traps'

    I found the prop. manual is 'as clear as mud' when it comes to·the general use of·MOVS and MOVD, and·using them·for cog registers block copy/move etc!!
    (well, actually·move·would be·just a step up from copy... just copy source block to destination block, then erase the source block .. if you must!!!)


    Regards;
    MRB

    Post Edited (m.r.b.) : 9/12/2007 11:54:47 AM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-12 17:00
    I shall add all those things you ask for during the next weeks - I had been handicapped by a double work load of main job and preparations for an evening class.. Both activitities will ease up now, so I can spend more time for this.
Sign In or Register to comment.