!--------------------------------------
! absval.S
! Function Return Values
! Load and Store Instructions
!--------------------------------------

.section ".rodata"

pcPrompt:
	.asciz "Enter an integer:  "

pcScanfFormat:
	.asciz "%d"

pcResult:
	.asciz "The integer's absolute value is %d.\n"

!--------------------------------------

.section ".data"

!--------------------------------------

.section ".bss"

	.align 4
piInput:
	.skip 4

	.align 4
piAbsVal:
	.skip 4

!--------------------------------------

.section ".text"

	.align 4
	.global main

main:

	save	%sp, -96, %sp

	! printf("Enter an integer:  ") ; 
	set	pcPrompt, %o0
	call	printf
	nop

	! scanf("%d", &iInput); 
	set	pcScanfFormat, %o0
	set	piInput, %o1
	call	scanf
	nop

	! iAbsVal = abs(iInput) ;
	set	piInput, %l0
	ld 	[%l0], %o0
	call	abs
	nop
	set	piAbsVal, %l0
	st 	%o0, [%l0]

	! printf("The integer's absolute value is %d.\n", iAbsVal); 
	set	pcResult, %o0
	set	piAbsVal, %o1
	ld 	[%o1], %o1
	call	printf
	nop

	! return 0;
	mov	0, %i0
	ret
	restore

