Quick way to peek/poke large amount of bytes? - 20M2

Chris Kelly

Well-known member
Hi guys

I'm using a 20M2 at present. Is there an efficient way to copy values from 128 RAM addresses into another 128 addresses?

e.g copy addresses 32 through 159 into addresses 160 through 287?

I get that it will work fine by using for example

Code:
    peek 32,b22
    poke 160,b22
    peek 33,b22
    poke 161,b22
    peek 34,b22
    poke 162,b22
    peek 35,b22
    poke 163,b22
    peek 36,b22
    poke 164,b22
and so on....

But that looks a bit cumbersome.

Just wondered if there is a more concise trick?

Cheers

Chris
 

hippy

Technical Support
Staff member
An alternative which uses only one byte variable -
Code:
For bPtr = 32 To 159
  b0    = @bPtr : bPtr = bPtr + 128 ; +128 = - 32 + 160 
  @bPtr = b0    : bPtr = bPtr - 128 ; -128 = + 32 - 160
Next
Not sure if it's actually quicker than lbenson's version though.
 

AllyCat

Senior Member
Hi,

In theory, the following would be even faster (because @BPTRINC executes in exactly the same time as @BPTR). But you may need to check for bugs (with a "real" PICaxe chip) because there are some "known issues" with the handling of the @BPTRINC operator/variable in the more complex expressions. :(
Code:
Bptr=160
For b22 = 32 to 159
  Peek b22, @bptrinc
Next b22
You might also speed up the code even more by repeating the "data transfer" instuction(s) several times within the loop (which tends to be the slowest operation), adjusting the variable values accordingly, of course.

Cheers, Alan.
 

lbenson

Senior Member
AllyCat--that was what I was looking for, but couldn't remember how to do it. Thanks. So obvious once you see it.
"known issues" with the handling of the @BPTRINC operator/variable in the more complex expressions.
Good caveat, but I wouldn't have considered this to be one of the "more complex expessions", and have never noted a problem with this particular type use of @bptrinc.
 
Top