sarahclark

Schneider Unity Pro indirect bit addressing

3 posts in this topic

I have to check 1024 (sequential) bits for change of state in any of the bits and record which bit changed.
I was going to do something like this:

A = ARRAY[0..63] OF INT (gives me 1024 bits to check)
B = ARRAY[0..63] OF INT (reference array to compare against)
WordIndex = INT
BitIndex = INT
Res = INT (record bit location)

FOR (WordIndex :=0 TO 63) DO
   FOR (BitIndex :=0 TO 15) DO
      IF A[WordIndex].[BitIndex] NE B[WordIndex].[BitIndex] THEN
         B[WordIndex].[BitIndex] := A[WordIndex].[BitIndex];
         Res := (WordIndex*16) + BitIndex;
         (other stuff) ;
      END_IF;
   END_FOR;
END_FOR;

Only problem is that Unity won't let me reference the bits in the word like this.
A[WordIndex].0 is fine, A[WordIndex].[BitIndex] is not.
Is my syntax wrong or is this not possible?

Share this post


Link to post
Share on other sites

This is not possible.

You must use mask for your case:

 

FOR (WordIndex :=0 TO 63) DO
   FOR (BitIndex :=0 TO 15) DO
      
wMask := SHL(16#0001, BitIndex );
      IF A[WordIndex] AND wMask  NE B[WordIndex] AND wMask  THEN
         B[WordIndex] :=(B[WordIndex] AND NOT wMask) OR (A[WordIndex] AND wMask) ;
         Res := (WordIndex*16) + BitIndex;
         (other stuff) ;
      END_IF;
   END_FOR;
END_FOR;

1 person likes this

Share this post


Link to post
Share on other sites

leon78, that's exactly what I was after. Thank you very much :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now