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

  1. ;
  2. ; *** Listing 13-23 ***
  3. ;
  4. ; Zeros the high-bit of each byte in a 100-byte array,
  5. ; using branched-to in-line code.
  6. ;
  7.     jmp    Skip
  8. ;
  9. MAXIMUM_ARRAY_LENGTH    equ    200
  10. ARRAY_LENGTH    equ    100
  11. ByteArray    label    byte
  12.     db    ARRAY_LENGTH dup (80h)
  13. ;
  14. ; Clears the high bit of each byte in an array.
  15. ;
  16. ; Input:
  17. ;    BX = pointer to the start of the array to clear
  18. ;    CX = number of bytes to clear (no greater than
  19. ;        MAXIMUM_ARRAY_LENGTH)
  20. ;
  21. ; Output: none
  22. ;
  23. ; Registers altered: AX, BX, CX
  24. ;
  25. ClearHighBits:
  26. ;
  27. ; Calculate the offset in the in-line code to which to jump
  28. ; in order to get the desired number of repetitions.
  29. ;
  30.     mov    al,InLineBitClearEnd-SingleRepetitionStart
  31.                 ;# of bytes per single
  32.                 ; repetition of
  33.                 ; AND [BX],AL/INC BX
  34.     mul    cl        ;# of code bytes in the # of
  35.                 ; repetitions desired
  36.     mov    cx,offset InLineBitClearEnd
  37.     sub    cx,ax        ;point back just enough
  38.                 ; instruction bytes from
  39.                 ; the end of the in-line
  40.                 ; code to perform the
  41.                 ; desired # of repetitions
  42.     mov    al,not 80h    ;pattern to clear high bits
  43.                 ; with
  44.     jmp    cx        ;finally, branch to perform
  45.                 ; the desired # of
  46.                 ; repetitions
  47. ;
  48. ; In-line code to clear the high bits of up to the maximum #
  49. ; of bytes.
  50. ;
  51.     rept    MAXIMUM_ARRAY_LENGTH-1
  52.                 ;maximum # of bytes to clear
  53.                 ; less 1
  54.     and    [bx],al        ;clear the high bit of this
  55.                 ; byte
  56.     inc    bx        ;point to the next byte
  57.     endm
  58. SingleRepetitionStart:        ;a single repetition of the
  59.                 ; loop code, so we can
  60.                 ; calculate the length of
  61.                 ; a single repetition
  62.     and    [bx],dl        ;clear the high bit of this
  63.                        ; byte
  64.     inc    bx             ;point to the next byte
  65. InLineBitClearEnd:
  66.     ret
  67. ;
  68. Skip:
  69.     call    ZTimerOn
  70.     mov    bx,offset ByteArray
  71.                 ;array in which to clear
  72.                 ; high bits
  73.     mov    cx,ARRAY_LENGTH    ;# of bytes to clear
  74.                 ; (always less than
  75.                 ; MAXIMUM_ARRAY_LENGTH)
  76.     call    ClearHighBits    ;clear the high bits of the
  77.                 ; bytes
  78.     call    ZTimerOff
  79.