News:

  • May 16, 2024, 11:42:56 PM

Login with username, password and session length

Author Topic: Bitmask Example  (Read 2999 times)

eman5oh

  • Full Member
  • ***
  • Posts: 45
Bitmask Example
« on: November 18, 2020, 10:02:32 AM »
I would love to see an example of how to do a bitmask in DoMore. I want to be able to evaluate individual bits in 8 or 16 bit memory location. Is anyone able to point me to an example?

Thanks

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 5996
  • Yes Pinky, Do-more will control the world!
Re: Bitmask Example
« Reply #1 on: November 18, 2020, 10:06:12 AM »
I would love to see an example of how to do a bitmask in DoMore. I want to be able to evaluate individual bits in 8 or 16 bit memory location. Is anyone able to point me to an example?

Thanks

Individual bits? Use a bit cast. Just add the bit number following a colon. For the low bit of D0, it would be D0:0. The highest bit would be D0:31.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

eman5oh

  • Full Member
  • ***
  • Posts: 45
Re: Bitmask Example
« Reply #2 on: November 18, 2020, 10:15:21 AM »
Thanks, I knew there was a simple solution to this. I found this after posting  https://forum.hosteng.com/index.php/topic,1804.0.html , it makes it even easier to do what I wanted, map the individual bits to C bits. DoMore rocks!

Thanks

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3666
    • Host Engineering
Re: Bitmask Example
« Reply #3 on: November 18, 2020, 12:37:39 PM »
Thanks, I knew there was a simple solution to this. I found this after posting  https://forum.hosteng.com/index.php/topic,1804.0.html , it makes it even easier to do what I wanted, map the individual bits to C bits. DoMore rocks!

Thanks

Yes, it's always best to implement the data in its smallest form, then use casts to look at it in larger data sizes, e.g. C0, C1, C10, address individual bits.  C0:UB C32:SD can then reference those bits as a BYTE or even a DWORD (although the BIT ID must be BYTE and DWORD aligned, respectively).

The big benefit is you can still do INDIRECT addressing at the bit level, e.g. C[V0] can reference any C bit just by tweaking V0 from 0 to 4095 (or however big your big block is).  Bit casts of larger data types cannot be done indirectly, e.g. D0:31 and D0:0 can NOT be accessed indirectly like D0:V0 and tweaking V0 to be 0..31.  This does NOT work.  Note that you CAN do C[V0]:UB, but V0 will byte alighn itself (i.e. V0 of 0..7 will be C0:UB, V0 of 8..15 will be C8:UB, etc.).

Hence, using bits (the smallest size you need to reference) as your "base" type, you can still cast LARGER DATA SIZEs AND get the benefits of INDIRECT ARRAY ADDRESSING.