Maybe this could help:
; test.asm
;
; compile with:
; $ nasm -felf64 -o test.o test.asm
; $ ld -o test test.o
;
bits 64
default rel ; x86-64 default addressing is RIP relative!
; Moved to .rodata.
section .rodata
strNewLine: db `\n`
section .text
global _start
_start:
; argc is in [rsp]
; argv[n] are in [rsp+8*n+8]
;mov ecx,[rsp] ; argc (not used here!)
xor ebx,ebx ; RBX is saved by syscalls (SysV ABI).
; Used as index...
.loop:
mov rdi,[rsp+rbx*8+8]
test rdi,rdi ; argv[rbx] == NULL?
jz .no_more_args
call printstr ; print the string
call printnl ; print a new line character
add ebx,1 ; avoid using INC/DEC (they are slow!).
jmp .loop
.no_more_args:
mov eax,60 ; syscall_exit
xor edi,edi ; exit(0).
syscall
; rdi = string ptr.
strlen:
xor eax,eax
.loop:
cmp byte [rdi+rax],0
jz .strlen_end
add eax,1
jmp .loop
.strlen_end:
ret
;rdi = string ptr
printstr:
call strlen
mov edx,eax ; string length.
mov eax,1 ; syscall_write
mov rsi,rdi ; string ptr.
mov edi,eax ; stdout
syscall
ret
printnl:
mov eax,1 ; syscall_write
mov edi,eax ; stdout
mov edx,eax ; 1 char do print
lea rsi,[strNewLine] ; points to '\n'.
syscall
ret