Hippy,
Thanks for the two suggestions, both will be useful.
The timings I measured using the do-loop measure exactly the same as the if-goto coding for both the test = true and test = false cases so I can simplify my macro by removing the label parameter.
The readtable suggestion is also useful and I can use it to save a significant amount of time.
My original code:
Code:
pinsB = b0 / 4 | %000001 186.5 uS
pinsB = b0 * 4 | %000001 163.5 uS
Total 350 uS
Using readtable as you suggested loses out against the efficiency of being able to code multiple arithmetic & logical operations in a single statement:
Code:
b1 = b0 & $F0, ReadTable b1, pinsB 198.5 uS
b1 = b0 & $0F, ReadTable b1, pinsB 193.5 uS
Total 392 uS
However, once you got me thinking of how I might use readtable, I realized I could pre-calculate all the possible portB bit-patterns for one of the nibbles and my code would need just one readtable statement to output that nibble.
Choosing the high nibble, because the division is slower than the multiplication, I get a massive saving of 111 uS:
Code:
ReadTable b0, pinsB 75.5 uS
pinsB = b0 * 4 | %000001 163.5 uS
Total 239 uS
Table $00, ( %000001, %000101, %001001, %001101, %010001, %010101, %011001, %011101 )
Table $08, ( %100001, %100101, %101001, %101101, %110001, %110101, %111001, %111101 )
...
Table $F0, ( %000001, %000101, %001001, %001101, %010001, %010101, %011001, %011101 )
Table $F8, ( %100001, %100101, %101001, %101101, %110001, %110101, %111001, %111101 )
Bookmarks