Memory move, saving CPU cycles

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Memory move, saving CPU cycles

2,386件の閲覧回数
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
ラベル(1)
0 件の賞賛
返信
4 返答(返信)

1,036件の閲覧回数
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 件の賞賛
返信

1,036件の閲覧回数
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 件の賞賛
返信

1,036件の閲覧回数
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 件の賞賛
返信

1,036件の閲覧回数
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 件の賞賛
返信