Hi, I just hacked out some extra macros for using BITS instead of FLAGS (ie LOCAL IsFound : DWORD) in by programs and thought i would share them:

     CHECKBIT MACRO data:REQ, bit:REQ
        mov eax, data
        push ebx
        push ecx
        mov ecx, bit
        dec ecx
        mov ebx, 1
        shl ebx, cl
        and eax, ebx
        shr eax, cl
        pop ecx
        pop ebx
     ENDM
     
     SETBIT MACRO data:REQ, bit:REQ
        push eax
        push ebx
        push ecx
        lea eax, data
        mov ecx, bit
        dec ecx
        mov ebx, 1
        shl ebx, cl
        or , ebx
        pop ecx
        pop ebx
        pop eax
     ENDM   
     
     CLEARBIT MACRO data:REQ, bit:REQ
        push eax
        push ebx
        push ecx
        lea eax, data
        mov ecx, bit
        dec ecx
        mov ebx, 1
        shl ebx, cl
        xor ebx, 0FFFFFFFFh
        and , ebx
        pop ecx
        pop ebx
        pop eax
     ENDM   

As you can see, CHECKBIT is the only one that will change a register (EAX), and will return 1 (TRUE) if the bit is set (1) or a 0 (FLASE) if the bit is set 0. All three are '1' based, meaning the bit value can not be 0. So a DWORD has bits 1 through 32. These greatly reduce the memory used for flags, as a DWORD takes up 4 bytes to hold a one bit representation. Instead, make some equates like so:

IsOn    equ 1
Running equ 2
FLAGE3  equ 3

.data 
   FLAGS  dd 0

.code
   ...
   CHECKBIT FLAGS, IsOn
   .if(eax)
      SETBIT FLAGS, Running  
   .endif
This basically asks, if IsOn, then Set Running... Anywho, i know its basic, but its worth having, I hope you like...:D NaN This message was edited by NaN, on 3/18/2001 8:40:44 PM
Posted on 2001-03-18 18:25:00 by NaN
Why not?:

IsOn    equ 00001y
Running equ 00010y
FLAGE3  equ 00100y

.data 
   FLAGS  dd 0

.code
   ...
   .if(FLAGS and IsOn)
      or FLAGS, Running
   .endif
bitRAKE
Posted on 2001-03-18 23:18:00 by bitRAKE

   D  O  H  !  !
Now i feel dumb.... lol! :) Thanx BitRAKE for pointing out such an oversite.. i went coding happy and didnt stop to think it thu better... To answer your question, i would say nothing. Except, maybe clearing a bit, as you would need to invert the equated name and then perform the AND on it. But none the less, even this is far more efficient than my earlier macros... Thanx again for pointing this out. NaN
Posted on 2001-03-18 23:48:00 by NaN
Ok, just so i can still hold face on such an oversite i have updated my earlier code to the more simple set: NOTE: one assumption, YOU MUST DECLAIR A DOUBLE CALLED 'DATA' (in caps)

     SETBIT MACRO data:REQ
        or DATA, data
     ENDM
     
     CLEARBIT MACRO data:REQ
        push eax
        mov eax, data
        xor eax, 0FFFFFFFFh
        and DATA, eax
        pop eax
     ENDM
     
     IF_FLAGGED MACRO bit:REQ
          mov eax, bit
          .if ( eax & DATA )
     ENDM     

     IF_NOT_FLAGGED MACRO bit:REQ
          mov eax, bit
          .if !( eax & DATA )
     ENDM     
Again, its use:


IsOn     equ 1b
Running  equ 10b
IsRed    equ 100b

.data
    DATA dd 0

.code

    IF_FLAGGED IsOn
       SETBIT Running
    .endif
   
    ...

    IF_NOT_FLAGGED IsRed
        CLEAR BIT Running
    .endif    
Again, thanx BitRAKE for your observations. NaN
Posted on 2001-03-19 00:27:00 by NaN
That's the great thing about MACROs - you can create your own language fairly easy. I've been trying to look at the common practices that are used in trying to write larger applications with ASM/Win32/COM, and from that knowledge create MACROs that extend the language to make MASM a greater tool (and improve my knowledge of MASM). One example is the 'mmov' MACRO I posted earlier. I think I'm going to change the name to 'mv', because it's used so much :) We really need a common set of tools to work with and build on. Hutch has created a great start for us all to build on. Ernie has went to great lengths to add COM tools to that. Iczelion has provided free documentation for the beginner - which was very much needed. These things have been catalysts to keep assembly a language to use. I'm still getting funny looks from other programmers when I say I prefer to program in assembly, but hopefully that won't always be the case :) bitRAKE
Posted on 2001-03-19 14:33:00 by bitRAKE
Well said... BTW: I used Svin's clocking code on the improvement verses my first draft and found your suggestion halfed the clocks on average from 10 to 5 in every case. As well i saved one clock by replacing: xor eax, 0FFFFFFFFh, with not eax So they are fairly optomal now. As well, i added a set of equates to the macro file:

     BIT1      equ 00000001h
     BIT2      equ 00000002h
     BIT3      equ 00000004h
     BIT4      equ 00000008h
     BIT5      equ 00000010h
     BIT6      equ 00000020h
     BIT7      equ 00000040h
     BIT8      equ 00000080h
     BIT9      equ 00000100h
     BIT10     equ 00000200h
     BIT11     equ 00000400h
     BIT12     equ 00000800h
     BIT13     equ 00001000h
     BIT14     equ 00002000h
     BIT15     equ 00004000h
     BIT16     equ 00008000h
     BIT17     equ 00010000h
     BIT18     equ 00020000h
     BIT19     equ 00040000h
     BIT20     equ 00080000h
     BIT21     equ 00100000h
     BIT22     equ 00200000h
     BIT23     equ 00400000h
     BIT24     equ 00800000h
     BIT25     equ 01000000h
     BIT26     equ 02000000h
     BIT27     equ 04000000h
     BIT28     equ 08000000h
     BIT29     equ 10000000h
     BIT30     equ 20000000h
     BIT31     equ 40000000h
     BIT32     equ 80000000h
This makes it easier to define in my code flags in the way you suggested by simply going: IsRunning equ BIT2 and use IsRunning as a Flag... NaN This message was edited by NaN, on 3/20/2001 1:05:08 AM
Posted on 2001-03-19 20:21:00 by NaN