# --------------------------------------------------------------------
# showList.s
#	display a list of integers
# Takes 2 arguments: address of int array, number of ints in array.
# Displays the integers in a column. Returns number of ints displayed.
# ....................................................................
# calling sequence:
#	push number_of_ints (array_size)
#	push base_address of int array
#	call	showList
#	add 8 to stack pointer
# ....................................................................
# author: David Bozarth - 29 April 2004
# modified 30 April 2004
# --------------------------------------------------------------------
#
WORD = -4
#
# Stack frame
stkTop = strSep			# top-of-stack marker	
strSep = basePtr + WORD		# base addx of separator/delimiter string
basePtr = 0
rtnAddr = basePtr - WORD
intPtrIn = rtnAddr - WORD	# int_array_base_address argument
intSize = intPtrIn - WORD	# number_of_integers (array size) argument
	
	.data
strNewl:
	.string "\n"
strSpace:
	.string " "
	
	.text
	.align 4
	.globl showList

showList:
	pushl	%ebp			# save caller's base pointer
	movl	%esp, %ebp		# establish our base pointer
	addl	$stkTop, %esp		# allocate local variables
	pushl	%ebx			# save registers
	pushl	%ecx

	# designate separator here
	movl	$strNewl, %ebx		# address of constant separator
	#movl	$strSpace, %ebx		# address of constant separator
	movl	%ebx, strSep(%ebp)
	
	xorl	%ecx, %ecx		# reset counter
	movl	intPtrIn(%ebp), %ebx	# array base address
sendLoop:		
	cmpl	intSize(%ebp), %ecx	# while count <= size
	jae	allDone

	movl	(%ebx, %ecx, 4), %eax	# fetch the next integer
	pushl	%eax
	call	putDec			# send one integer to display
	addl	$4, %esp
	pushl	strSep(%ebp)	
	call	writeStr		# send newline to display
	addl	$4, %esp
	incl	%ecx			# counter++
	jmp	sendLoop

allDone:
	movl	%ecx, %eax		# return number of ints displayed
	popl	%ecx			# restore registers
	popl	%ebx
	movl	%ebp, %esp		# restore stack pointer
	popl	%ebp			# restore caller's base pointer
	ret
