home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / ifindbyt.asm < prev    next >
Assembly Source File  |  1988-08-28  |  4KB  |  105 lines

  1.  
  2. ;   FILENAME: IFINDBYT.ASM
  3. ;
  4. ;   Copyright (c) 1988 by Borland International, Inc.
  5. ;
  6. ;   DESCRIPTION: This module implements two routines. The first,
  7. ;   GetASCIIZStrLen is simply an alternate entry point into the main routine
  8. ;   FindBytePos. FindBytePos determines the position of an unsigned byte value
  9. ;   in an array of bytes. This module uses IDEAL mode syntax.
  10. ;
  11. ;   ASSEMBLY INSTRUCTIONS: To assemble this module use the following
  12. ;   TASM command line.
  13. ;
  14. ;       TASM /dMDL=memorymodel ifindbyt
  15. ;
  16. ;   'memorymodel' in the above command line may be replaced by TINY, SMALL,
  17. ;   MEDIUM, COMPACT, LARGE or HUGE.
  18. ;
  19.  
  20. %tabsize 4
  21.  
  22. ifndef  MDL
  23.     display "Error: This module requires that you provide a memory model"
  24.     display "       definition on the command line. I.E. /dMDL=SMALL."
  25.     err ; Force a fatal error
  26. else
  27.  
  28.     ideal                           ; Use TASM's Ideal mode
  29.     model   MDL             ; Define the memory model
  30.  
  31.     codeseg
  32.  
  33.     global  FindBytePos:proc        ; Define public proc's
  34.     global  GetASCIIZStrLen:proc
  35.  
  36.  
  37.     label GetASCIIZStrLen proc
  38.  
  39.     ;   This label is used as an alternate entry point into the
  40.     ;   routine FindBytePos. By initializing ax and cx appropriately we
  41.     ;   take advantage of the code in FindBytePos and gain another sub-routine.
  42.     ;
  43.     ;   The routine returns the length of an ASCIIZ string including the
  44.     ;   termintating length byte.
  45.     ;
  46.     ;   Input
  47.     ;       ArrayPtr - far pointer to byte array
  48.     ;   Output
  49.     ;       cx <> 0
  50.     ;           cx - Number of bytes left to search in array
  51.     ;           es:di - Segment:Offset+1  of the byte value searched for
  52.     ;       cx = 0 - Byte value couldn't be found.
  53.     ;       ax - Number of bytes searched
  54.     ;       es:di - points to one byte past the last byte checked
  55.     ;   Calling convention
  56.     ;       Pascal
  57.     ;   Registers modified
  58.     ;       ax, bx, cx, di, es, Flags
  59.  
  60.         mov     al, 0           ; Look for the termianting null character
  61.         mov     cx, 0FFFFh      ; Search a max 64K characters
  62.  
  63.     proc    FindBytePos
  64.  
  65.     ;   This function returns the position+1 in the indicated array of the
  66.     ;   byte value in al. Note that this routine assumes that the pointer
  67.     ;   passed to it is normalized if the array being searched is longer
  68.     ;   than 0FFF0h bytes.
  69.     ;
  70.     ;   Input
  71.     ;       ArrayPtr - far pointer to byte array
  72.     ;       al - unsigned byte value to search for
  73.     ;       cx - maximum number of bytes to search.
  74.     ;   Output
  75.     ;       cx <> 0
  76.     ;           cx - Number of bytes left to search in array
  77.     ;           es:di - Segment:Offset+1  of the byte value searched for
  78.     ;       cx = 0 - Byte value couldn't be found.
  79.     ;       ax - Number of bytes searched
  80.     ;       es:di - points to one byte past the last byte checked
  81.     ;   Calling convention
  82.     ;       Pascal
  83.     ;   Registers modified
  84.     ;       ax, bx, cx, di, es, Flags
  85.  
  86.     arg ArrayPtr:dword=ParmSize    ; Define parameter passed on stack
  87.  
  88.         push    bp                  ; Set up the stack to access parameters
  89.         mov     bp, sp
  90.         les     di, [ArrayPtr]      ; Get the address of the array to search
  91.         cld                         ; Search from low address to high address
  92.         mov     bx, di              ; Store the address of the beginning of the
  93.                                     ; array
  94.         repne   scasb               ; Find the byte if it exists
  95.         mov     ax, di              ; Move the position pointer into ax
  96.         sub     ax, bx              ; Calculate the number of bytes searched
  97.         pop     bp                  ; Restore the stack pointer
  98.         ret     ParmSize            ; Clean up stack since we're using Pascal
  99.                                     ; calling conventions.
  100.     endp    FindBytePos
  101.  
  102. endif   ; ifndef MDL
  103.  
  104. end
  105.