summaryrefslogtreecommitdiff
path: root/4/practice_problem_4_5.c
diff options
context:
space:
mode:
authorMike Vink <ivi@vinkies.net>2025-02-16 18:21:50 +0100
committerMike Vink <ivi@vinkies.net>2025-02-16 18:21:50 +0100
commitb9bf3afbb52aebcc0f93df55b55ec0f0f521b1ab (patch)
tree76899e2e38c2a9ca7e40db160a9c86ee0ad4e0dc /4/practice_problem_4_5.c
parent7ae6aa6a64f3f697edb90bb573862bf31dd14e69 (diff)
add some practice problems from 4HEADmaster
Diffstat (limited to '4/practice_problem_4_5.c')
-rw-r--r--4/practice_problem_4_5.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/4/practice_problem_4_5.c b/4/practice_problem_4_5.c
new file mode 100644
index 0000000..604de44
--- /dev/null
+++ b/4/practice_problem_4_5.c
@@ -0,0 +1,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
+*/