diff options
Diffstat (limited to '4/practice_problem_4_6.c')
| -rw-r--r-- | 4/practice_problem_4_6.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/4/practice_problem_4_6.c b/4/practice_problem_4_6.c new file mode 100644 index 0000000..c6808b7 --- /dev/null +++ b/4/practice_problem_4_6.c @@ -0,0 +1,23 @@ +#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 + cmovg %r11, %r10 x = -x, if -x was positive + addq %r10,%rax Add to sum + addq %r8,%rdi start++ + subq %r9,%rsi count--. Set CC +test: + jne loop Stop when 0 + ret +*/ |
