Applying mask to long
escher
Posts: 138
This is a conceptual question but I'm having an issue applying a solution in ASM:
If you have let's say a WORD:
1010101010101010
And you want to set some bits in a LONG, via a mask such as:
00000000001111111111111111000000
So that the LONG reads:
00000000001010101010101010000000
Without affecting any bits not specified by the mask, and appropriately toggling those IN the mask from 1-> 0 or 0 -> 1 as necessary.
I've bashed out a bunch of different attempted solutions but they've all had caveats or corner cases or been simply bad.
Do I HAVE to perform an OR operation to set the high bits, and an ANDN to set the low bits, separately?
Thank you!
If you have let's say a WORD:
1010101010101010
And you want to set some bits in a LONG, via a mask such as:
00000000001111111111111111000000
So that the LONG reads:
00000000001010101010101010000000
Without affecting any bits not specified by the mask, and appropriately toggling those IN the mask from 1-> 0 or 0 -> 1 as necessary.
I've bashed out a bunch of different attempted solutions but they've all had caveats or corner cases or been simply bad.
Do I HAVE to perform an OR operation to set the high bits, and an ANDN to set the low bits, separately?
Thank you!
Comments
It is a two operation process to define a subset, but if you want to avoid an interim illegal value, (eg all low or all hi on a port) you can use XOR-AND-XOR
Can you elaborate on XOR-AND-XOR?
Usually inside a Pasm-Cog you 'filter/mask' outa anyways by using dira to explicit declare pins as output, so interim values are not really a problem.
Not sure about XOR-AND-XOR either.
Enjoy!
Mike
If the destination is just some internal RAM that does not need atomic changes, the OR ANDN is ok.