diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-12-03 00:02:12 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-12-03 00:02:12 +0000 |
commit | 623b3acc1f8b719b15523982ff5ed04eb85b19d5 (patch) | |
tree | 5aee01714fd4bcf60971356889f1192f797c5690 /examples | |
parent | c2a4eb3985de412b548a713ed72ee752f4ee8e3b (diff) | |
download | obf-623b3acc1f8b719b15523982ff5ed04eb85b19d5.tar.gz obf-623b3acc1f8b719b15523982ff5ed04eb85b19d5.tar.bz2 obf-623b3acc1f8b719b15523982ff5ed04eb85b19d5.zip |
Added some examples to test the interpreter
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hello-world.bf | 1 | ||||
-rw-r--r-- | examples/print-0-99.bf | 29 | ||||
-rw-r--r-- | examples/rot13.bf | 28 | ||||
-rw-r--r-- | examples/simple-adder.bf | 20 |
4 files changed, 78 insertions, 0 deletions
diff --git a/examples/hello-world.bf b/examples/hello-world.bf new file mode 100644 index 0000000..ea2b641 --- /dev/null +++ b/examples/hello-world.bf @@ -0,0 +1 @@ +++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
\ No newline at end of file diff --git a/examples/print-0-99.bf b/examples/print-0-99.bf new file mode 100644 index 0000000..13e6d5e --- /dev/null +++ b/examples/print-0-99.bf @@ -0,0 +1,29 @@ +++++++++++ +>++++++++++++++++++++++++++++++++++++++++++++++++ +>++++++++++ +[ + + >++++++++++++++++++++++++++++++++++++++++++++++++ + >++++++++++ + [ + + >++++++++++++++++++++++++++++++++++++++++++++++++ + >++++++++++ + [ + <<<<<. + >>. + >>.+ + <<<<<. + >>>>>>- + ] + <---------------------------------------------------------- + + <<+ + >- + ] + <---------------------------------------------------------- + + <<+ + > + - +] diff --git a/examples/rot13.bf b/examples/rot13.bf new file mode 100644 index 0000000..7be1cc7 --- /dev/null +++ b/examples/rot13.bf @@ -0,0 +1,28 @@ +-,+[ Read first character and start outer character reading loop + -[ Skip forward if character is 0 + >>++++[>++++++++<-] Set up divisor (32) for division loop + (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) + <+<-[ Set up dividend (x minus 1) and enter division loop + >+>+>-[>>>] Increase copy and remainder / reduce divisor / Normal case: skip forward + <[[>+<-]>>+>] Special case: move remainder back to divisor and increase quotient + <<<<<- Decrement dividend + ] End division loop + ]>>>[-]+ End skip loop; zero former divisor and reuse space for a flag + >--[-[<->+++[-]]]<[ Zero that flag unless quotient was 2 or 3; zero quotient; check flag + ++++++++++++<[ If flag then set up divisor (13) for second division loop + (MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero) + >-[>+>>] Reduce divisor; Normal case: increase remainder + >[+[<+>-]>+>>] Special case: increase remainder / move it back to divisor / increase quotient + <<<<<- Decrease dividend + ] End division loop + >>[<+>-] Add remainder back to divisor to get a useful 13 + >[ Skip forward if quotient was 0 + -[ Decrement quotient and skip forward if quotient was 1 + -<<[-]>> Zero quotient and divisor if quotient was 2 + ]<<[<<->>-]>> Zero divisor and subtract 13 from copy if quotient was 1 + ]<<[<<+>>-] Zero divisor and add 13 to copy if quotient was 0 + ] End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) + <[-] Clear remainder from first division if second division was skipped + <.[-] Output ROT13ed character from copy and clear it + <-,+ Read next character +] End character reading loop
\ No newline at end of file diff --git a/examples/simple-adder.bf b/examples/simple-adder.bf new file mode 100644 index 0000000..3f5f2ee --- /dev/null +++ b/examples/simple-adder.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"!
\ No newline at end of file |