	.arch armv6
	.eabi_attribute 28, 1
	.eabi_attribute 20, 1
	.eabi_attribute 21, 1
	.eabi_attribute 23, 3
	.eabi_attribute 24, 1
	.eabi_attribute 25, 1
	.eabi_attribute 26, 2
	.eabi_attribute 30, 6
	.eabi_attribute 34, 1
	.eabi_attribute 18, 4
	.file	"Prg4.c"
	.text
	.align	2
	.global	rangeSum
	.syntax unified
	.arm
	.fpu vfp
	.type	rangeSum, %function
rangeSum:
	str	lr, [sp, #-4]!  @ Save lr to stack
	str	fp, [sp, #-4]!  @ Save fp to stack
	mov	fp, sp          @ Point fp to bottom of new frame
	sub	sp, sp, #12     @ Reserve 3 words of frame space
	str	r0, [fp, #-8]   @ First param second from TOS
	str	r1, [fp, #-12]  @ Second param at TOS
	mov	r3, #0          @ sum = 0
	str	r3, [fp, #-4]   @ sum third from TOS
	b	.L2
.L3:
	ldr	r3, [fp, #-8]   @ r3 = lo
	add	r2, r3, #1      @ r2 = lo+1
	str	r2, [fp, #-8]   @ lo = lo+1
	ldr	r2, [fp, #-4]   @ r2 = sum
	add	r3, r2, r3      @ sum = sum + lo (before incr)
	str	r3, [fp, #-4]   @ Copy back to frame
.L2:
	ldr	r2, [fp, #-8]   @ r2 = lo
	ldr	r3, [fp, #-12]  @ r3 = hi
	cmp	r2, r3          @ if r2 < r3
	blt	.L3             @    loop again

	ldr	r0, [fp, #-4]   @ Return value in R0
	mov	sp, fp          @ Pop off local vars
	ldr	fp, [sp], #4    @ Restore fp to old val, and reduce sp
	ldr	pc, [sp], #4    @ Back to caller

	.section	.rodata
	.align	2
.LC0:
	.ascii	"%d\012\000"
	.text
	.align	2
	.global	main
main:
	str	lr, [sp, #-4]!  @ Save lr to stack
	str	fp, [sp, #-4]!  @ Save fp to stack
	mov	fp, sp          @ Point fp to bottom of new frame
	sub	sp, sp, #4      @ Reserve one word of space for total
	mov	r0, #10
	mov	r1, #20
	bl	rangeSum
   str   r0, [fp, #-4]   @ Store total into frame

	ldr	r0, .L6         @ R0 gets address of format string
	ldr	r1, [fp, #-4]   @ R1 gets total
	bl	printf

   mov   r0, #0          @ Return 0 from main
	mov	sp, fp          @ Pop off local var total
	ldr	fp, [sp], #4    @ Restore fp to old val, and reduce sp
	ldr	pc, [sp], #4    @ Back to compiler-provided caller
.L6:
	.word	.LC0
	.align	2
.L7:
	.word	.LC0
	.size	main, .-main
	.ident	"GCC: (Raspbian 6.3.0-18+rpi1) 6.3.0 20170516"
	.section	.note.GNU-stack,"",%progbits
