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

  1.  
  2. ;   FILENAME: ILOCSTRG.ASM
  3. ;
  4. ;   Copyright (c) 1988 by Borland International
  5. ;
  6. ;   DESCRIPTION: This module implements a routine that searches the current
  7. ;   data segment looking for the nth string. The strings must be in Turbo
  8. ;   Pascal format(i.e. must have a preceeding length byte) and must be
  9. ;   consecutive.
  10. ;
  11. ;   ASSEMBLY INSTRUCTIONS: To assemble this module use the following
  12. ;   TASM command line.
  13. ;
  14. ;       TASM /dMDL=memorymodel ilocstrg
  15. ;
  16. ;   'memorymodel' in the above command line may be replaced by TINY, SMALL,
  17. ;   MEDIUM, COMPACT, LARGE or HUGE. If assembling this module to run on
  18. ;   a 286/386 machine, turn on the P286 directive in order to take advantage
  19. ;   of 286/386 specific instructions. For example:
  20. ;
  21. ;       TASM /dMDL=memorymodel /jP286 ilocstrg
  22.  
  23. %tabsize 4
  24.  
  25. ifndef  MDL
  26.     display "Error: This module requires that you provide a memory model"
  27.     display "       definition on the command line. I.E. /dMDL=SMALL."
  28.     err ; Force a fatal error
  29. else
  30.  
  31.     ideal               ; Use TASM's Ideal mode
  32.     model   MDL         ; Define the memory model
  33.  
  34.     include "imacros.mac"
  35.     include "ibios.mac"
  36.     include "bios.inc"
  37.  
  38.     codeseg
  39.  
  40.     global  LocateString:proc       ; Declare public proc
  41.  
  42.     proc    LocateString
  43.  
  44.     ;   This procedure determines the offset of the error message referenced
  45.     ;   by the value in AX. It returns a near pointer to the string in di.
  46.     ;
  47.     ;   Input
  48.     ;       al - Message to find
  49.     ;       es:di - Far pointer to location to start search
  50.     ;   Output
  51.     ;       es:di - Far pointer to start of string
  52.     ;   Calling conventions
  53.     ;       NA
  54.     ;   Registers modified
  55.     ;       bl, cl, di, es, Flags
  56.  
  57.         mov     bl, 1               ; Use bl as a counter of how many strings
  58.                                     ; we've found
  59.         xor     cl, cl              ; Initialize cl
  60.  
  61.     NextString:
  62.         cmp     bl, al              ; Check if we've found the string we're
  63.         je      short Exit          ; looking for. If it is, leave.
  64.  
  65.         mov     cl, [BYTE es:di]    ; Get length byte of the next string
  66.         inc     cl
  67.  
  68.         ; Find the end of the string
  69.  
  70.     NextChar:
  71.         inc     di                  ; Point to the next character
  72.         loop    NextChar
  73.  
  74.         inc     bl                  ; Increment the string counter
  75.         jmp     NextString          ; Find the next string
  76.  
  77.     Exit:
  78.         ret
  79.     endp    LocateString
  80.  
  81. endif   ; ifndef MDL
  82.  
  83. end
  84.