
fmtinput: .string "The sum of %d, %d, %d, %d, %d, %d, and %d is: "
fmtsum:	  .string "%d\n"

	.balign 4		// word align all instructions
//-SUM()-------------------------------------------------------------
sum:
	stp	x29, x30, [sp, -16]!
	mov	x29, sp

	add	w0, w0, w1	// input parameters are stored in w0-w7
	add	w0, w0, w2	// but sum() only uses w0-w6
	add	w0, w0, w3
	add	w0, w0, w4
	add	w0, w0, w5
	add	w0, w0, w6

return:	ldp	x29, x30, [sp], 16
	ret

//-MAIN()------------------------------------------------------------

	.global main		// make main() global
				// OS calls main(), so only main()
				// needs to be global

main:	stp	x29, x30, [sp, -16]!
	mov	x29, sp

	// Make up seven numbers as parameters
	mov	w19, 10
	mov	w20, 20
	mov	w21, 30
	mov	w22, 40
	mov	w23, 50
	mov	w24, 60
	mov	w25, 70

	// Print parameters
	adrp	x0, fmtinput	// 1st arg to printf: string format
	add	x0, x0, :lo12:fmtinput
	mov	w1, w19		// 2nd arg to printf: first number
	mov	w2, w20		// 3rd arg to printf: second number
	mov	w3, w21		// 4th arg to printf: third number
	mov	w4, w22		// 5th arg to printf: fourth number
	mov	w5, w23		// 6th arg to printf: fifth number
	mov	w6, w24		// 7th arg to printf: sixth number
	mov	w7, w25		// 8th arg to printf: seventh number
	bl	printf

	// Sum up the numbers, result is returned in w0.
	mov	w0, w19		// 1st arg to sum: first number
	mov	w1, w20		// 2nd arg to sum: second number
	mov	w2, w21		// 3rd arg to sum: third number
	mov	w3, w22		// 4th arg to sum: fourth number
	mov	w4, w23		// 5th arg to sum: fifth number
	mov	w5, w24		// 6th arg to sum: sixth number
	mov	w6, w25		// 7th arg to sum: seventh number
	bl	sum

	mov	w1, w0		// Save the sum result before we 
				// overwrite x0 with print string format

	// Setup print format for result
	adrp	x0, fmtsum
	add	x0, x0, :lo12:fmtsum
	bl	printf

done:	mov	w0, 0
	ldp	x29, x30, [sp], 16
	ret
