aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/fib.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-19 22:33:35 +0200
committerlemon <lsof@mailbox.org>2023-06-19 22:33:35 +0200
commit61367525aea8f3f11c29e628fe49768dda959cef (patch)
tree7f3f428b40086c20ebc2e7aa54f49b4394b6e820 /test/fib.c
parent88bf0602d09bebbf18213fbf02821e9f63b964a8 (diff)
backend: compile comparison instrs and branches
Diffstat (limited to 'test/fib.c')
-rw-r--r--test/fib.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/fib.c b/test/fib.c
new file mode 100644
index 0000000..6254a5f
--- /dev/null
+++ b/test/fib.c
@@ -0,0 +1,19 @@
+unsigned fib(unsigned x) {
+ unsigned r = 0, q = 1;
+ while (x--) {
+ unsigned s = r + q;
+ r = q;
+ q = s;
+ }
+ return q;
+}
+
+int atoi(const char *);
+int printf(const char *, ...);
+
+int main(int argc, char **argv) {
+ unsigned n = argv[1] ? atoi(argv[1]) : 10;
+ printf("fib(%u) = %u\n", n, fib(n));
+}
+
+/* vim:set ts=3 sw=3 expandtab: */