# ;; echo.s # should be a replacement for /bin/echo ... ;-) # #include .file "echo.s" .data _separator: .string " " _eoln: .string "\n" .text .globl echo # first argument goes into %rdi == 1, stdout # second argument goes into %rsi == pointer to str1 # third argument goes into %rdx == number of bytes in str1 echo: xor %r10,%r10 # we'll use %r10 for our "zero" register pop %r8 # this is argc... pop %rsi # remove command dec %r8 jz _finish # check for no args left in argv _around: pop %rsi # this is the next *argv --- could test here since you are through when this a NULL pointer! mov (%rsi),%r9b # check to see if this just an empty string (so we don't do a separator) cmp %r9b,%r10b jz _shortcut # if that's just a zero byte at the beginning, skip it... mov $1,%rdi call writestr mov $1,%rdi lea _separator,%rsi call writestr _shortcut: dec %r8 jnz _around _finish: mov $1,%rdi lea _eoln,%rsi call writestr mov $0, %rdi # and exit with a zero status mov $__NR_exit, %rax # syscall = 60 is exit syscall