Use ROTATE rather than Divide or Multiply. If the sum is 2,4,8,16,32,64 etc... use ROTATE many times.
Use multiple for-next using Bytes rather than one for-next using a Word or Long loop variable.
Use a constant to set bits rather than a variable. PORTx.0 thru to PORTx.7 with a case statement uses more code but will be a lot faster than PORTx.variable
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When swapping nibbles in a byte variable, GCB supports the function "SWAP4". A macro is much faster, especially on a PIC, where it is literally 10 x faster. 1 instruction cycle vs 10 instruction cycles. On an AVR, the call to function and the return are eliminated making it faster as well.
(AVR section untested) .
Ideas here for making your code run faster.
1- goto
for c1=1 to 100
if var(c1)=var2 then var3=1
next
for c1=1 to 100
if var(c1)=var2 then goto endfornext
next
endfornext: var3=1
2-don't use and
if var1=5 and var2=20 then
if var1=5 then if var2=20 then
3-for next vs repeat
for ptr=1 to 100
next
ptr=1
repeat 100
ptr++
end repeat
4-thinking... more goto stuff... any ideas to add?
Last edit: stan cartwright 2022-04-29
Good tips. Cheers.
When swapping nibbles in a byte variable, GCB supports the function "SWAP4". A macro is much faster, especially on a PIC, where it is literally 10 x faster. 1 instruction cycle vs 10 instruction cycles. On an AVR, the call to function and the return are eliminated making it faster as well.
(AVR section untested) .
Nice, certainly couldn't be optimized any more than that.