Advertisement
Guest User

Untitled

a guest
Dec 5th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. replaceChar:
  2.   pushq %rbp # setup
  3.   movq %rsp,%rbp # setup
  4.     subq $pointerSize, %rsp # get some space in the stack
  5.     pushq %rdi # save to pointer value into the satck
  6.   movb $0, %r8b # set r8 as loop index
  7.   movb (%rdi), %r11b # r11 is the amount of chars in the string
  8.   leaq 4(%rdi), %rdi # increase the pointer (move fowerd to the string)
  9. .loopStart:
  10.   cmpb %r8b, %r11b # check the loop index
  11.   je .replaceAfterLoop
  12.   cmpb (%rdi), %sil # check if need to replace
  13.   je .replaceChar
  14. .loopEnd:
  15.   inc %rdi # increase the pointer value
  16.   inc %r8b # increase the loop index value
  17.   jmp .loopStart
  18. .replaceChar:
  19.   movb %dl,(%rdi) # replace the char
  20.   jmp .loopEnd
  21. .replaceAfterLoop:
  22.     popq %rax # restore the value of pointer into the return value
  23.   movq %rbp, %rsp # leave
  24.   popq %rbp # leave
  25.   ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement