summaryrefslogtreecommitdiff
path: root/3
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2024-05-22 08:58:05 +0200
committerMike Vink <mike@pionative.com>2024-05-22 08:58:05 +0200
commit758543aef80c3b3568a20b0dff20202c796a4819 (patch)
tree7ae11e919fb961b72f07ab5a6e9516d814082823 /3
parent51169f5f9ab178a4ddfe9dac461405a71c9c0f94 (diff)
24 and 25
Diffstat (limited to '3')
-rw-r--r--3/6_control/24_while_loop.c8
-rw-r--r--3/6_control/25_while_guard.c13
2 files changed, 17 insertions, 4 deletions
diff --git a/3/6_control/24_while_loop.c b/3/6_control/24_while_loop.c
index a3367fc..18a6c70 100644
--- a/3/6_control/24_while_loop.c
+++ b/3/6_control/24_while_loop.c
@@ -11,10 +11,10 @@
short loop_while(short a, short b)
{
- short result = ;
- while () {
- result = ;
- a = ;
+ short result = 0;
+ while (a > b) {
+ result = result + a*b;
+ a = a - 1;
}
return result;
}
diff --git a/3/6_control/25_while_guard.c b/3/6_control/25_while_guard.c
new file mode 100644
index 0000000..ad33917
--- /dev/null
+++ b/3/6_control/25_while_guard.c
@@ -0,0 +1,13 @@
+// %rdi <- a
+// %rsi <- b
+// loop:
+// testq %rsi, %rsi
+// jle .L8
+long loop_while2(long a, long b) {
+ long result = b;
+ while (b > 0) {
+ result = result * a;
+ b = b - a;
+ }
+ return result;
+}