Memory move, saving CPU cycles

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Memory move, saving CPU cycles

2,384 Views
Bloodhound
Contributor I
Hi All,
 
Just looking a the crude method I've used to transfer a message from a CAN Rx buffer into a RAM buffer.
Something like this below uses over 90 cycles....
 
        lda   MSCANRXBUF
        sta   CANRxBuffer             
        lda   MSCANRXBUF+1
        sta   CANRxBuffer+1
        lda   MSCANRXBUF+2
        sta   CANRxBuffer+2       
        ...
        ...
        lda   MSCANRXBUF+12
        sta   CANRxBuffer+12
 
Now I guess I could set up memory pointers and increment them in a loop, but, in the end am I actually going to save any CPU cycles looping around to still use the same commands anyway?
I don't have any efficient loop routines, but maybe someone has an example on how much more efficient a memory transfer loop might be when only dealing with a relatively small memory transfer.
 
Thanks,
Ross
Labels (1)
0 Kudos
Reply
4 Replies

1,034 Views
peg
Senior Contributor IV
Hi Ross,

Looping only saves code space it doesn't help with execution speed.
You can extract a slight speed improvement in cases where both the source and destination are direct page or one or the other is by using the MOV instruction.
It reads better using MOV as well.

0 Kudos
Reply

1,034 Views
Bloodhound
Contributor I
Thanks Peg,
 
I agree totally on the MOV instruction, but, unfortunately with the MSCAN buffer sitting at $0540 it needs to use H:X to perform a MOV, still, the MOV ,X+,opr8a is only 5 cylces and a couple to set up H:X, so I'm better off with that.
 
Cheers,
Ross
 
0 Kudos
Reply

1,034 Views
bigmac
Specialist III
Hello Ross,
 
Here is a comparison of three potential methods, for the transfer of N bytes, assuming the RAM buffer is within page zero (which it needs to be for the MOV method to work) -
 
Indexed loop method:
Cycles:  11*N + 3
Bytes:   10
 
LDA/STA method:
Cycles:  7*N
Bytes:   5*N
 
Indexed MOV method:
Cycles:  5*N + 3
Bytes:   2*N + 3
 
Regards,
Mac
 


Message Edited by bigmac on 2007-12-10 02:52 AM
0 Kudos
Reply

1,034 Views
kef
Specialist I
Extended addressing mode  LDA  + STA  takes 8 cycles, 8cycles/byte
 
LDHX  + STHX pair takes 10cycles but transfers 2 bytes, so you could have 5cycles/byte.
 
 
0 Kudos
Reply