Advertisement
DMG

Substring stringa

DMG
Nov 15th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Program koji provjerava da li se string_2 nalazi u string_1
  2. # dmarjanovic
  3.  
  4. .section .data
  5.     string_2: .ascii "nmar\0"
  6.     string_1: .ascii "dragutinmarjanovic\0"
  7. .section .text
  8. .globl main
  9.  
  10. main:
  11.  
  12.     # Brojac za string_1
  13.     movl $0, %esi
  14.     # Brojac za string_2
  15.     movl $0, %ebx
  16.    
  17. for_string:
  18.    
  19.     cmpb $0, string_2(,%ebx,1)
  20.     je substr_true
  21.  
  22.     cmpb $0, string_1(,%esi,1)
  23.     je substr_false
  24.    
  25.     movb string_2(,%ebx,1), %cl
  26.     cmpb string_1(,%esi,1), %cl
  27.     je maybe_substr
  28.    
  29.     incl %esi
  30.     movl $0, %ebx
  31.     jmp for_string
  32.    
  33.     maybe_substr:
  34.         incl %esi
  35.         incl %ebx
  36.         jmp for_string
  37.        
  38. substr_true:
  39.     movl $2, %eax
  40.     jmp end
  41.    
  42. substr_false:
  43.     movl $-2, %eax
  44.  
  45. end:
  46.     movl $1, %eax
  47.     int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement