Subversion Repositories Kolibri OS

Rev

Rev 1467 | Rev 7577 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; strlen function
  2. ;
  3. ; Copyright (c) 2003 Thomas Mathys
  4. ; killer@vantage.ch
  5. ;
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 2 of the License, or
  9. ; (at your option) any later version.
  10. ;
  11. ; This program is distributed in the hope that it will be useful,
  12. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ; GNU General Public License for more details.
  15. ;
  16. ; You should have received a copy of the GNU General Public License
  17. ; along with this program; if not, write to the Free Software
  18. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19. ;
  20. ;%ifndef _STRLEN_INC
  21. ;%define _STRLEN_INC
  22.  
  23.  
  24. ;********************************************************************
  25. ;       returns the length of an asciiz string
  26. ;       input           :       esi = pointer to string
  27. ;       output          :       eax = string length
  28. ;       destroys        :       nothing
  29. ;********************************************************************
  30. strlen:
  31.         push    ecx edi
  32.         pushfd
  33.         cld                             ; !
  34.         mov     ecx,-1
  35.         mov     edi,esi                 ; find terminating zero
  36.         xor     al,al
  37.         repne   scasb
  38.         mov     eax,edi                 ; calculate string length
  39.         sub     eax,esi
  40.         dec     eax
  41.         popfd
  42.         pop     edi ecx
  43.         ret
  44.  
  45.  
  46.  
  47. ; linlen function
  48. ;
  49. ; Copyright (c) 2009 Igor Afanasiev
  50.  
  51. linlen:
  52.         push    ecx edi
  53.         pushfd
  54.         cld
  55.         mov     ecx,eax
  56.         inc ecx
  57.         mov     edi,esi                 ; find terminating zero
  58.         mov     al,13
  59.         repne   scasb
  60.         mov     eax,edi                 ; calculate string length
  61.         sub     eax,esi
  62.         dec     eax
  63.         popfd
  64.         pop     edi ecx
  65.         ret
  66.  
  67. ;description:
  68. ; проверяет содержится ли строка str1 в строке str0
  69. ; проверка делается только начиная с первых символов, указанных в str0 и str1
  70. ; пример 1: если str0='aaabbbccc', str1='bbb' совпадения не будет
  71. ; пример 2: если str0='aaabbbccc', str1='aaa' совпадение будет
  72. ;output:
  73. ; al = 0 если строка str1 содержится в str0
  74. ; al != 0 если строка str1 не содержится в str0
  75. align 4
  76. proc str_instr uses edi esi, str0:dword, str1:dword
  77.         ;xor eax,eax
  78.         mov edi,[str0]
  79.         mov esi,[str1]
  80.         cld
  81.         @@:
  82.                 mov al,[esi]
  83.                 cmp al,0
  84.                 je .e1
  85.                 inc esi
  86.                 scasb ;сравниваем символы
  87.         jz @b ;если совпали, то переходим к сравнению следующих
  88.         ;сюда попадаем если строки не совпали
  89.         sub al,[edi-1]
  90.         .e1: ;сюда попадаем если строка str1 (esi) закончилась
  91.         ret
  92. endp
  93.  
  94.