Basic documentation completed.
[CS-101.git] / turing_tarpit.html
bloba217b2fb4b475468e09ecc371318dc4290e6d362
1 <html>
2 <title>Turing Tarpit Simulator</title>
3 <script>
5 /* internal values for simulated computer */
6 var ins_pointer = 0; /* instruction pointer */
7 var dat_pointer = 0; /* data pointer */
8 var dat_pointer_changed = 0; /* bool set to 1 if data pointer has changed in the last step */
9 var dat_pointer_last_address = 0; /* address of data pointer in last step */
10 var ram_last_address = 0; /* address of RAM updated in last step */
11 var breakpoints = 1; /* bool set to 0 to ignore breakpoints */
12 var ram = new Array(); /* memory of virtual machine */
13 var jmp = new Array(); /* used as a stack to jump from one command to another */
14 var ins = null; /* current instruction from code */
15 var halt = false; /* halts program ASAP */
17 /* objects that display data to the user */
18 var disp_docs;
19 var disp_code;
20 var disp_ram;
21 var disp_ins_pointer;
22 var disp_dat_pointer;
23 var disp_pointer = "<div id=disp_pointer>&#8658;</div>"; /* data pointer displayed in memory block */
25 /* highlight current instruction running on machine */
26 function code_highlight(inputEl, selStart, selEnd) {
27 if (inputEl.setSelectionRange) {
28 inputEl.focus();
29 inputEl.setSelectionRange(selStart, selEnd);
30 } else if (inputEl.createTextRange) {
31 var range = inputEl.createTextRange();
32 range.collapse(true);
33 range.moveEnd('character', selEnd);
34 range.moveStart('character', selStart);
35 range.select();
39 /* turns breakpoints on and off */
40 function debug_toggle_breakpoints()
42 var button = document.getElementById("dbg_status");
43 if(breakpoints) {
44 breakpoints=0;
45 button.innerHTML='<img src="http://opentextbook.info/icons/32x32/bug_delete.png">';
46 }else {
47 breakpoints=1;
48 button.innerHTML='<img src="http://opentextbook.info/icons/32x32/bug_add.png">';
52 /* removes all breakpoints in source code */
53 function debug_remove_breakpoints()
55 /* ask user for permission first */
56 var ans = confirm("Permanently remove all breakpoints from code?");
57 var code = document.getElementById("code");
58 if(ans) { code.value = code.value.replace( /\*/g , '' ); }
61 /* test current code character - return true if it is an instruction */
62 /* tried to use regex on this and could not get it to work :( */
63 function tst_inst()
65 if(ins == '+' || ins == '-' || ins == '>' || ins == '<' ||
66 ins == '*' || ins == '.' || ins == '[' || ins == ']' || ins == ',') {
67 return true;
69 return false;
72 /* find next instruction in code and move instruction pointer to it */
73 function fnd_nxt_inst()
75 do {
76 if(ins_pointer > disp_code.value.length) { break; } /* must stop at end of code */
77 update_ins_pointer(1);
78 ins = disp_code.value.substring(ins_pointer-1,ins_pointer); /* get data at ins_pointer location */
79 }while(!tst_inst());
80 if(ins_pointer > disp_code.value.length) {
81 alert("HALT: Program is Complete");
82 halt = true;
83 reset();
86 /* highlight code currently executing on screen */
87 code_highlight(disp_code, ins_pointer-1, ins_pointer);
90 /* find previous instruction in code and move instruction pointer to it */
91 function fnd_prv_inst()
93 ins_pointer--;
94 while(ins_pointer >= 0)
96 ins = disp_code.value.substring(ins_pointer-1, ins_pointer); /* get data at ins_pointer location */
97 if(tst_inst()) { return; }
98 ins_pointer--;
100 if(ins_pointer == 0) {
101 alert("SEGFAULT: Program could not find corresponding jump instruction");
102 halt = true;
103 reset();
107 /* execute next instruction from input */
108 function exe_nxt_inst()
110 var temp_count = 0;
111 fnd_nxt_inst();
112 switch(ins)
114 case '+':
115 ram_modify(dat_pointer, 1);
116 break;
117 case '-':
118 ram_modify(dat_pointer, -1);
119 break;
120 case '>':
121 dat_point_modify(1);
122 break;
123 case '<':
124 dat_point_modify(-1);
125 break;
126 case '*': /* these are comments - a break from the standard language */
127 if(breakpoints) { stop(); }
128 break;
129 case '.':
130 print_mem();
131 break;
132 case '[':
133 jump_fwd();
134 break;
135 case ']':
136 jump_bak();
137 break;
138 case ',':
139 break;
140 default:
141 /* must be a comment :) */
145 /* if byte at data pointer is = 0, jump forward to instruction after matching ']' command */
146 function jump_fwd()
148 if(ram[dat_pointer] != 0) { return; }
149 /* add this jump to stack */
150 jmp.push('[');
151 /* loop through code, pushing and popping stack until stack is empty */
152 while(jmp.length > 0) {
153 fnd_nxt_inst();
154 if(ins == ']') { jmp.pop();
155 } else if (ins == '[') { jmp.push(']'); }
159 /* if byte at data pointer is != 0, jump back to instruction after matching '[' command */
160 function jump_bak()
162 if(ram[dat_pointer] == 0) { return; }
163 /* add this jump to stack */
164 jmp.push(']');
165 /* loop through code, pushing and popping stack until stack is empty */
166 while(jmp.length > 0 && ins_pointer > 0) {
167 fnd_prv_inst();
168 if(ins == '[') { jmp.pop();
169 } else if (ins == ']') { jmp.push(']'); }
174 rewind code to beginning reset all memory locations
175 this simulates rebooting the computer
177 function reset()
179 update_ins_pointer(0);
180 dat_point_modify(0);
181 ram_reset();
182 ram_highlight_clear();
183 dat_point_highlight();
184 document.getElementById("output_disp").innerHTML = '';
185 document.getElementById("addr_0").innerHTML = "0" + disp_pointer;
186 dat_point_highlight_clear();
189 /* stop stepping through code on timer if breakpoints enabled */
190 function stop()
192 halt = true;
195 /* run through program on timer, stopping at breakpoints if enabled */
196 function run()
198 var total_steps = document.getElementById("code").value.length;
199 while(ins_pointer <= total_steps && halt == false) { step_next(); }
202 /* step forward one instruction */
203 function step_next()
205 //update_ins_pointer(1);
206 exe_nxt_inst();
207 dat_point_highlight();
210 /* more back one instruction - undoes work of previous instruction */
211 function step_back()
213 update_ins_pointer(-1);
214 dat_point_highlight();
217 /* update instruction pointer
218 direction:
220 1 increment pointer by one
221 0 set pointer to 0
222 -1 decrement pointer by one
224 function update_ins_pointer(direction)
226 if(direction < 0 && ins_pointer != 0 ) { ins_pointer--; }
227 else if (direction == 0 ) { ins_pointer = 0; }
228 else { ins_pointer++; }
229 disp_ins_pointer.value = ins_pointer;
232 /* update instruction pointer and set to new value */
233 function ins_point_modify_by_address(val)
235 /* instruction pointer can never be less than 0 */
236 if(val < 0) {
237 alert("Instruction Pointer cannot be set less than Zero.");
238 disp_ins_pointer.value = ins_pointer; /* reset val to previous */
239 return;
241 if(val > disp_code.value.length) {
242 alert("Instruction Pointer cannot be set beyond end of code.\n Current length of code: " + disp_code.value.length);
243 disp_ins_pointer.value = ins_pointer; /* reset val to previous */
244 return;
246 ins_pointer = disp_ins_pointer.value;
249 /* setup virtual machine - must be called on page load */
250 function init_form()
252 disp_code = document.getElementById("code");
253 disp_ins_pointer = document.getElementById("ins_pointer_disp");
254 disp_dat_pointer = document.getElementById("dat_pointer_disp");
255 disp_ram = document.getElementById("ram_disp");
256 ram_reset();
257 ram_init();
258 document.getElementById("addr_0").innerHTML = "0" + disp_pointer;
259 disp_docs = document.getElementById("docs");
260 /* reset_output(); */
263 /* reset all RAM to 0 */
264 function ram_reset()
266 var i;
267 for(i=0; i < 64; i++) { ram[i] = 0; }
270 /* update highlight of one memory address and release other highlight if needed */
271 function ram_highlight(address)
273 var disp_last_address = document.getElementById("ram_"+ram_last_address);
274 /* highlight background of current address */
275 document.getElementById("ram_"+address).style.backgroundColor = "#ff0";
277 /* remove highlight from last address modified */
278 if(ram_last_address != address){
279 if(ram_last_address%2==0) {
280 disp_last_address.style.backgroundColor = "#fff";
281 } else {
282 disp_last_address.style.backgroundColor = "#def";
287 /* remove highlight from all memory cells regardless of current status */
288 function ram_highlight_clear()
290 var i;
291 for(i=0; i < 64; i++)
293 if(i%2==0) {
294 document.getElementById("ram_"+i).style.backgroundColor = "#fff";
295 } else {
296 document.getElementById("ram_"+i).style.backgroundColor = "#def";
298 document.getElementById("ram_"+i).innerHTML = ram[i];
302 /* define RAM on screen */
303 function ram_init()
305 var i;
306 var table = "<table id=memory_table>\n";
307 for(i=0; i < 16; i++){
308 if(i%2==0) {
309 table += "\t<tr class=even>";
310 } else {
311 table += "\t<tr class=odd>";
313 table += "<td width='35' class=addr id=addr_"+i+">"+i+"</td><td width='35' class=ram id=ram_"+i+">"+ram[i]+"</td>";
314 table += "<td width='35' class=addr id=addr_"+(i+16)+">"+(i+16)+"</td><td class=ram id=ram_"+(i+16)+">"+ram[i+16]+"</td>\n";
315 table += "<td class=addr id=addr_"+(i+32)+">"+(i+32)+"</td><td width='35' class=ram id=ram_"+(i+32)+">"+ram[i+32]+"</td>\n";
316 table += "<td class=addr id=addr_"+(i+48)+">"+(i+48)+"</td><td width='35' class=ram id=ram_"+(i+48)+">"+ram[i+48]+"</td></tr>\n";
318 table += "</table>\n";
319 disp_ram.innerHTML = table;
323 modify the value at this address - reset RAM highlights for all addresses
324 1 increment RAM by one
325 0 set RAM to 0
326 -1 decrement RAM by one
328 function ram_modify(address, change)
330 if(address < 0 || address > 63) {
331 alert("SEGFAULT: Cannot Modify Data Outside of Memory Range");
332 halt = true;
333 reset();
334 return;
337 if (change > 0 ) {
338 ram[address]++;
339 } else if(change < 0 ) {
340 ram[address]--;
341 } else {
342 ram[address] = 0;
344 ram_highlight(address);
345 document.getElementById("ram_"+address).innerHTML = ram[address];
346 ram_last_address = address;
350 modify state of data pointer
351 1 increment data pointer by one
352 0 set data pointer to 0
353 -1 decrement data pointer by one
356 function dat_point_modify(change)
358 dat_pointer_last_address = dat_pointer;
359 if (change > 0 ) {
360 dat_pointer++;
361 } else if(change < 0 ) {
362 /* could put SEGFAULT here, but C does not have a check for this, so neither will I ;) */
363 dat_pointer--;
364 } else {
365 dat_pointer = 0;
368 /* place '>' char next to memory address in table */
369 if(dat_pointer >= 0 && dat_pointer < 64) {
370 document.getElementById("addr_"+dat_pointer).innerHTML = dat_pointer + disp_pointer;
373 /* remove '>' char next to memory address in table */
374 if(dat_pointer_last_address >= 0 && dat_pointer_last_address < 64) {
375 document.getElementById("addr_"+dat_pointer_last_address).innerHTML = dat_pointer_last_address;
378 disp_dat_pointer.value = dat_pointer;
379 dat_pointer_changed = 1;
382 function dat_point_modify_by_address(val)
384 dat_pointer_last_address = dat_pointer;
385 dat_pointer = disp_dat_pointer.value;
386 /* place '>' char next to memory address in table */
387 if(dat_pointer >= 0 && dat_pointer < 64) {
388 document.getElementById("addr_"+dat_pointer).innerHTML = dat_pointer + disp_pointer;
391 /* remove '>' char next to memory address in table */
392 if(dat_pointer_last_address >= 0 && dat_pointer_last_address < 64) {
393 document.getElementById("addr_"+dat_pointer_last_address).innerHTML = dat_pointer_last_address;
395 dat_pointer_changed = 1;
396 dat_point_highlight();
399 /* turns on and off data pointer highlight if it has changed this step */
400 function dat_point_highlight()
402 if(dat_pointer_changed) {
403 disp_dat_pointer.style.backgroundColor = "#ff0";
404 dat_pointer_changed = 0;
405 } else {
406 disp_dat_pointer.style.backgroundColor = "#fff";
409 /* as a convenience to the user, set to red if pointer is out of memory range */
410 if(dat_pointer < 0 || dat_pointer > 63) {
411 disp_dat_pointer.style.backgroundColor = "#f00";
415 /* remove highlight from data pointer */
416 function dat_point_highlight_clear()
418 disp_dat_pointer.style.backgroundColor = "#fff";
421 /* print ASCII representation of memory at data pointer */
422 function print_mem()
424 var x = String.fromCharCode(ram[dat_pointer]);
425 document.getElementById("output_disp").innerHTML += x;
428 /* documentation stored inside invisible div. This shows its contents. */
429 function display_docs()
431 disp_docs.style.visibility = "visible";
432 docs_select("docs_main");
435 /* hide documentation from user */
436 function hide_docs()
438 disp_docs.style.visibility = "hidden";
441 function docs_select(page)
443 if(page == "basic") {
444 document.getElementById("docs_content").innerHTML = document.getElementById("docs_basic").innerHTML;
445 } else if(page == "features") {
446 document.getElementById("docs_content").innerHTML = document.getElementById("docs_features").innerHTML;
447 } else if(page == "examples") {
448 document.getElementById("docs_content").innerHTML = document.getElementById("docs_examples").innerHTML;
449 } else if(page == "examples2") {
450 document.getElementById("docs_content").innerHTML = document.getElementById("docs_examples2").innerHTML;
451 } else {
452 document.getElementById("docs_content").innerHTML = document.getElementById("docs_main").innerHTML;
456 </script>
458 <style type="text/css">
460 body {
461 font-family: Tahoma, Arial, Helvetica, sans-serif;
464 #disp_pointer {
465 float:right;
466 color: #f00;
469 #code_buttons {
470 position: absolute;
471 top: 570px;
472 left: 10px;
475 #input_banner {
476 position: absolute;
477 top: 120px;
478 left: 10px;
481 #da_banner {
482 position: absolute;
483 top: 360px;
484 left: 625px;
487 #ref_banner {
488 position: absolute;
489 top: 410px;
490 left: 625px;
493 #ip_banner {
494 position: absolute;
495 top: 315px;
496 left: 625px;
499 #output_banner {
500 position: absolute;
501 top: 120px;
502 left: 625px;
505 #memory_banner {
506 position: absolute;
507 top: 120px;
508 left: 315px;
511 #input {
512 position: absolute;
513 top: 140px;
514 left: 10px;
517 #ram_disp {
518 position: absolute;
519 top: 140px;
520 left: 315px;
523 #memory_table {
524 border:1px solid #000;
525 border-collapse: collapse;
528 .even td {
529 padding: 4px;
530 border-bottom:1px solid #000;
533 .odd td {
534 padding: 4px;
535 background-color: #def;
536 border-bottom: 1px solid #000;
539 .addr {
540 color: #00f;
543 .ram {
544 border-right:1px solid #000;
547 #output {
548 position: absolute;
549 top: 140px;
550 left: 625px;
553 #docs {
554 border:1px solid #000;
555 background-color: #dfd;
556 position: absolute;
557 top: 10px;
558 left: 10px;
559 width: 1000px;
560 height:700px;
561 visibility: hidden;
564 #docs_top_banner {
565 color: #fff;
566 background-color: #88f;
567 border-bottom:1px solid #000;
568 position: absolute;
569 top: 0px;
570 left: 0px;
571 height: 25px;
572 padding-top: 5px;
573 padding-left: 5px;
574 width: 995px;
577 #docs_close_btn {
578 background-color: #f00;
579 border:3px solid #000;
580 position: absolute;
581 top: 0px;
582 right: 0px;
583 height: 25px;
584 cursor: pointer;
587 #docs_mnu_btn {
588 border:2px solid #000;
589 background-color: #faa;
590 color: #000;
591 position: absolute;
592 top: 0px;
593 left: 375px;
594 height: 25px;
595 padding-top: 3px;
596 padding-left: 20px;
597 padding-right: 20px;
598 cursor: pointer;
601 #docs_content {
602 position: absolute;
603 top: 35px;
604 padding: 10px;
607 #docs_link:hover {
608 background-color: #faa;
609 cursor: pointer;
613 .docs_code_ex {
614 background-color: #fff;
615 border: 1px solid #ddd;
616 padding: 5px;
619 .docs_hidden {
620 visibility: hidden;
623 #instruction {
624 position: absolute;
625 top: 335px;
626 left: 625px;
629 #data {
630 position: absolute;
631 top: 385px;
632 left: 625px;
635 #reference {
636 position: absolute;
637 top: 430px;
638 left: 625px;
639 width: 280px;
642 </style>
643 <body onLoad="init_form();">
645 <center><h2>Turing Tarpit Simulator</h2></center>
647 <center>
648 <button onClick='reset();'><img src="http://opentextbook.info/icons/32x32/resultset_first.png"></button>
649 &nbsp;&nbsp;
650 <button onClick='step_back();'><img src="http://opentextbook.info/icons/32x32/resultset_previous.png"></button>
651 &nbsp;&nbsp;
652 <button onClick='step_next();'><img src="http://opentextbook.info/icons/32x32/resultset_next.png"></button>
653 &nbsp;&nbsp;
654 <button onClick='run();'><img src="http://opentextbook.info/icons/32x32/resultset_last.png"></button>
655 &nbsp;&nbsp;
656 <button onClick='halt();'><img src="http://opentextbook.info/icons/32x32/cancel.png"></button>
657 &nbsp;&nbsp;
658 <button disabled><img src="http://opentextbook.info/icons/32x32/disk.png"></button>
659 &nbsp;&nbsp;
660 <button onClick='display_docs();'><img src="http://opentextbook.info/icons/32x32/book_open.png"></button>
661 </center>
663 <div id="code_buttons">
664 <button id="dbg_status" onClick='debug_toggle_breakpoints();'>
665 <img src="http://opentextbook.info/icons/32x32/bug_add.png">
666 </button>
667 &nbsp;&nbsp;
668 <button id="dbg_status" onClick='debug_remove_breakpoints();'>
669 <img src="http://opentextbook.info/icons/32x32/bin.png">
670 </button>
671 </div>
673 <div id="input_banner">INPUT</div>
674 <div id="input"><textarea id="code" rows="27" cols="38"></textarea></div>
676 <div id="ip_banner">INSTRUCTION POINTER</div>
677 <div id="instruction"><input onBlur="ins_point_modify_by_address(disp_ins_pointer.value);" id="ins_pointer_disp" type="text" diabled value=0></div>
679 <div id="da_banner">DATA POINTER</div>
680 <div id="data"><input onBlur="dat_point_modify_by_address(disp_dat_pointer.value);" id="dat_pointer_disp" type="text" diabled value=0></div>
682 <div id="ref_banner">INSTRUCTION REFERENCE</div>
683 <table id="reference">
684 <tr><td>+</td><td>increment byte at data pointer</td></tr>
685 <tr><td>-</td><td>decrement byte at data pointer</td></tr>
686 <tr><td>></td><td>increment data pointer</td></tr>
687 <tr><td><</td><td>decrement data pointer</td></tr>
688 <tr><td>.</td><td>print byte at data pointer</td></tr>
689 <tr><td>,</td><td>accept one byte of input</td></tr>
690 <tr><td>*</td><td>set breakpoint</td></tr>
691 </table>
693 <div id="memory_banner">MEMORY</div>
694 <div id="ram_disp"></div>
695 <div id="output_banner">OUTPUT</div>
696 <div id="output">
697 <textarea name=code id=output_disp rows="10" cols="38" disabled ></textarea>
698 </div>
699 <div id="docs">
700 <div id="docs_top_banner">
701 Turing Tarpit Simulator Documentation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
702 <div id="docs_mnu_btn" onClick="docs_select('main');">Main Menu</div>
703 <div id="docs_close_btn" onClick="hide_docs();">X</div></div>
705 <div id="docs_content"></div>
706 </div>
708 <div id="docs_main" class="docs_hidden">
709 <div id="docs_link" onClick="docs_select('basic');">Basic Operation</div>
710 <div id="docs_link" onClick="docs_select('features');">Features and Hints</div>
711 <div id="docs_link" onClick="docs_select('examples');">Example Code 1</div>
712 <div id="docs_link" onClick="docs_select('examples2');">Example Code 2</div>
714 </div>
716 <div id="docs_basic" class="docs_hidden">
718 Basic
720 <p>This program is completely self contained in one HTML document. You are free do use it how you wish, subject to the terms and conditions of the GNU GPL license (version 3).
722 <p>Although it has not been tested in all browsers, it should work well under most any modern web browser that supports Dynamic HTML and JavaScript. You must have JavaScript enabled for this application to work properly.
724 <p>No server interaction or outside service is needed for this program to operate.
726 </div>
728 <div id="docs_features" class="docs_hidden">
730 Features and Hints
732 <p>All characters outside the Instruction Set are considered comments and will be skipped over during runtime.
734 <p>While program executes, the Input cursor is moved over the current instruction.
736 <p>User can change the address of the Data Pointer and Instruction Pointer at any time.
737 Memory and pointers that have been modified are highlighted in yellow until the next step.
739 <p>The Data Pointer can point to any location. If you de-reference a pointer out of memory range, a segfault error will occur. This causes the computer to reboot without warning.
741 <p>The Instruction Pointer can point to a location range of 1 to the number of characters in the input.
743 <p>Restarting the machine will reset all Memory, Data and Instruction Pointers to zero.
745 <p>The output of the program cannot be edited.
747 <p>A user can add a break instruction in the code using an asterisk '*'. This will cause the machine to pause when in Run Mode. Breaks can be disabled and enabled with the debug button, and can be permanently deleted with the delete button.
749 <p>In this version the programs you type in are not saved to your computer. This must be done as a manual operation.
751 <p>As this program is reliant on the speed and efficiency of your browsers JavaScript implementation some computers will be able to execute programs faster than others.
753 </div>
755 <div id="docs_examples" class="docs_hidden">
756 These are some examples of programs and snippets to get you started. Click the "Load" button to apply these to the Input of the simulator. (Please Note: You will erase the current program stored there.) Many of these examples can be found at Wikipedia.
758 <p><b>Clear Byte:</b>
759 Sets value at current Data Pointer to Zero.
760 <div class=docs_code_ex>
762 </div>
763 <p><b>Clear Previous Cells:</b>
764 Sets value of all previous bytes including current byte to Zero.
765 <div class=docs_code_ex>
766 [[-]<]
767 </div>
768 <p><b>Rewind:</b>
769 Goes back to byte Zero.
770 <div class=docs_code_ex>
771 [<]>
772 </div>
773 <p><b>Fast-forward:</b>
774 Increments the data pointer until a 0 is found then decrements if until the current cell is non-zero.
775 <div class=docs_code_ex>
776 [>]<
777 </div>
778 <p><b>Simple Loop:</b>
779 Accepts input from the user and echos it to the screen, similar to the UNIX cat program.
780 <div class=docs_code_ex>
781 ,[.,]
782 </div>
783 <p><b>Moving the Data Pointer:</b>
784 Accepts input from the user and saves all input in the memory for future use.
785 <div class=docs_code_ex>
786 >,[.>,]
787 </div>
788 </div>
791 <div id="docs_examples2" class="docs_hidden">
792 <p><b>Add Two Bytes:</b>
793 Adds current location to the next location and leaves behind a Zero for the first value.
794 <div class=docs_code_ex>
795 [->+<]
796 </div>
797 <p><b>Lower To Upper:</b>
798 Accepts lower case input from the user and makes it uppercase. Stops when user presses the enter key.
799 <div class=docs_code_ex>
800 ,----------[----------------------.,----------]
801 </div>
802 <p><b>Copy Value:</b>
803 Copy value of byte Zero to byte One.
804 <div class=docs_code_ex>
805 >[-]>[-]<<[->+>+<<]>>[-<<+>>]<<
806 </div>
807 <p><b>Seek:</b>
808 Move Data Pointer forward until it lands on a byte with a value of 1, preserving all bytes it passes.
809 <div class=docs_code_ex>
810 -[+>-]+
811 </div>
812 <p><b>Single Digit Add:</b>
813 Adds two single digit numbers and display result. Works on one-digit results only.
814 <div class=docs_code_ex>
815 ,>++++++[<-------->-],[<+>-]<.
816 </div>
817 <p><b>Single Digit Multiplication:</b>
818 Multiply two single digit numbers and display result. Works on one-digit results only.
819 <div class=docs_code_ex>
820 ,>,>++++++++[<------<------>>-]
821 <<[>[>+>+<<-]>>[<<+>>-]<<<-]
822 >>>++++++[<++++++++>-]<.>.
823 </div>
824 <p><b>Single Digit Division:</b>
825 Accepts two single-digit numbers from the user, divides them and displays the truncated quotient. Dividend is stored in byte Zero and Divisor is stored in byte One.
826 <div class=docs_code_ex>
827 ,>,>++++++[-<--------<-------->>]<<[>[->+>+<<]>[-<<-[>]>>>[<[>>>-<<<[-]]>>]<<]>>>+<<[-<<+>>]<<<]>[-]>>>>[-<<<<<+>>>>>]<<<<++++++[-<++++++++>]<.
828 </div>
829 </div>
830 </body>
831 </html>