Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. section .data
  2.  
  3. prompt db "Please enter your name: ", 10
  4. length equ $ - prompt
  5. text times 255 db 0
  6. buffer times 255 db 0
  7.  
  8. Enter your text
  9. section .text
  10. global main
  11. main:
  12. mov rax, 1
  13. mov rdi, 1
  14. mov rsi, prompt
  15. mov rdx, length
  16. syscall
  17.  
  18. mov rax, 0
  19. mov rdi, 0
  20. mov rsi, text
  21. syscall
  22.  
  23. mov rcx, rax ; rcx will be the character counter.
  24. mov rsi, text ; a pointer to the current character. Start from the beginning.
  25. add rsi, rcx
  26. dec rsi ; Remember the 0-index
  27. mov rdi, buffer
  28.  
  29. ;; This subroutine is also SUB-optimal if your teacher demands
  30. ;; performance, look into the advantages of `lea` and a simple
  31. ;; rep;scas loop as well.
  32. process_loop:
  33. mov bl, [rsi] ; Now copy from back to front
  34. mov [rdi], bl
  35. inc rdi
  36. dec rsi
  37. dec rax
  38. jnz process_loop
  39.  
  40. mov rax, 1 ; And print the string
  41. mov rdi, 1
  42. mov rsi, buffer
  43. mov rdx, rcx
  44. syscall
  45.  
  46. exit:
  47. mov rax, 60
  48. mov rdi, 0
  49. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement