# Execution begins at address 0 
	.pos 0 
	irmovq stack, %rsp  	# Set up stack pointer  
	call main		# Execute main program
	halt			# Terminate program 

# Array of 4 elements
	.align 8 	
array:	.quad 0x000d000d000d
	.quad 0x00c000c000c0
	.quad 0x0b000b000b00
	.quad 0xa000a000a000

main:	irmovq array,%rdi	
	irmovq $4,%rsi
	call rsum		# rsum(array, 4)
	ret

/* $begin rsum-ys */
# long rsum(long *start, long count)
# start in %rdi, count in %rsi
rsum:
	xorq %rax,%rax		# Set return value to 0
	andq %rsi,%rsi		# Set condition codes
	jle     return		# If count <= 0, return 0
	pushq %rbx		# Save callee-saved register
	mrmovq (%rdi),%rbx	# Get *start
	irmovq $-1,%r10
	addq %r10,%rsi		# count--
	irmovq $8,%r10          
	addq %r10,%rdi          # start++
	call rsum
	addq %rbx,%rax          # Add *start to sum
	popq %rbx		# Restore callee-saved register
return:
	ret
/* $end rsum-ys */

# The stack starts here and grows to lower addresses
	.pos 0x200		
stack:	 

