home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / scan.seq < prev    next >
Text File  |  1991-03-25  |  2KB  |  74 lines

  1. \ SCANW.SEQ     Scan a list of words for a word         by Tom Zimmer
  2.  
  3. comment:
  4.  
  5.         Works like the normal SCAN, but scans a list of WORDS for a WORD.
  6.         That is you must divide the space to be searched by 2 to obtain
  7.         the length to search
  8.  
  9. comment;
  10.                                         \ a1 = scan start address
  11.                                         \ w1 = length to scan (words)
  12.                                         \ w2 = word we are looking for
  13.                                         \ a2 = address where w2 was found
  14.                                         \ w3 = remaining search length (WORDS)
  15. code  scanw     ( a1 w1 w2 --- a2 w3 )  \ Scan array a1 for word w2.
  16.                 pop ax          pop cx
  17.           cx<>0 if
  18.                     pop di          push es
  19.                     mov es, sseg
  20.                     repnz           scasw
  21.                     pop es
  22.                  0= if
  23.                     inc cx
  24.                     dec di          dec di
  25.                  then
  26.                     push di         push cx
  27.                     next
  28.             then                        \ zero search length exit
  29.                 push cx
  30.                 next
  31.                 end-code
  32.  
  33.  
  34. \ Scan for char BACKWARDS starting at addr+len, back through len bytes
  35. \ before addr, returning addr' and len' of char.
  36.  
  37. code -scan      ( addr len char -- addr' len' )
  38.                 pop ax          pop cx
  39.                 jcxz 0 $
  40.                 pop di
  41.                 mov dx, es      mov es, sseg
  42.                 std
  43.                 repnz           scasb
  44.                 cld
  45.                 mov es, dx
  46.              0= if
  47.                 inc cx          inc di
  48.              then
  49.                 push di         push cx
  50.                 next
  51.         0 $:    push cx         next            end-code
  52.  
  53. \ Skip occurances of char BACKWARDS starting at addr, back through
  54. \ addr-len, returning addr' and len' of char.
  55.  
  56. code -skip      ( addr len char -- addr' len' )
  57.                 pop ax          pop cx
  58.                 jcxz 0 $
  59.                 pop di
  60.                 mov dx, es      mov es, sseg
  61.                 std
  62.                 repz            scasb
  63.                 cld
  64.                 mov es, dx
  65.             0<> if
  66.                 inc cx          dec di
  67.             then
  68.                 push di         push cx
  69.                 next
  70.         0 $:    push cx         next            end-code
  71.  
  72.  
  73.  
  74.