Home |  About Us |  Help |  Site Map |  Contact
Assembly Snippet Reverse Odometer Bit Subset
Design Criteria : speed / size

; *** Iterate through all combinations of a fixed
; ***  number of bits in reverse order

bitOdom2 proc STDCALL bitCount:DWORD, highBit:DWORD

  sub  edx,edx      ; zero to bit pattern
  mov  eax,bitCount ; number of bits in pattern
  bts  edx,eax      ; set the nth bit on
  dec  edx          ; number of required bits on
next:
  sub  ecx,ecx      ; zero a back counter
  mov  ebx,highBit  ; number of bits in pattern
lp00:
  inc  ecx          ; increment the back counter
  bsr  eax,edx      ; bit search right
  je   noBits       ; no bits left
  btr  edx,eax      ; reset the left most bit
  inc  eax          ; point to next bit left
  dec  ebx          ; reduce the highest bit position
  cmp  ebx,eax      ; compare current high to bit pos
  jc   lp00         ; loop if bit outside range
lp01:
  bts  edx,eax      ; set one bit on in new position
  inc  eax          ; next hightest bit position
  loop lp01         ; dec back count, loop if not zero

; *** odometer values incremented and correct
  nop               ; action to be taken

  jmp  next         ; loop and get next bit pattern
noBits: ret

bitOdom2 endp
pseudocode
bitCount = number of bits in odometer
highBit = highest bit number

odom = ( 2 ^ highBit ) -1
do
  high = highBit
  count = 0
  do
    increment count
    index leftmost 1 bit in odom
    set indexed bit to 0 in odom
    decrement high
    increment index
  loop while index > high and odom > 0
  if odom > 0
    do
      set the indexed bit on in odom
      increment index
      decrement count
    loop while count > 0

rem action to be taken

  end if
loop while odom > 0
More

Related




Home |  About Us |  Help |  Site Map |  Contact