Advertisement
Guest User

strutils.cpp

a guest
Apr 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #ifdef _WIN32
  2.     __asm
  3.     {
  4.         mov ah, 'A'
  5.         mov dh, 'Z'
  6.  
  7.         mov esi, str1
  8.         mov ecx, str2
  9.         mov dl, [ecx]
  10.         test dl,dl ; NULL?
  11.         jz short str2empty_label
  12.  
  13. outerloop_label:
  14.         mov ebx, esi ; save esi
  15.         inc ebx
  16. innerloop_label:
  17.         mov al, [esi]
  18.         inc esi
  19.         test al,al
  20.         je short str2notfound_label ; not found!
  21.  
  22.         cmp     dl,ah           ; 'A'
  23.         jb      short skip1
  24.         cmp     dl,dh           ; 'Z'
  25.         ja      short skip1
  26.         add     dl,'a' - 'A'    ; make lowercase the current character in str2
  27. skip1:     
  28.  
  29.         cmp     al,ah           ; 'A'
  30.         jb      short skip2
  31.         cmp     al,dh           ; 'Z'
  32.         ja      short skip2
  33.         add     al,'a' - 'A'    ; make lowercase the current character in str1
  34. skip2:     
  35.  
  36.         cmp al,dl
  37.         je short onecharfound_label
  38.         mov esi, ebx ; restore esi value, +1
  39.         mov ecx, str2 ; restore ecx value as well
  40.         mov dl, [ecx]
  41.         jmp short outerloop_label ; search from start of str2 again
  42. onecharfound_label:
  43.         inc ecx
  44.         mov dl,[ecx]
  45.         test dl,dl
  46.         jnz short innerloop_label
  47.         jmp short str2found_label ; found!
  48. str2empty_label:
  49.         mov eax, esi // empty str2 ==> return str1
  50.         jmp short ret_label
  51. str2found_label:
  52.         dec ebx
  53.         mov eax, ebx // str2 found ==> return occurence within str1
  54.         jmp short ret_label
  55. str2notfound_label:
  56.         xor eax, eax // str2 nt found ==> return NULL
  57.         jmp short ret_label
  58. ret_label:
  59.     }
  60. #endif
  61. #ifdef _WIN64
  62.  
  63. #endif // _WIN64
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement