summaryrefslogtreecommitdiff
path: root/example/test_files
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2023-07-14 07:25:31 -0700
committerMatthew Sotoudeh <matthew@masot.net>2023-07-14 07:25:31 -0700
commit0b12ba0ca00f7cdfb50b614fb24b673fb7e4e322 (patch)
treec8dc0b54c6f9df2f10185fc93f4276f1a8535802 /example/test_files
initial code
Diffstat (limited to 'example/test_files')
-rw-r--r--example/test_files/cycle17
-rw-r--r--example/test_files/fib15
-rw-r--r--example/test_files/hasheq31
3 files changed, 63 insertions, 0 deletions
diff --git a/example/test_files/cycle b/example/test_files/cycle
new file mode 100644
index 0000000..e5fc1d3
--- /dev/null
+++ b/example/test_files/cycle
@@ -0,0 +1,17 @@
+mov tortoise $0
+mov hare $0
+mov cycle_found $0
+label loop
+ ; tortise = tortoise->next
+ load tortoise tortoise
+ ; hare = hare->next->next
+ load hare hare
+ load hare hare
+ ; are_eq = (tortoise == hare)
+ mov are_eq tortoise
+ eq are_eq hare
+ ; cycle found?
+ ite are_eq cycle loop
+label cycle
+ mov cycle_found $1
+end
diff --git a/example/test_files/fib b/example/test_files/fib
new file mode 100644
index 0000000..f197e07
--- /dev/null
+++ b/example/test_files/fib
@@ -0,0 +1,15 @@
+store $0 $0
+store $1 $1
+mov idx $1
+label loop
+ ; fib = f(idx) + f(idx - 1)
+ load fib idx
+ sub idx $1
+ load fib2 idx
+ add idx $1
+ add fib fib2
+ ; memory[idx + 1] = fib
+ add idx $1
+ store idx fib
+ite $1 loop loop
+end
diff --git a/example/test_files/hasheq b/example/test_files/hasheq
new file mode 100644
index 0000000..702c17d
--- /dev/null
+++ b/example/test_files/hasheq
@@ -0,0 +1,31 @@
+; find inputs that hash to the same thing under
+; https://doc.riot-os.org/group__sys__hashes__djb2.html
+; and
+; https://doc.riot-os.org/group__sys__hashes__sdbm.html
+
+mov hash1 $123456
+mov hash2 $789012
+mov same_found $0
+
+mov i $0
+label loop
+ load next_word i
+
+ ; djb2 iteration
+ mul hash1 $33
+ xor hash1 next_word
+
+ ; sdbm iteration
+ mul hash2 $65599
+ add hash2 next_word
+
+ ; compare
+ mov are_eq hash1
+ eq are_eq hash2
+
+ add i $1
+ ite are_eq hashes_same loop
+
+label hashes_same
+ mov same_found $1
+end
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback