#-------------------------------------------------------------------------------
# Thomas C. Bressoud
# 31 January 2007
# inputint.s
#
# Description:  Program that retrieves an integer value from the user
#-------------------------------------------------------------------------------

# Next directive defines additions to the data segment

.data
.align 2		; Start on 4 byte boundary
.globl _msg
_msg:			; char msg[] = "Enter an integer input: "
	.asciz	"Enter an integer input: "
.globl _out
_out:
	.asciz  "You entered (in decimal): "
	
# Next directive defines additions to the text (code) segment

.text
.align 3		; Start on a 4 byte boundary
.globl	_main	; Make the _main symbol visible outside this module
_main:
	mflr	r0	; Put the return address from main into r0
	stw		r0,8(r1)	; Save in the linkage of the callers stack frame
	stwu	r1,-32(r1)	; Allocate a new stack frame, updating the stack ptr

	; print_string(_msg)
	lis		r3,hi16(_msg)	; Put high 16 bits of msg address into r3
	ori		r3,r3,lo16(_msg)	; or in the low 16 bits
	bl		_print_string	; Print out the string
	
	; r13 = next_int()
	bl		_next_int
	mr		r13,r3
	
	; print_string(_out)
	lis		r3,hi16(_out)	; Put high 16 bits of out address into r3
	ori		r3,r3,lo16(_out)	; or in the low 16 bits
	bl		_print_string
	
	; println_int(r13)
	mr		r3,r13
	bl		_println_int
	
	addi	r1, r1, 32
	lwz		r0, 8(r1)
	mtlr	r0
	blr

