# ;; printenv.s # should be a replacement for /bin/printenv ... ;-) # #include .file "printenv.s" .data _separator: .string " " _eoln: .string "\n" .text .globl printenv # 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 printenv: xor %r10,%r10 # we'll use %r10 for our "zero" register pop %r8 # this is argc... _around: pop %rsi # this is the next *argv --- could test here since you are through when this a NULL pointer! dec %r8 jnz _around pop %rsi _environ: pop %rsi cmp %rsi,%r10 jz _finish mov $1,%rdi call writestr mov $1,%rdi lea _eoln,%rsi call writestr jmp _environ _finish: mov $0, %rdi # and exit with a zero status mov $__NR_exit, %rax # syscall = 60 is exit syscall