# ------------------------------------------------------------------
# getDec.s
#	Read a decimal string from input, convert to integer.
# Assumes input string represents signed decimal number.
# Takes destination address of new integer, as parameter.
# Returns number of characters in input string.
# ..................................................................
# calling sequence:
#	push destination address of integer
#	call	getDec
#	add 4 to stack pointer
# ..................................................................
# author: David Bozarth - 27 April 2004
# modified 30 April 2004
# ------------------------------------------------------------------
#
WORD = -4
#
# Stack frame
stkTop = strLoc		# top-of-stack marker - BUG ? must be 16 to work 4/27 **
strLoc = basePtr + 4 * WORD		# char buffer should be 12 bytes
basePtr = 0
rtnAddr = basePtr - WORD
intPtrIn = rtnAddr - WORD		# destination address argument

	.data
nChars:
	.long	12
	
	.text
	.align	4
	.globl	getDec

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

	pushl	$nChars			# number of chars to store
	leal	strLoc(%ebp), %ebx	# base addx of char buffer
	pushl	%ebx
	call	readStr			# .. n_chars read -> eax
	addl	$8, %esp
	movl	%eax, %ecx		# n_chars read -> ecx
	#pushl	strLoc(%ebp)		# convert string to int
	leal	strLoc(%ebp), %ebx	# read string from input
	pushl	%ebx 
	call	sDecToInt		# .. int -> eax
	addl	$4, %esp
	movl	intPtrIn(%ebp), %ebx	# move int to expected address
	movl	%eax, (%ebx)
allDone:
	movl	%ecx, %eax		# return n_chars read
	popl	%ecx
	popl	%ebx
	movl	%ebp, %esp		# restore stack pointer
	popl	%ebp			# restore caller's base pointer
	ret
