home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / DOS / Programa / CCDL122.ZIP / LIBS / INTERP / SOURCE / PSTR.ASM < prev   
Encoding:
Assembly Source File  |  1995-11-03  |  2.7 KB  |  214 lines

  1.     .model    LARGE,C
  2.  
  3.  
  4.     public pstrcmp,pstrcpy,pstrchr,pstrstr,pstrlen,pstrncpy, pstrncmp
  5.     public pstrrchr,pstrcat
  6.  
  7. GETLEN    macro
  8.     cld
  9.     sub    cx,cx
  10.     dec    cx
  11.     sub    ax,ax
  12.     repne    scasw
  13.     not    cx
  14.     dec    cx
  15.     endm
  16.  
  17.     .code
  18. ;
  19. ;* int pstrncmp(short *a, short *b, int size);
  20. ;
  21. pstrncmp    proc
  22.     arg    a:dword,b:dword, c:word
  23.     uses    si,di,ds
  24.     mov    cx,[c]
  25.     les    di,b
  26.     lds    si,a
  27.     rep    cmpsw
  28.     jz    scmatched
  29.     js    scneg
  30. scpos:
  31.     sub    ax,ax
  32.     inc    ax
  33.     jmp    short scret
  34. scneg:
  35.     sub    ax,ax
  36.     dec    ax
  37.     jmp    short scret
  38. scmatched:
  39.     sub    ax,ax
  40. scret:
  41.  
  42.     ret
  43. pstrncmp    endp
  44. ;
  45. ;* int pstrcmp(short *a, short *b);
  46. ;
  47. pstrcmp    proc
  48.     arg    a:dword,b:dword
  49.     uses    si,di,ds
  50.     les    di,a
  51.     GETLEN
  52.     inc    cx
  53.     push    cx
  54.     push    word ptr [b+2]
  55.     push    word ptr [b]
  56.     push    word ptr [a+2]
  57.     push    word ptr [a]
  58.     call    pstrncmp
  59.     add    sp,10
  60.     ret
  61. pstrcmp    endp
  62. ;
  63. ;* void pstrcpy(short *a, short *b);
  64. ;
  65. pstrcpy    proc
  66.     arg    a:dword,b:dword
  67.     uses    si,di,ds
  68.     les    di,b
  69.     GETLEN
  70.     inc    cx
  71.     les    di,a
  72.     lds    si,b
  73.     rep    movsw
  74.     ret
  75. pstrcpy endp    
  76. ;
  77. ;* void pstrcat(short *a, short *b);
  78. ;
  79. pstrcat    proc
  80.     arg    a:dword,b:dword
  81.     uses    si,di,ds
  82.     les    di,a
  83.     GETLEN
  84.     add    cx,cx
  85.     add    word ptr [a],cx
  86.     push    word ptr [b+2]
  87.     push    word ptr [b]
  88.     push    word ptr [a+2]
  89.     push    word ptr [a]
  90.     call    pstrcpy
  91.     add    sp,8
  92.     ret
  93. pstrcat endp    
  94. ;
  95. ;* void pstrncpy(short *a, short *b,int len);
  96. ;
  97. pstrncpy    proc
  98.     arg    a:dword,b:dword,c:word
  99.     uses    si,di,ds
  100.     mov    cx,[c]
  101.     les    di,a
  102.     lds    si,b
  103.     rep    movsw
  104.     ret
  105. pstrncpy endp    
  106. ;
  107. ;* short *pstrchr(short *a, short b);
  108. ;
  109. pstrchr    proc
  110.     arg    a:dword,b:word
  111.     uses    si,di,ds
  112.     les    di,[a]
  113.     GETLEN
  114.     les    di,[a]
  115.     mov    ax,[b]
  116.     repne    scasw
  117.     jne    scnull
  118.     dec    di
  119.     dec    di
  120.     mov    ax,di
  121.     mov    dx,es
  122.     jmp    short scret2
  123. scnull:
  124.     sub    ax,ax
  125.     sub    dx,dx
  126. scret2:
  127.     ret
  128. pstrchr    endp
  129. ;
  130. ;* short *pstrrchr(short *a, short b);
  131. ;
  132. pstrrchr    proc
  133.     arg    a:dword,b:word
  134.     uses    si,di,ds
  135.     les    di,[a]
  136.     GETLEN
  137.     dec    di
  138.     dec    di
  139.     mov    ax,[b]
  140.     std
  141.     repne    scasw
  142.     jne    scnull2
  143.     inc    di
  144.     inc    di
  145.     mov    ax,di
  146.     mov    dx,es
  147.     jmp    short scret3
  148. scnull2:
  149.     sub    ax,ax
  150.     sub    dx,dx
  151. scret3:
  152.     cld
  153.     ret
  154. pstrrchr    endp
  155. ;          
  156. ;* short pstrlen(short *a);
  157. ;
  158. pstrlen    proc
  159.     arg    a:dword,b:dword
  160.     uses    si,di,ds
  161.     les    di,a
  162.     GETLEN
  163.     mov    ax,cx
  164.     ret
  165. pstrlen    endp
  166. ;
  167. ;* short *pstrstr(short *a, short *b);
  168. ;
  169. pstrstr    proc
  170.     arg    a:dword,b:dword
  171.     uses    si,di,ds
  172.     les    di,b
  173.     GETLEN
  174.     les    di,b
  175. sslp:
  176.     push    cx
  177.     push    es
  178.     push    di
  179.     mov    ax,es:[di]
  180.     push    ax
  181.     push    word ptr [a+2]
  182.     push    word ptr [a]
  183.     call    pstrchr
  184.     add    sp,6
  185.     mov    cx,ax
  186.     or    cx,dx
  187.     jz    short ssnomore
  188.     push    dx
  189.     push    ax
  190.     call    pstrncmp
  191.     or    ax,ax
  192.     pop    ax
  193.     pop    dx
  194.     jz    short ssnomore
  195.     inc    ax
  196.     inc    ax
  197.     mov    word ptr [a],ax
  198.     mov    word ptr [a+2],dx
  199.     pop    di
  200.     pop    es
  201.     pop    cx
  202.     jmp    sslp
  203.  
  204. ssnomore:
  205.     add    sp,6
  206.     ret
  207.  
  208.     
  209. pstrstr    endp
  210.     end
  211.  
  212.     
  213.     
  214.