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

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