look at NCD command to do what you asked, checkout AND && for your example, search for MASK: http://www.picbasic.co.uk/forum/show...highlight=mask
or you could use a lookup table
look at NCD command to do what you asked, checkout AND && for your example, search for MASK: http://www.picbasic.co.uk/forum/show...highlight=mask
or you could use a lookup table
Last edited by Archangel; - 1st March 2015 at 09:59.
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.
What PIC device?
sorry can't write PIC assembler but something like
WReg= 8
Rotate Left f through Carry, 1
jump on carry, done
dec WReg
Rotate Left f through Carry, 1
jump on carry, done
etc...
or maybe BTFSC - BitTest, skip if clear
George
To repeat, look up NCD in the manual. I think it does what you want.
Except he wants the fastest not the easiest.
This is what the NCD routine looks like in the pbppic18.lib file when stripping out the non runtime stuff:I'll say what I usually say which is that I pretty much suck at assembly language stuff but that looks pretty tight to me. Obviously the execution time will vary depending on how many times it has to iterate thru the loop before it finds a bit that is set. Then there are helper macros which puts the byte/Word in question into the correct register (R0) and so on, if interested they are in the pbppic18.mac file.Code:;**************************************************************** ;* NCD : Priority encode * ;* * ;* Input : R0 = 16 bit value * ;* Output : W = bit number * ;* * ;* Notes : * ;**************************************************************** NCD clrf R0 + 1 NCDL movwf R0 movlw 17 ; Set result ncdloop addlw -1 ; Count down result - sets C so loop will end rlcf R0, F ; Shift upper bit to carry rlcf R0 + 1, F bnc ncdloop ; If carry set then done goto DUNN
Is there a faster way? Perhaps but I'd give NCD a try and get some performance data on that first - otherwise you don't know what to beat (or if you even need to beet it) - IMHO of course.
/Henrik.
Bookmarks