.data
chr: .byte 0x6
arr: .rept 10
     .byte 0x0
     .endr
ar1: .byte 0x0
     .byte 0x1
     .byte 0x2
     .byte 0x3
     .byte 0x4
     .byte 0x5
     .byte 0x6
     .byte 0x7
     .byte 0x8
     .byte 0x9
.equiv len,.-ar1
ln:	.ascii "\n"
.text
.globl _start
_start:
	popl	%ecx		# argc
	popl	%ecx		# 0-arg

#	call writearr
	
	movl	$arr,%esi
lewp:
	popl	%ecx		# argv
	test 	%ecx,%ecx
	jz	exit

	movb	(%ecx),%dh
	movb	%dh,(%esi)
	subb	$0x30,(%esi)
	incl	%esi
	
	movl	%ecx,%ebx
	xorl	%edi,%edi

	

strlen:
	movb	(%ebx),%al
	inc	%edi
	inc	%ebx
	test	%al,%al
	jnz	strlen
#	movb	$10,-1(%ebx)
	cmp 	$2,%edi
	jnz exit1	
	jmp	lewp

writechr:
# 	write(1,argv[i],strlen(argv[i]));
	pusha
	movl	$4,%eax
	movl	$1,%ebx
	movl	$chr,%ecx
	movb	(%ecx),%dl
	movb	$0x30,%dh
	addb	%dh,%dl
	movb	%dl,(%ecx)
	movl	$1,%edx
	int	$0x80
	popa
	ret

writearr:
	pusha
	movl $arr,%eax
	movl $0,%ecx
	movl $chr,%esi
st:
	cmp $10,%ecx
	jz endwrite
	movb (%eax,%ecx),%bh
	movb %bh,(%esi)
	call writechr
	incl %ecx
	jmp st
endwrite:
	popa
	ret	

writeln:
	pusha
	movl $4,%eax
	movl $1,%ebx
	movl $ln,%ecx
	movl $1,%edx
	int $0x80
	popa
	ret
	
exit1:
	movl	$1,%eax
	movl	$1,%ebx
	int 	$0x80

exit:
	call writearr
	call writeln
	movl	$1,%eax
	xorl	%ebx,%ebx
	int 	$0x80
