Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- replaceChar:
- pushq %rbp # setup
- movq %rsp,%rbp # setup
- subq $pointerSize, %rsp # get some space in the stack
- pushq %rdi # save to pointer value into the satck
- movb $0, %r8b # set r8 as loop index
- movb (%rdi), %r11b # r11 is the amount of chars in the string
- leaq 4(%rdi), %rdi # increase the pointer (move fowerd to the string)
- .loopStart:
- cmpb %r8b, %r11b # check the loop index
- je .replaceAfterLoop
- cmpb (%rdi), %sil # check if need to replace
- je .replaceChar
- .loopEnd:
- inc %rdi # increase the pointer value
- inc %r8b # increase the loop index value
- jmp .loopStart
- .replaceChar:
- movb %dl,(%rdi) # replace the char
- jmp .loopEnd
- .replaceAfterLoop:
- popq %rax # restore the value of pointer into the return value
- movq %rbp, %rsp # leave
- popq %rbp # leave
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement