# ------------------------------------------------------------------
# putDec.s
#	display an integer on the screen
# takes integer on stack, returns void
# ..................................................................
# calling sequence:
#	push integer
#	call	putDec
#	add 4 to stack pointer
# ..................................................................
# author: David Bozarth - 26 April 2004
# modified 30 April 2004
# ------------------------------------------------------------------
#
WORD = -4
BUFFER = -12
#	
# Stack frame
stkTop = strBuf
strBuf = basePtr + BUFFER
basePtr = 0
rtnAddr = basePtr - WORD
intIn = rtnAddr - WORD			# integer argument

	.text
	.align	4
	.globl	putDec

putDec:
	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

	leal	strBuf(%ebp), %ebx	# string address
	movl	$BUFFER, %ecx		# size
	negl	%ecx
zeroLoop:
	cmpl	$0, %ecx
	je	doConvert
	
	movb	$0, (%ebx)
	incl	%ebx			# .. array address
	decl	%ecx			# .. array index
	jmp	zeroLoop
				
doConvert:	
	leal	strBuf(%ebp), %ebx	# convert int to string
	pushl	%ebx
	pushl	intIn(%ebp)		# integer -> convert to string
	call	sIntToDec		
	addl	$8, %esp
	leal	strBuf(%ebp), %ebx	# send string to display
	pushl	%ebx
	call	writeStr		
	addl	$4, %esp

allDone:
	popl	%ecx			# restore registers
	popl	%ebx
	movl	%ebp, %esp		# restore stack pointer
	popl	%ebp			# restore caller's base pointer
	ret
