title: Accepting user input in assembly? Simple program (On macOS)
body: <p>I'm having some trouble with this simple program that accepts a name from the user and prints "Hello, name here"</p>
  
  <p>This is my code so far...</p>
  
  <pre><code>%define SYSCALL_WRITE 0x2000004
  %define SYSCALL_EXIT  0x2000001
  %define SYSCALL_READ  0x2000003
  
  SECTION .data
    prompt db "Enter name "
    text2 db "Hello, "
  
  SECTION .bss
    name resb 16
  
  SECTION .text
    global _start
  
  _start:
    call _printText1
    call _getInput
    call _printText2
    call _printName
    mov rax, SYSCALL_EXIT
    mov rdi, 0
    syscall
  
  _printText1:
    mov rax, SYSCALL_WRITE
    mov rdi, 1
    mov rsi, prompt
    mov rdx, 11
    syscall
    ret
  
  _getInput:
    mov rax, SYSCALL_READ
    mov rdi, 0
    mov rsi, name
    mov rdx, 1
    syscall
    ret
  
  _printText2:
    mov rax, SYSCALL_WRITE
    mov rdi, 1
    mov rsi, text2
    mov rdx, 7  
    syscall
    ret
  
  _printName:
    mov rax, SYSCALL_WRITE
    mov rdi, 1
    mov rsi, name
    mov rdx, 16
    syscall
    ret
  </code></pre>
  
  <p>When I execute it, the output doesn't print "Hello, ". The first letter of the name entered is printed before the next commandline...</p>
  
  <p><code>nMy-MacBook:Assembly username$ ame</code></p>
  
  <p>and the rest of the name is accepted as a command argument, for which the system replies </p>
  
  <p><code>-bash: ame: command not found</code></p>
  
  <p>What exactly am I doing wrong? I deleted the _getInput and _printName functions and it still only prints "Enter name " without printing "Hello, ".</p>
  
  <p>Thank you.</p>