this picaxe08M code isnot efficient

sdscott

New Member
How can I make this code segment more efficient to use less programming memory?
if b3=$2D then let b3=$0A
endif
if b4=$2D then let b4=$0A
endif
if b5=$2D then let b5=$0A
endif
if b3=$32 then let b3=$0F
endif
if b4=$32 then let b4=$0F
endif
if b5=$32 then let b5=$0F
endif

I cannot figure how to increment the working register as a variable,; b3-b5 to check for condition as hex $2D or $32 and change to corresponding value, $0A or $32, respectively.

I am trying for something like this;

FOR b13 = 3 to 5
if b(b13)=$2D then let b(b13)=$0A
if b(b13)=$32 then let b(b13)=$0F
Next b13



Thanks in advance.
D.
 

hippy

Ex-Staff (retired)
I don't think there's that much inefficient in the original. One alternative is -

Code:
For bPtr = 3 to 5
  If @bPtr = $2D Then : Let @bPtr = $0A : End If
  If @bPtr = $32 Then : Let @bPtr = $0F : End If
Next
There are a number of ways to optimise that. I would personally choose -

Code:
For bPtr = 3 to 5
  Select Case @bPtr
    Case $2D : Let @bPtr = $0A
    Case $32 : Let @bPtr = $0F
  End Select
Next
I haven't checked to see if they save any memory.
 

sdscott

New Member
I see that bPtr does not work with the older picaxe-08M mpu... What code would be equivalent for the first-gen M series?

D.
 

hippy

Ex-Staff (retired)
Sorry; hadn't noticed it was "M", not "M2".

I think you could be stuck with what you have. There might be some MIN or MAX trick depending on what values b3-b5 hold.
 

sdscott

New Member
Thanks again, Hippy. I was able to rework some of the other code in my project to lower memory to 250/256. As a challenge, I wanted to ensure the code was backward-compatible with 08M.

D.
 

hippy

Ex-Staff (retired)
You are more than welcome to post your full code. Others may be able see something which could deliver significant savings. I know that's not a priority when under the limits, but could inspire ideas that may help in future projects.
 
Top