Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "rw32-2017.inc"
  2.  
  3. section .data
  4.     my_string db "ahoj svete a lide!", 0
  5.    
  6.     replaced_string dd 0, 0, 0, 0, 0
  7.    
  8.        
  9.        
  10. section .text
  11. main:
  12.     mov ebp, esp
  13.        
  14.     mov eax, my_string
  15.     call my_string_len
  16.     call WriteUInt32
  17.    
  18.     push "e"
  19.     push my_string
  20.     push eax
  21.     push replaced_string
  22.     call my_char_replace
  23.  
  24.     xor eax, eax
  25.     ret
  26.  
  27. my_char_replace:
  28.     push ebp ; stack frame enter
  29.     mov ebp, esp
  30.     push edi
  31.     push ebx
  32.     push edx
  33.     push esi
  34.     push ecx
  35.    
  36.     ; ebp+20 char to replace
  37.     ; ebp+16 input
  38.     ; ebp+12 len
  39.     ; ebp+8 output
  40.    
  41.     xor ecx, ecx
  42.     xor edx, edx
  43.     mov edi, [ebp+16] ; input adress
  44.     mov esi, [ebp+8] ; output adress
  45.     mov al, [ebp+20] ; char to replace
  46.    
  47. do_while:
  48.     cmp [edi+ecx], al ; compare with replacement char
  49.     je _replace_char
  50.         mov ebx, [edi+ecx]
  51.         mov [esi+ecx], ebx
  52.         jmp _move_char
  53.        
  54.         _replace_char:
  55.             mov [edi+ecx], byte "_"
  56.             inc edx
  57.  
  58.         _move_char:
  59.         inc ecx
  60.     cmp ecx, [ebp+12]
  61.     jne do_while ; loop, if we're before end
  62.    
  63.     mov eax, edx ; store replaced chars
  64.    
  65.     pop ecx
  66.     pop esi
  67.     pop edx
  68.     pop ebx
  69.     pop edi
  70.     mov esp, ebp ; stack frame leave
  71.     pop ebp
  72.  
  73.     ret 32
  74.  
  75. my_string_len:
  76.     push ebx
  77.     xor ebx, ebx
  78.    
  79.     while:  cmp [eax + ebx], byte 0
  80.             je end
  81.             inc ebx
  82.             jmp while
  83.  
  84.     end:    mov eax, ebx
  85.             pop ebx
  86.             ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement