Home |  About Us |  Help |  Site Map |  Contact
Assembly Snippet Fast Byte Odometer
Design Criteria : speed

; *** Iterate through all non unique byte values
; *** less than 254 of any quantity
; *** buffer multple of 4 and zero terminated

byteOdom proc STDCALL buff:DWORD,qty:DWORD,range:DWORD

  push edi             ; push edi onto the stack
  mov  edi,buff        ; address of odomoeter values
  mov  edx,256         ; highest byte value+1
  sub  edx,range       ; byte range n to 255
  mov  ecx,qty         ; number of bytes in odometer
lp00:
  mov  [edi+ecx-1],dl  ; initialize one byte in buffer
  loop lp00            ; decement ecx and loop till zero
  dec  byte ptr [edi]  ; start with -1 for first iteration
next:
  sub  ebx,ebx         ; zero a forward dword offset
lp01:
  mov  eax,ebx         ; working dword offset
  inc  ebx             ; point to next dword
  inc  dword ptr [edi+eax*4] ; increment dword
  je   lp01            ; loop if these 4 expired to zero
  sub  ebx,ebx         ; byte offset forward pointer
lp02:
  mov  eax,ebx         ; working byte offset pointer
  inc  ebx             ; point to next byte
  cmp  [edi+eax],dl    ; compare byte to lowest byte value
  jc   notOk           ; jump if byte not within valid range

; *** odometer values incremented and correct
  mov  eax,[edi]       ; get least significant odometer byte
  sub  eax,edx         ; normalize to get the value
  nop                  ; action to be taken

  jmp  next            ; loop and increment the odometer
notOk:
  cmp  byte ptr [edi+eax],0 ; compare byte to zero
  mov  byte ptr [edi+eax],dl ; reset byte to lowest value
  je   lp02            ; loop and check next byte
  pop  edi
  ret

byteOdom endp

pseudocode
let lowValue = 256 - odometer range
fill an array of quantity elements with lowValue
do
  do
    increment 4 array elements little endian with carry
    point to next 4 array elements
  loop while incremented elements all equal zero

  for each element in array
    if element = 0
      element = lowValue
    end if
  loop while element > 1

  if element > 1
    value = array[0 to odometer range] - lowValue
rem action to be taken

  endif
while element > 1
More

Related




Home |  About Us |  Help |  Site Map |  Contact