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.
Ok,
In the listing he’s rotating left. I would think that would result in quicker times for the lower values.
I’m pretty sure there’s an error in my asm, as the example uses a different instruction to rotate with carry.
This is the same thing in BASIC but rotating right so the higher values should be found faster.
I’d be interested to enter a race with it.. just not sure some lines are converted the way I’d want them to.
Code:workword var word workbyte var workword.byte0 ‘ 1st byte bitcarry var workword.8 ‘ 9th bit bitcount var byte NCD8: bitcount = 8 ‘ mov l to w & w to f workbyte = portX ‘ mov l to w & w to f if workbyte = 0 then ‘ portX was zero goto whatawaste endif inloop: bitcount = bitcount - 1 ‘ decf workword = workword << 1 ‘ 2 x rrf with carry if bitcarry = 0 then ‘ btfss goto inloop ‘ goto endif return whatawaste: bitcount = 0 ‘ bsf return
Last edited by Art; - 8th March 2015 at 17:24.
Bookmarks