global _start

section .text

return	db 10,0

strlen: ; < (address of string) > (length of string)
	push ebp
	mov ebp, esp
	xor ecx, ecx
	mov eax, [ebp+8]	; address of string
.lp: 	cmp [eax+ecx], byte 0
	je .end
	inc ecx
	jmp short .lp
.end:
	mov eax, ecx		; output string length
	mov esp, ebp
	pop ebp
	ret

print_str: ; < (address of string) > (nothing)
	push ebp
	mov ebp, esp
	push ebx

	mov ebx, [ebp+8]	; address of string

	push ebx
	call strlen
	add esp, 4

	mov edx, eax		; string length in edx for write
	mov ecx, ebx		; string address in ecx for write
	mov ebx, 1		; standard output
	mov eax, 4		; write
	int 80h

	pop ebx
	mov esp, ebp
	pop ebp
	ret

_start:
	mov ebx, [esp]		; number of parameters (argc)
	mov esi, esp		; address of addresses of
	add esi, 4		;   command line parameter (argv)
lp:
	push dword [esi]	; current parameter address (argv[i])
	call print_str
	add esp, 4

	push dword return
	call print_str
	add esp, 4

	add esi, 4		; next parameter
	dec ebx

	cmp ebx, 0
	jne lp

	mov ebx, 0		; success
	mov eax, 1		; _exit
	int 80h
