# ;; echo.s # should be a replacement for /bin/echo ... ;-) # #include .file "echo.s" .data _separator: .string " " _eoln: .string "\n" .text .globl echo # calling writestr: # first argument goes into %ebx == 1, stdout # second argument goes into %ecx == pointer to str1 echo: pop %esi # this is argc... pop %ecx # remove command, throw this away dec %esi jz _finish # check for no args left in argv _around: pop %ecx # this is the next *argv --- could test here since you are through when this a NULL pointer! movb (%ecx),%dl # check to see if this just an empty string (so we don't do a separator) or %dl,%dl jz _shortcut # if that's just a zero byte at the beginning, skip it... mov $1,%ebx # %ecx is already setup call writestr mov $1,%ebx lea _separator,%ecx call writestr _shortcut: dec %esi jnz _around mov $1,%ebx lea _eoln,%ecx call writestr _finish: mov $0, %ebx # and exit with a zero status mov $__NR_exit, %eax # int $0x80