Not wishing to be rude, but how can 255 iterations be quicker than NCD or the in-line assembler equivalent?
George
Not wishing to be rude, but how can 255 iterations be quicker than NCD or the in-line assembler equivalent?
George
As I see it, . . . . you only need 8 iterations with lookdown and using < or > as it jumps to the first "iteration" that tests as true.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
For those who are curios as to the testing results of NCD vs. Lookdown2 in the context of this discussion.
I ran the following code in the MPLAB Simulator.
and here are the results.Code:NCDSUB: for i = 0 to 255 mystatus = i ''Start MPLAB SIM Stopwatch mybyte = NCD mystatus ''Stop MPLAB SIM Stopwatch next i lcdout $FE,1,"NCD: ", idec mybyte pause 500 return LOOKSUB: for i = 0 to 255 mystatus = i ''Start MPLAB SIM Stopwatch lookdown2 mystatus, <= [%00000000, %00000001, %00000011, %00000111, %00001111, %00011111, %00111111, %01111111, %11111111], mybyte ''Stop MPLAB SIM Stopwatch next i lcdout,1, "Lookdown: ", idec mybyte pause 500 return
![]()
Regards,
TABSoft
Lookdown2 makes 2x code over lookup, have you tested to confirm? Thanks
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Best I can think of is 3 assembler instructions, but more time than 3 cycles of course.
Copy the port value to a byte, count how many times you shift the byte right until the byte is zero.
If those times are for a single value,
I think it would be better than either example to check each bit in a verbose fashion still in the compiler.
Code:bytevar var byte ‘ buffer byte for port bitnum var byte ‘ output bit number that was set bytevar = porta btfsc _bytevar ,07 goto labelone btfsc _bytevar ,06 goto labeltwo btfsc _bytevar ,05 ......
Or rotate left until carry is set:
It’s been a while for asm, and might not work straight up, but enough to get the idea.Code:bitcount var byte bytebuff var byte NCD8: bytebuff = portX clrf _bitcount bcf status ,C findbit: incf _bitcount rrf _bytebuff btfss status ,C goto findbit return
findbit: is currently an endless loop if the port is zero, so you’d need to check for zero at the beginning.
Bookmarks