home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / awk / awk320sr.zip / AWKFSTR.ASM < prev    next >
Assembly Source File  |  1991-04-25  |  7KB  |  394 lines

  1. ; far string operations
  2. ;
  3. ;  Copyright (C) 1988, 1989, 1990, 1991 by Rob Duff
  4. ;  All rights reserved
  5. ;
  6. _TEXT   SEGMENT PUBLIC WORD 'CODE'
  7.  
  8.         ASSUME  CS:_TEXT
  9.  
  10.         PUBLIC  _fstrstr
  11. _fstrstr PROC    NEAR
  12.         push    bp
  13.         mov     bp,sp
  14.         push    si
  15.         push    di
  16.         push    ds
  17.         cld
  18.  
  19.         les     di,[bp+8]
  20.         cmp     BYTE PTR es:[di],0
  21.         jnz     str01
  22.         mov     dx,[bp+6]
  23.         mov     ax,[bp+4]
  24.         jmp     short str06
  25.  
  26. str01:  les     di,[bp+4]
  27.         push    es
  28.  
  29.         mov     bx,di
  30.         xor     ax,ax
  31.         mov     cx,-1
  32.   repnz scasb
  33.         not     cx
  34.         mov     dx,cx
  35.  
  36.         les     di,[bp+8]
  37.         push    es
  38.  
  39.         mov     bp,di
  40.         xor     ax,ax
  41.         mov     cx,-1
  42.   repnz scasb
  43.         inc     cx
  44.         not     cx
  45.  
  46.         pop     ds
  47.         pop     es
  48.  
  49. str02:  mov     si,bp
  50.         lodsb
  51.         xchg    di,bx
  52.         xchg    cx,dx
  53.   repnz scasb
  54.         mov     bx,di
  55.  
  56.         jnz     str03
  57.         cmp     cx,dx
  58.         jnb     str04
  59. str03:  xor     bx,bx
  60.         mov     es,bx
  61.         mov     bx,1
  62.         jmp     short str05
  63.  
  64. str04:  xchg    cx,dx
  65.         jcxz    str05
  66.  
  67.         mov     ax,cx
  68.         dec     cx
  69.    repz cmpsb
  70.         mov     cx,ax
  71.         jnz     str02
  72.  
  73. str05:  mov     ax,bx
  74.         dec     ax
  75.         mov     dx,es
  76.  
  77. str06:  pop     ds
  78.         pop     di
  79.         pop     si
  80.         pop     bp
  81.         ret
  82. _fstrstr ENDP
  83.  
  84.         PUBLIC  _fstrcat
  85. _fstrcat PROC    NEAR
  86.         push    bp
  87.         mov     bp,sp
  88.         push    si
  89.         push    di
  90.         cld
  91.         push    ds
  92.  
  93.         les     di,[bp+4]
  94.         mov     dx,di
  95.         xor     al,al
  96.         mov     cx,-1
  97.   repnz scasb
  98.         push    es
  99.  
  100.         lea     si,[di-1]
  101.         les     di,[bp+8]
  102.         mov     cx,-1
  103.   repnz scasb
  104.         not     cx
  105.         sub     di,cx
  106.         push    es
  107.  
  108.         pop     ds
  109.         pop     es
  110.         xchg    si,di
  111.         test    si,1
  112.         jz      fstrcat
  113.         movsb
  114.         dec     cx
  115. fstrcat: shr     cx,1
  116.    repz movsw
  117.         adc     cx,cx
  118.     rep movsb
  119.  
  120.         mov     ax,dx
  121.         mov     dx,es
  122.  
  123.         pop     ds
  124.         pop     di
  125.         pop     si
  126.         pop     bp
  127.         ret
  128. _fstrcat ENDP
  129.  
  130.         PUBLIC  _fstrlen
  131. _fstrlen PROC    NEAR
  132.         push    bp
  133.         mov     bp,sp
  134.         push    si
  135.         push    di
  136.         cld
  137.  
  138.         les     di,[bp+4]
  139.         xor     al,al
  140.         mov     cx,-1
  141.   repnz scasb
  142.         mov     ax,cx
  143.         not     ax
  144.         dec     ax
  145.  
  146.         pop     di
  147.         pop     si
  148.         pop     bp
  149.         ret
  150. _fstrlen ENDP
  151.  
  152.         PUBLIC  _fstrchr
  153. _fstrchr PROC    NEAR
  154.         push    bp
  155.         mov     bp,sp
  156.         push    si
  157.         push    di
  158.         cld
  159.  
  160.         les     di,[bp+4]
  161.         xor     al,al
  162.         mov     cx,-1
  163.   repnz scasb
  164.         not     cx
  165.  
  166.         mov     al,[bp+8]
  167.         cmp     al,0
  168.         je      chr01
  169.         mov     di,[bp+4]
  170.   repnz scasb
  171.         jz      chr01
  172.  
  173.         xor     di,di
  174.         mov     es,di
  175.         inc     di
  176. chr01:
  177.         dec     di
  178.         mov     ax,di
  179.         mov     dx,es
  180.         pop     di
  181.         pop     si
  182.         pop     bp
  183.         ret
  184. _fstrchr ENDP
  185.  
  186.         PUBLIC  _fstrcmp
  187. _fstrcmp PROC    NEAR
  188.         push    bp
  189.         mov     bp,sp
  190.         push    si
  191.         push    di
  192.         mov     dx,ds
  193.         cld
  194.  
  195.         xor     ax,ax
  196.         mov     bx,ax
  197.         les     di,[bp+8]
  198.         mov     si,di
  199.         xor     al,al
  200.         mov     cx,-1
  201.   repnz scasb
  202.         not     cx
  203.  
  204.         mov     di,si
  205.         lds     si,[bp+4]
  206.    repz cmpsb
  207.  
  208.         mov     al,[si-1]
  209.         mov     bl,es:[di-1]
  210.         sub     ax,bx
  211.  
  212.         mov     ds,dx
  213.         pop     di
  214.         pop     si
  215.         pop     bp
  216.         ret
  217. _fstrcmp ENDP
  218.  
  219.         PUBLIC  _fstrcpy
  220. _fstrcpy PROC    NEAR
  221.         push    bp
  222.         mov     bp,sp
  223.         push    si
  224.         push    di
  225.         push    ds
  226.         cld
  227.  
  228.         les     di,[bp+8]
  229.         mov     si,di
  230.         xor     al,al
  231.         mov     cx,-1
  232.   repnz scasb
  233.         not     cx
  234.  
  235.         push    es
  236.         pop     ds
  237.         les     di,[bp+4]
  238.    repz movsb
  239.  
  240.         mov     dx,[bp+6]
  241.         mov     ax,[bp+4]
  242.  
  243.         pop     ds
  244.         pop     di
  245.         pop     si
  246.         pop     bp
  247.         ret
  248. _fstrcpy ENDP
  249.  
  250.         PUBLIC  _fstrncat
  251. _fstrncat PROC   NEAR
  252.         push    bp
  253.         mov     bp,sp
  254.         push    si
  255.         push    di
  256.         push    ds
  257.  
  258.         cld
  259.         xor     al,al
  260.  
  261.         les     di,[bp+8]
  262.         mov     cx,-1
  263.   repnz scasb
  264.         not     cx
  265.         dec     cx
  266.         mov     bx,cx
  267.  
  268.         les     di,[bp+4]
  269.         mov     cx,-1
  270.   repnz scasb
  271.         dec     di
  272.  
  273.         mov     cx,[bp+12]
  274.         cmp     cx,bx
  275.         jb      fstrncat
  276.         mov     cx,bx
  277. fstrncat:
  278.         lds     si,[bp+8]
  279.     rep movsb
  280.         stosb
  281.  
  282.         mov     dx,[bp+6]
  283.         mov     ax,[bp+4]
  284.  
  285.         pop     ds
  286.         pop     di
  287.         pop     si
  288.         pop     bp
  289.         ret
  290. _fstrncat ENDP
  291.  
  292.         PUBLIC  _fstrncpy
  293. _fstrncpy PROC   NEAR
  294.         push    bp
  295.         mov     bp,sp
  296.         push    si
  297.         push    di
  298.         push    ds
  299.         cld
  300.  
  301.         les     di,[bp+8]
  302.         mov     si,di
  303.  
  304.         xor     al,al
  305.         mov     bx,[bp+12]
  306.         mov     cx,bx
  307.   repnz scasb
  308.         sub     bx,cx
  309.         xchg    cx,bx
  310.  
  311.         mov     di,es
  312.         mov     ds,di
  313.         les     di,[bp+4]
  314.    repz movsb
  315.  
  316.         mov     cx,bx
  317.    repz stosb
  318.  
  319.         mov     dx,[bp+6]
  320.         mov     ax,[bp+4]
  321.  
  322.         pop     ds
  323.         pop     di
  324.         pop     si
  325.         pop     bp
  326.         ret
  327. _fstrncpy ENDP
  328.  
  329.         PUBLIC  _fstrlwr
  330. _fstrlwr PROC    NEAR
  331.         push    bp
  332.         mov     bp,sp
  333.         push    si
  334.         push    di
  335.         push    ds
  336.         cld
  337.  
  338.         lds     si,[bp+8]
  339.         les     di,[bp+4]
  340.         mov     dx,di
  341. strlwr: lodsb
  342.         cmp     al,'A'
  343.         jb      stolwr
  344.         cmp     al,'Z'
  345.         ja      stolwr
  346.         add     al,'a'-'A'
  347. stolwr: stosb
  348.         and     al,al
  349.         jnz     strlwr
  350.  
  351.         mov     ax,dx
  352.         mov     dx,es
  353.         pop     ds
  354.         pop     di
  355.         pop     si
  356.         pop     bp
  357.         ret
  358. _fstrlwr ENDP
  359.  
  360.         PUBLIC  _fstrupr
  361. _fstrupr PROC    NEAR
  362.         push    bp
  363.         mov     bp,sp
  364.         push    si
  365.         push    di
  366.         push    ds
  367.         cld
  368.  
  369.         lds     si,[bp+8]
  370.         les     di,[bp+4]
  371.         mov     dx,di
  372. strupr: lodsb
  373.         cmp     al,'a'
  374.         jb      stoupr
  375.         cmp     al,'z'
  376.         ja      stoupr
  377.         sub     al,'a'-'A'
  378. stoupr: stosb
  379.         and     al,al
  380.         jnz     strupr
  381.  
  382.         mov     ax,dx
  383.         mov     dx,es
  384.         pop     ds
  385.         pop     di
  386.         pop     si
  387.         pop     bp
  388.         ret
  389. _fstrupr ENDP
  390.  
  391. _TEXT   ENDS
  392.         END
  393.  
  394.