home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / zendisk2.zip / LST13-26.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  77 lines

  1. ;
  2. ; *** Listing 13-26 ***
  3. ;
  4. ; Replacement code for ClearHighBits in Listing 13-25.
  5. ; This version performs 64K rather than 0 repetitions
  6. ; when CX is 0.
  7. ;----------------------------------------------------------
  8. ; Clears the high bit of each byte in an array.
  9. ;
  10. ; Input:
  11. ;    BX = pointer to the start of the array to clear
  12. ;    CX = number of bytes to clear (0 means 64K)
  13. ;
  14. ; Output: none
  15. ;
  16. ; Registers altered: AX, BX, CX, DX
  17. ;
  18. ClearHighBits:
  19. ;
  20. ; Calculate the offset in the partial in-line code to which
  21. ; to jump in order to perform CX modulo 4 repetitions (the
  22. ; remaining repetitions will be handled by full passes
  23. ; through the loop).
  24. ;
  25.     dec    cx    ;# of reps - 1, since 1 to 4
  26.             ; (rather than 0 to 3) repetitions
  27.             ; are performed on the first,
  28.             ; possibly partial pass through
  29.             ; the loop
  30.             
  31.     mov    ax,cx
  32.     and    ax,3    ;# of repetitions modulo 4
  33.     inc    ax    ;(# of reps modulo 4)+1 in order to
  34.             ; perform 1 to 4 repetitions on the
  35.             ; first, possibly partial pass
  36.             ; through the loop
  37.     mov    dx,ax
  38.     shl    ax,1
  39.     add    ax,dx    ;(((# of reps - 1) modulo 4)+1)*3
  40.             ; is the # of bytes from the
  41.             ; the end of the partial
  42.             ; in-line code to branch to
  43.             ; in order to handle the
  44.             ; # of repetitions that
  45.             ; must be handled in the
  46.             ; first, possibly partial
  47.             ; loop
  48.     mov    dx,offset InLineBitClearEnd
  49.     sub    dx,ax    ;point back just enough
  50.                  ; instruction bytes from
  51.                  ; the end of the in-line
  52.                  ; code to perform the
  53.                  ; desired # of repetitions
  54.     shr    cx,1     ;divide by 4, since we'll do
  55.     shr    cx,1     ; 4 repetitions per loop
  56.     inc    cx       ;account for the first,
  57.                  ; possibly partial pass
  58.                  ; through the loop
  59.     mov    al,not 80h
  60.             ;pattern with which to clear
  61.             ; high bits
  62.     jmp    dx    ;finally, branch to perform
  63.             ; the desired # of repetitions
  64. ;
  65. ; Partial in-line code to clear the high bits of 4 bytes per
  66. ; pass through the loop.
  67. ;
  68. ClearHighBitsLoop:
  69.     rept    4
  70.     and    [bx],al        ;clear the high bit of this
  71.                 ; byte
  72.     inc    bx        ;point to the next byte
  73.     endm
  74. InLineBitClearEnd:
  75.     loop    ClearHighBitsLoop
  76.     ret
  77.