aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-11-16 18:42:30 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-11-16 18:42:30 +0100
commit2f6a51855571ee12bad247ac026aa02a061800f0 (patch)
tree82fb10f7f697ec2c1cd24aa39c517a67c401857b /examples
parent2d3d9d3a5fd436735b912d1fe0ad731a81eca036 (diff)
downloadbfc-2f6a51855571ee12bad247ac026aa02a061800f0.tar.gz
bfc-2f6a51855571ee12bad247ac026aa02a061800f0.tar.bz2
bfc-2f6a51855571ee12bad247ac026aa02a061800f0.zip
Updated to generate correct assembly (segfaults)
Diffstat (limited to 'examples')
-rw-r--r--examples/add_2_5.bf20
-rw-r--r--examples/getchar_putchar.bf1
2 files changed, 21 insertions, 0 deletions
diff --git a/examples/add_2_5.bf b/examples/add_2_5.bf
new file mode 100644
index 0000000..a6425d7
--- /dev/null
+++ b/examples/add_2_5.bf
@@ -0,0 +1,20 @@
+++ ; Cell c0 = 2
+> +++++ ; Cell c1 = 5
+
+[ ; Start your loops with your cell pointer on the loop counter (c1 in our case)
+< + ; Add 1 to c0
+> - ; Subtract 1 from c1
+] ; End your loops with the cell pointer on the loop counter
+
+; At this point our program has added 5 to 2 leaving 7 in c0 and 0 in c1
+; but we cannot output this value to the terminal since it is not ASCII encoded.
+
+; To display the ASCII character "7" we must add 48 to the value 7.
+; We use a loop to compute 48 = 6 * 8.
+
+++++ ++++ ; c1 = 8 and this will be our loop counter again
+[
+< +++ +++ ; Add 6 to c0
+> - ; Subtract 1 from c1
+]
+< . ; Print out c0 which has the value 55 which translates to "7"!
diff --git a/examples/getchar_putchar.bf b/examples/getchar_putchar.bf
new file mode 100644
index 0000000..f36f02a
--- /dev/null
+++ b/examples/getchar_putchar.bf
@@ -0,0 +1 @@
+,.