View Full Version : Optimising ASM code, to read 6 sequential HUB held parameters, to COG local reg

09-11-2007, 06:59 PM
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
:rdpar rdlong destindex, #0

add srcindex,#4
add destindex,#4

djnz asmtempa, :loop

would that work??

Regards MRB

Ken Peterson
09-11-2007, 07:32 PM
fix your typo and it might http://forums.parallax.com/images/smilies/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?

09-12-2007, 03:27 AM
Ken was just kidding http://forums.parallax.com/images/smilies/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 Peterson
09-12-2007, 03:42 AM
@deSilva: Perhaps you should back off on the "!!". Seems like you're shouting at everyone. http://forums.parallax.com/images/smilies/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.



The more I know, the more I know I don't know.· Is this what they call Wisdom?

09-12-2007, 04:04 AM
Well, I already reduced capitalizing my phrases - please leave me the exclamation marks http://forums.parallax.com/images/smilies/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?

09-12-2007, 04:45 PM

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.

org 0

mov asmtemp,#6 '6 longs to copy
mov srcptr,PAR
movd :rdpar,#destination
: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.


09-12-2007, 06:21 PM
@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!!!)


Post Edited (m.r.b.) : 9/12/2007 11:54:47 AM GMT

09-13-2007, 12:00 AM
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.