# --------------------------------------------------------------------
# bankTransact.s
#	get update for bank object
# Prompts the user to enter a bank account transaction.
# Returns the amount of the transaction.
# ..................................................................
# calling sequence:
#	push address of bank object
#	call	bankTransact
#	add 4 to stack pointer
# ..................................................................
# author: David Bozarth - 12 May 2004
# modified 12 May 2004
# ------------------------------------------------------------------
#
	.include "bankClass.h"
#
TRUE = 1
FALSE = 0
WORD = 4
#
# Stack frame
stkTop = intTrans		# top-of-stack marker
intTrans = basePtr - WORD	# transaction amount
basePtr = 0
rtnAddr = basePtr + WORD
thisPtr = rtnAddr + WORD	# object base address argument

	.data
strPrompt:
	.string "Transaction amount <-0- to quit> <Enter> : "
strNewl:
	.string "\n"
		
	.text
	.align	WORD
	.globl	bankTransact

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

	call	newline
	movl	thisPtr(%ebp), %ebx	# object base address
	leal	theId(%ebx), %eax	# int balance field address
	pushl	%eax
	call	writeStr		# show account ID
	addl	$WORD, %esp
	call	newline
	
	pushl	$strPrompt		# prompt for transaction
	call	writeStr
	addl	$WORD, %esp
	leal	intTrans(%ebp), %eax	# holder for transaction amount
	pushl	%eax			# destination address
	call	getDec
	addl	$WORD, %esp

	movl	thisPtr(%ebp), %ebx	# object base address
	leal	theBal(%ebx), %ecx	# int balance field address
	movl	(%ecx), %eax		# acct_bal before update
	addl	intTrans(%ebp), %eax	# add current transaction amount
	movl	%eax, (%ecx)		# update object with new balance
	leal	intTrans(%ebp), %eax	# holder for transaction amount
	movl	(%eax), %eax		# return value of integer stored
allDone:
	popl	%ecx			# restore registers
	popl	%ebx
	movl	%ebp, %esp		# restore stack pointer
	popl	%ebp			# restore caller's base pointer
	ret
