Search Bit

We will need to know what software you are using GX or IEC before we can help, and what do you mean from LSB to MSB.

LSB = Least Significant Bit
MSB = Most Significant Bit

He wants to search a 16 bit word from one end to the other and find the bit that is True (or False, I guess).
 
Still need to know which software version he is running. I suspect its quite late in India and we wont know till tomorrow. Thanks for the LSB/MSB info Tharon.
 
Try BON instruction this gives a check on specified bit status in a word although this may not be what you want, to check which bit is on i.e. step though bits in word till a bit is "1" then use a loop, load a 2 registers with 1
"WAnd" reg1 with the word if result <> 0 then this bit is set
multiply reg1 by 2 and add 1 to reg2 then try again.
when you reach 16 count then exit loop.
reg 2 will contain the bit No. that has the "1"
Sorry can't give you an example no Gx or IEC here at the moment
but it may go something like this:

mov k1 d1 // move 1 to D1 & D2
mov k1 d2
Label:p2 // jump back label
wand d1 d3 //and the word to check (D3) with D1
<> D3 K0 CJ P1 //if result <> 0 then bit must be set (D2 = bit no)jump to P1
mul D1 K2 // mask for next bit
ADD D2 K1 D2 //add the bit pointer
< D2 K16 CJ P2 //if bit pointer < 16 then jump back
Label:p1

there are many ways of checking for bits in a word you could shift one place to bit 0 then test this bit.
I'm sure someone here could knock up a quick bit of logic or check the instructions in the manual
 
Yes i wants to search a 16 bit word from one end(right) to the other and(left) also from left end to right end.

e.g if D0 = 0001 0101 0011 0100 (this 16 bit word i want to check)
Then i want result in D1=2 (bit search from right to left)
D2=3 or 12 (bit search from left to right)
 

Similar Topics

G
Hi Folks: I'm new to these online Q&A things, So please excuse my misspellings and use or lack of use of punctuation{or mispuncuation as the case...
Replies
11
Views
6,853
Searching edit zones within all routines and other criteria still says no results found, yet I still have the "edits present" indicator at the...
Replies
6
Views
253
I have an InTouch HMI that has PID parameters. I need to find what the PID values were in the past. I have backups from the past, but none...
Replies
48
Views
5,552
Good morning folks, I'm on a quest to find all of the references to the CurrentUserHasCode function in our project. I have the project...
Replies
2
Views
430
Need to learn a few more tricks in Proficy Machine Edition. I don't use it often, but one of the first things I usually do when getting into a new...
Replies
3
Views
1,018
Back
Top Bottom