Optimising ASM code, to read 6 sequential HUB held parameters, to COG local reg
m.r.b.
Posts: 36
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
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
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?
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!
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?
Well, I already reduced capitalizing my phrases - please leave me the exclamation marks
@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?
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.
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
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