title: syscall read/write 1 byte only?
body: <p>I am new to assembly and trying to write a version of the &quot;echo&quot; built-in but only operating on 1 byte at a time.</p>
  <p>I have the following which works the way I want, except it overflows more than 1 byte on both read and write even though I explicitly say 1 byte in x2 on both syscalls. What am I doing wrong?</p>
  <p>Example run:</p>
  <pre><code>sh-4.2$ ./echo1b
  f
  f
  o
  o
  b
  b
  bar
  bar
  bazbazbaz
  bazbazbaz
  q
  sh-4.2$
  </code></pre>
  <p>Here is the code:</p>
  <pre><code>.data
  temp:   .byte 1  
  
  .text
  .globl _start
  _start:
      /* read one byte from stdin, store to temp */
      mov x0, #0x0
      adr x1, temp
      mov x2, #0x1
      mov x8, #0x3F
      svc #0x0
  
      /* write newline to stdout */
      mov x0, #0x1
      mov x1, #0xA
      mov x2, #0x1
      mov x8, #0x40
      svc #0x0
      
      /* if byte in temp is &quot;q&quot;, exit */
      mov x5, #0x71
      ldr x1, temp
      cmp x1, x5
      beq exit
  
      /* otherwise, write it to stdout and repeat */
      mov x0, #0x1
      adr x1, temp
      mov x2, #0x1
      mov x8, #0x40
      svc #0x0
      b _start
  
  exit:
      /* exit cleanly */  
      eor x0, x0, x0 
      eor x1, x1, x1
      eor x2, x2, x2
      mov x8, #0x5D
      svc #0x0
  </code></pre>