aboutsummaryrefslogtreecommitdiff
path: root/example/main.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-07-04 23:37:51 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2023-07-04 23:37:51 +0300
commite82c73d2b57e58894d8c93fc720559df6392d58b (patch)
tree3a637c10d0334e21ba3a75fbf5854d0f43efe07e /example/main.c
parent703e37ac56883f9a54b35960fde438c7cfba4592 (diff)
downloadbcgen-e82c73d2b57e58894d8c93fc720559df6392d58b.tar.gz
bcgen-e82c73d2b57e58894d8c93fc720559df6392d58b.zip
add loop example
Diffstat (limited to 'example/main.c')
-rw-r--r--example/main.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/example/main.c b/example/main.c
new file mode 100644
index 0000000..7ca152b
--- /dev/null
+++ b/example/main.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include "../bcode.h"
+
+int main()
+{
+ struct compile_state cs;
+ init(&cs);
+
+ select_movi(&cs, 2, 0); // i
+ select_movi(&cs, 1, 1000000000); // limit
+ select_movi(&cs, 0, 0); // total
+
+ breg_t l = label(&cs); // top
+ select_addr(&cs, 0, 0, 2); // add iter to total
+ select_addi(&cs, 2, 2, 1);
+ breloc_t r = select_bltr(&cs, 2, 1, 0); // 0 is placeholder value,
+ // should maybe add in an
+ // UNDEFINED macro or something
+ end(&cs);
+
+ patch(&cs, r, l);
+
+ printf("%llu\n", (unsigned long long)run(&cs));
+ destroy(&cs);
+}