summaryrefslogtreecommitdiff
path: root/4/practice_problem_4_5.c
blob: 604de44a9886b41c44c52e4db5abc74fb1891131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>

/*
long sum(long *start, long count)
start in %rdi, count in %rsi
sum:
	irmovq $8,%r8 		Constant 8
	irmovq $1,%r9 		Constant 1
	xorq %rax,%rax		sum = 0
	andq %rsi,%rsi		Set cc
	jmp test		Goto test
loop:
	mrmovq (%rdi), %r10 	Get *start
	xorq %r11, %r11		Constant 0
	subq %r10, %r11		-x
	jle add			if x was positive, skip
	rrmovq %r11, %r10	x = -x
add:
	addq %r10,%rax		Add to sum
	addq %r8,%rdi 		start++
	subq %r9,%rsi 		count--. Set CC
test:
	jne loop		Stop when 0
	ret
*/