Updated Documentation
[CS-101.git] / turing_tarpit.html
blobf3d5722b75f916a1fc0841906c8d1472d71103e7
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 ins_pointer_changed = 0; /* bool set to 1 if ins pointer has changed in the last step */
8 var ins_pointer_last_address = 0; /* address of ins pointer in last step */
9 var dat_pointer = 0; /* data pointer */
10 var dat_pointer_changed = 0; /* bool set to 1 if data pointer has changed in the last step */
11 var dat_pointer_last_address = 0; /* address of data pointer in last step */
12 var ram_last_address = 0; /* address of RAM updated in last step */
13 var breakpoints = 1; /* bool set to 0 to ignore breakpoints */
14 var ram = new Array(); /* memory of virtual machine */
15 var jmp = new Array(); /* used as a stack to jump from one command to another */
16 var ins = null; /* current instruction from code */
17 var halt = false; /* halts program ASAP */
19 /* objects that display data to the user */
20 var disp_docs;
21 var disp_code;
22 var disp_ram;
23 var disp_ins_pointer;
24 var disp_dat_pointer;
25 var disp_pointer = "<div id=disp_pointer>&#8658;</div>"; /* data pointer displayed in memory block */
27 /* select all contents of this input for the convenience of the user */
28 function select_all(e)
30 document.getElementById(e).focus();
31 document.getElementById(e).select();
34 /* highlight current instruction running on machine */
35 function code_highlight(inputEl, selStart, selEnd)
37 if (inputEl.setSelectionRange) {
38 inputEl.focus();
39 inputEl.setSelectionRange(selStart, selEnd);
40 } else if (inputEl.createTextRange) {
41 var range = inputEl.createTextRange();
42 range.collapse(true);
43 range.moveEnd('character', selEnd);
44 range.moveStart('character', selStart);
45 range.select();
49 /* turns breakpoints on and off */
50 function debug_toggle_breakpoints()
52 var button = document.getElementById("dbg_status");
53 if(breakpoints) {
54 breakpoints=0;
55 button.innerHTML='<img src="http://opentextbook.info/icons/32x32/bug_delete.png">';
56 }else {
57 breakpoints=1;
58 button.innerHTML='<img src="http://opentextbook.info/icons/32x32/bug_add.png">';
62 /* removes all breakpoints in source code */
63 function debug_remove_breakpoints()
65 /* ask user for permission first */
66 var ans = confirm("Permanently remove all breakpoints from code?");
67 var code = document.getElementById("code");
68 if(ans) { code.value = code.value.replace( /\*/g , '' ); }
71 /* test current code character - return true if it is an instruction */
72 /* tried to use regex on this and could not get it to work :( */
73 function tst_inst()
75 if(ins == '+' || ins == '-' || ins == '>' || ins == '<' ||
76 ins == '*' || ins == '.' || ins == '[' || ins == ']' || ins == ',') {
77 return true;
79 return false;
82 /* find next instruction in code and move instruction pointer to it */
83 function fnd_nxt_inst()
85 do {
86 if(ins_pointer > disp_code.value.length) { break; } /* must stop at end of code */
87 update_ins_pointer(1);
88 ins = disp_code.value.substring(ins_pointer-1,ins_pointer); /* get data at ins_pointer location */
89 }while(!tst_inst());
90 if(ins_pointer > disp_code.value.length) {
91 alert("HALT: Program is Complete");
92 halt = true;
93 reset();
96 /* highlight code currently executing on screen */
97 code_highlight(disp_code, ins_pointer-1, ins_pointer);
100 /* find previous instruction in code and move instruction pointer to it */
101 function fnd_prv_inst()
103 ins_pointer--;
104 while(ins_pointer >= 0)
106 ins = disp_code.value.substring(ins_pointer-1, ins_pointer); /* get data at ins_pointer location */
107 if(tst_inst()) { return; }
108 ins_pointer--;
110 if(ins_pointer == 0) {
111 alert("SEGFAULT: Program could not find corresponding jump instruction");
112 halt = true;
113 reset();
117 /* execute next instruction from input */
118 function exe_nxt_inst()
120 var temp_count = 0;
121 fnd_nxt_inst();
122 switch(ins)
124 case '+':
125 ram_modify(dat_pointer, 1);
126 break;
127 case '-':
128 ram_modify(dat_pointer, -1);
129 break;
130 case '>':
131 dat_point_modify(1);
132 break;
133 case '<':
134 dat_point_modify(-1);
135 break;
136 case '*': /* these are comments - a break from the standard language */
137 if(breakpoints) { stop(); }
138 break;
139 case '.':
140 print_mem();
141 break;
142 case '[':
143 jump_fwd();
144 break;
145 case ']':
146 jump_bak();
147 break;
148 case ',':
149 get_byte();
150 break;
151 default:
152 /* must be a comment :) */
156 /* if byte at data pointer is = 0, jump forward to instruction after matching ']' command */
157 function jump_fwd()
159 if(ram[dat_pointer] != 0) { return; }
160 /* add this jump to stack */
161 jmp.push('[');
162 /* loop through code, pushing and popping stack until stack is empty */
163 while(jmp.length > 0) {
164 fnd_nxt_inst();
165 if(ins == ']') { jmp.pop();
166 } else if (ins == '[') { jmp.push(']'); }
170 /* if byte at data pointer is != 0, jump back to instruction after matching '[' command */
171 function jump_bak()
173 if(ram[dat_pointer] == 0) { return; }
174 /* add this jump to stack */
175 jmp.push(']');
176 /* loop through code, pushing and popping stack until stack is empty */
177 while(jmp.length > 0 && ins_pointer > 0) {
178 fnd_prv_inst();
179 if(ins == '[') { jmp.pop();
180 } else if (ins == ']') { jmp.push(']'); }
184 /* get single byte of input from the user */
185 function get_byte()
187 var b = prompt("Please Single Byte of Data","");
188 alert(b);
189 ram_set(dat_pointer, b.charCodeAt(b));
193 rewind code to beginning reset all memory locations
194 this simulates rebooting the computer
196 function reset()
198 update_ins_pointer(0);
199 dat_point_modify(0);
200 ram_reset();
201 ram_highlight_clear();
202 dat_point_highlight();
203 document.getElementById("output_disp").innerHTML = '';
204 document.getElementById("addr_0").innerHTML = "0" + disp_pointer;
205 disp_ins_pointer.style.backgroundColor = "#fff";
206 dat_point_highlight_clear();
207 code_highlight(disp_code, 0, 1);
210 /* stop stepping through code on timer if breakpoints enabled */
211 function stop()
213 halt = true;
216 /* run through program on timer, stopping at breakpoints if enabled */
217 function run()
219 var total_steps = document.getElementById("code").value.length;
220 halt = false; /* seems weird, but this is the only way to make the halt work */
221 while(ins_pointer <= total_steps && halt == false) { step_next(); }
224 /* step forward one instruction */
225 function step_next()
227 //update_ins_pointer(1);
228 exe_nxt_inst();
229 dat_point_highlight();
232 /* more back one instruction - undoes work of previous instruction */
233 function step_back()
235 update_ins_pointer(-1);
236 dat_point_highlight();
239 /* update instruction pointer
240 direction:
242 1 increment pointer by one
243 0 set pointer to 0
244 -1 decrement pointer by one
246 function update_ins_pointer(direction)
248 if(direction < 0 && ins_pointer != 0 ) { ins_pointer--; }
249 else if (direction == 0 ) { ins_pointer = 0; }
250 else { ins_pointer++; }
251 disp_ins_pointer.value = ins_pointer;
252 ins_pointer_changed = 1;
253 ins_point_highlight();
256 /* update instruction pointer and set to new value */
257 function ins_point_modify_by_address(val)
259 /* instruction pointer can never be less than 0 */
260 if(val < 0) {
261 alert("Instruction Pointer cannot be set less than Zero.");
262 disp_ins_pointer.value = ins_pointer; /* reset val to previous */
263 return;
265 if(val > disp_code.value.length) {
266 alert("Instruction Pointer cannot be set beyond end of code.\n Current length of code: " + disp_code.value.length);
267 disp_ins_pointer.value = ins_pointer; /* reset val to previous */
268 return;
270 ins_pointer = disp_ins_pointer.value;
271 if(ins_pointer_last_address != ins_pointer) { ins_pointer_changed = 1; }
272 ins_point_highlight();
275 /* turns on and off data pointer highlight if it has changed this step */
276 function ins_point_highlight()
278 if(ins_pointer_changed) {
279 disp_ins_pointer.style.backgroundColor = "#ff0";
280 ins_pointer_changed = 0;
281 } else {
282 disp_ins_pointer.style.backgroundColor = "#fff";
286 /* setup virtual machine - must be called on page load */
287 function init_form()
289 disp_code = document.getElementById("code");
290 disp_ins_pointer = document.getElementById("ins_pointer_disp");
291 disp_dat_pointer = document.getElementById("dat_pointer_disp");
292 disp_ram = document.getElementById("ram_disp");
293 ram_reset();
294 ram_init();
295 document.getElementById("addr_0").innerHTML = "0" + disp_pointer;
296 disp_docs = document.getElementById("docs");
297 /* reset_output(); */
300 /* reset all RAM to 0 */
301 function ram_reset()
303 var i;
304 for(i=0; i < 64; i++) { ram[i] = 0; }
307 /* update highlight of one memory address and release other highlight if needed */
308 function ram_highlight(address)
310 var disp_last_address = document.getElementById("ram_"+ram_last_address);
311 /* highlight background of current address */
312 document.getElementById("ram_"+address).style.backgroundColor = "#ff0";
314 /* remove highlight from last address modified */
315 if(ram_last_address != address){
316 if(ram_last_address%2==0) {
317 disp_last_address.style.backgroundColor = "#fff";
318 } else {
319 disp_last_address.style.backgroundColor = "#def";
324 /* remove highlight from all memory cells regardless of current status */
325 function ram_highlight_clear()
327 var i;
328 for(i=0; i < 64; i++)
330 if(i%2==0) {
331 document.getElementById("ram_"+i).style.backgroundColor = "#fff";
332 } else {
333 document.getElementById("ram_"+i).style.backgroundColor = "#def";
335 document.getElementById("ram_"+i).innerHTML = ram[i];
339 /* define RAM on screen */
340 function ram_init()
342 var i;
343 var table = "<table id=memory_table>\n";
344 for(i=0; i < 16; i++){
345 if(i%2==0) {
346 table += "\t<tr class=even>";
347 } else {
348 table += "\t<tr class=odd>";
350 table += "<td width='35' class=addr id=addr_"+i+">"+i+"</td><td width='35' class=ram id=ram_"+i+">"+ram[i]+"</td>";
351 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";
352 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";
353 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";
355 table += "</table>\n";
356 disp_ram.innerHTML = table;
360 modify the value at this address - reset RAM highlights for all addresses
361 1 increment RAM by one
362 0 set RAM to 0
363 -1 decrement RAM by one
365 function ram_modify(address, change)
367 if(address < 0 || address > 63) {
368 alert("SEGFAULT: Cannot Modify Data Outside of Memory Range");
369 halt = true;
370 reset();
371 return;
374 if (change > 0 ) {
375 ram[address]++;
376 } else if(change < 0 ) {
377 ram[address]--;
378 } else {
379 ram[address] = 0;
381 ram_highlight(address);
382 document.getElementById("ram_"+address).innerHTML = ram[address];
383 ram_last_address = address;
386 /* modify one byte of memory - set to address */
387 function ram_set(address, val)
389 if(address < 0 || address > 63) {
390 alert("SEGFAULT: Cannot Modify Data Outside of Memory Range");
391 halt = true;
392 reset();
393 return;
396 ram[address] = val;
397 ram_highlight(address);
398 document.getElementById("ram_"+address).innerHTML = ram[address];
399 ram_last_address = address;
403 modify state of data pointer
404 1 increment data pointer by one
405 0 set data pointer to 0
406 -1 decrement data pointer by one
409 function dat_point_modify(change)
411 dat_pointer_last_address = dat_pointer;
412 if (change > 0 ) {
413 dat_pointer++;
414 } else if(change < 0 ) {
415 /* could put SEGFAULT here, but C does not have a check for this, so neither will I ;) */
416 dat_pointer--;
417 } else {
418 dat_pointer = 0;
421 /* place '>' char next to memory address in table */
422 if(dat_pointer >= 0 && dat_pointer < 64) {
423 document.getElementById("addr_"+dat_pointer).innerHTML = dat_pointer + disp_pointer;
426 /* remove '>' char next to memory address in table */
427 if(dat_pointer_last_address >= 0 && dat_pointer_last_address < 64) {
428 document.getElementById("addr_"+dat_pointer_last_address).innerHTML = dat_pointer_last_address;
431 disp_dat_pointer.value = dat_pointer;
432 dat_pointer_changed = 1;
435 function dat_point_modify_by_address(val)
437 dat_pointer_last_address = dat_pointer;
438 dat_pointer = disp_dat_pointer.value;
439 /* place '>' char next to memory address in table */
440 if(dat_pointer >= 0 && dat_pointer < 64) {
441 document.getElementById("addr_"+dat_pointer).innerHTML = dat_pointer + disp_pointer;
444 /* remove '>' char next to memory address in table */
445 if(dat_pointer_last_address >= 0 && dat_pointer_last_address < 64) {
446 document.getElementById("addr_"+dat_pointer_last_address).innerHTML = dat_pointer_last_address;
448 dat_pointer_changed = 1;
449 dat_point_highlight();
452 /* turns on and off data pointer highlight if it has changed this step */
453 function dat_point_highlight()
455 if(dat_pointer_changed) {
456 disp_dat_pointer.style.backgroundColor = "#ff0";
457 dat_pointer_changed = 0;
458 } else {
459 disp_dat_pointer.style.backgroundColor = "#fff";
462 /* as a convenience to the user, set to red if pointer is out of memory range */
463 if(dat_pointer < 0 || dat_pointer > 63) {
464 disp_dat_pointer.style.backgroundColor = "#f00";
468 /* remove highlight from data pointer */
469 function dat_point_highlight_clear()
471 disp_dat_pointer.style.backgroundColor = "#fff";
474 /* print ASCII representation of memory at data pointer */
475 function print_mem()
477 var x = String.fromCharCode(ram[dat_pointer]);
478 document.getElementById("output_disp").innerHTML += x;
481 /* documentation stored inside invisible div. This shows its contents. */
482 function display_docs()
484 disp_docs.style.visibility = "visible";
485 docs_select("docs_main");
488 /* hide documentation from user */
489 function hide_docs()
491 disp_docs.style.visibility = "hidden";
494 function docs_select(page)
496 if(page == "basic") {
497 document.getElementById("docs_content").innerHTML = document.getElementById("docs_basic").innerHTML;
498 } else if(page == "features") {
499 document.getElementById("docs_content").innerHTML = document.getElementById("docs_features").innerHTML;
500 } else if(page == "examples") {
501 document.getElementById("docs_content").innerHTML = document.getElementById("docs_examples").innerHTML;
502 } else if(page == "examples2") {
503 document.getElementById("docs_content").innerHTML = document.getElementById("docs_examples2").innerHTML;
504 } else if(page == "ascii") {
505 document.getElementById("docs_content").innerHTML = document.getElementById("docs_ascii").innerHTML;
506 } else {
507 document.getElementById("docs_content").innerHTML = document.getElementById("docs_main").innerHTML;
513 allows user to kick off example from the help menu.
514 closes documentation menu, overwrites code with example.
515 prints error message if something goes wrong.
518 function docs_try(ex)
520 var ans = confirm("This will delete code currently loaded in machine.");
521 if(!ans) { return; }
522 hide_docs(); /* close documentation window */
523 reset(); /* reset computer */
524 if(ex == null) { alert("Example not setup correctly."); return; }
525 disp_code.innerHTML = document.getElementById(ex).innerHTML; /* write data out to code textarea */
528 </script>
530 <style type="text/css">
532 body {
533 font-family: Tahoma, Arial, Helvetica, sans-serif;
536 #disp_pointer {
537 float:right;
538 color: #f00;
541 #code_buttons {
542 position: absolute;
543 top: 570px;
544 left: 10px;
547 #input_banner {
548 position: absolute;
549 top: 120px;
550 left: 10px;
553 #da_banner {
554 position: absolute;
555 top: 360px;
556 left: 625px;
559 #ref_banner {
560 position: absolute;
561 top: 410px;
562 left: 625px;
565 #ip_banner {
566 position: absolute;
567 top: 315px;
568 left: 625px;
571 #output_banner {
572 position: absolute;
573 top: 120px;
574 left: 625px;
577 #memory_banner {
578 position: absolute;
579 top: 120px;
580 left: 315px;
583 #input {
584 position: absolute;
585 top: 140px;
586 left: 10px;
589 #ram_disp {
590 position: absolute;
591 top: 140px;
592 left: 315px;
595 #memory_table {
596 border:1px solid #000;
597 border-collapse: collapse;
600 .even td {
601 padding: 4px;
602 border-bottom:1px solid #000;
605 .odd td {
606 padding: 4px;
607 background-color: #def;
608 border-bottom: 1px solid #000;
611 .addr {
612 color: #00f;
615 .ram {
616 border-right:1px solid #000;
619 #output {
620 position: absolute;
621 top: 140px;
622 left: 625px;
625 #docs {
626 border:1px solid #000;
627 background-color: #fff;
628 position: absolute;
629 top: 10px;
630 left: 10px;
631 width: 950px;
632 height:700px;
633 visibility: hidden;
636 #docs_top_banner {
637 color: #000;
638 background-color: #def;
639 border-bottom:1px solid #000;
640 position: absolute;
641 top: 0px;
642 left: 0px;
643 height: 25px;
644 padding-top: 5px;
645 padding-left: 5px;
646 width: 945px;
649 #docs_close_btn {
650 background: #fff;
651 border:1px solid #000;
652 position: absolute;
653 top: 0px;
654 right: 0px;
655 cursor: pointer;
656 padding: 6px;
659 #docs_mnu_btn {
660 border:2px solid #000;
661 color: #000;
662 position: absolute;
663 top: 0px;
664 left: 375px;
665 padding-top: 3px;
666 padding-left: 20px;
667 padding-right: 20px;
670 #docs_content {
671 position: absolute;
672 top: 35px;
673 padding: 10px;
676 #docs_link:hover {
677 background-color: #faa;
678 cursor: pointer;
682 .docs_code_ex {
683 background-color: #def;
684 border: 1px solid #ddd;
685 padding: 5px;
688 .docs_hidden {
689 visibility: hidden;
692 #instruction {
693 position: absolute;
694 top: 335px;
695 left: 625px;
698 #data {
699 position: absolute;
700 top: 385px;
701 left: 625px;
704 #ascii {
705 border-collapse: collapse;
706 border: 1px solid #ddd;
709 #reference {
710 border-collapse: collapse;
711 border: 1px solid #ddd;
712 position: absolute;
713 top: 430px;
714 left: 625px;
715 width: 280px;
718 .ref_even td {
719 border-bottom: 1px solid #ddd;
722 .ref_odd td {
723 border-bottom: 1px solid #ddd;
724 background-color: #def;
727 .ref_ins {
728 font-size: 18px;
729 font-weight:bold;
730 color: #00f;
733 </style>
734 <body onLoad="init_form();">
736 <center><h2>Turing Tarpit Simulator</h2></center>
738 <center>
739 <button onClick='reset();'><img src="http://opentextbook.info/icons/32x32/resultset_first.png" title="Restart" alt="Restart"></button>
740 &nbsp;&nbsp;
741 <button onClick='step_back();'><img src="http://opentextbook.info/icons/32x32/resultset_previous.png" title="Step Back" alt="Step Back"></button>
742 &nbsp;&nbsp;
743 <button onClick='step_next();'><img src="http://opentextbook.info/icons/32x32/resultset_next.png" title="Next Step" alt="Next Step"></button>
744 &nbsp;&nbsp;
745 <button onClick='run();'><img src="http://opentextbook.info/icons/32x32/resultset_last.png" title="Run" alt="Run"></button>
746 &nbsp;&nbsp;
747 <button onClick='halt();'><img src="http://opentextbook.info/icons/32x32/cancel.png" title="Halt Execution" alt="Halt Execution"></button>
748 &nbsp;&nbsp;
749 <button disabled><img src="http://opentextbook.info/icons/32x32/disk.png" title="Save Code" alt="Save Code"></button>
750 &nbsp;&nbsp;
751 <button onClick='display_docs();'><img src="http://opentextbook.info/icons/32x32/book_open.png" title="Open Documentation" alt="Open Documentation"></button>
752 </center>
754 <div id="code_buttons">
755 <button id="dbg_status" onClick='debug_toggle_breakpoints();' title="Enable/Disable Breakpoints" alt="Enable/Disable Breakpoints">
756 <img src="http://opentextbook.info/icons/32x32/bug_add.png">
757 </button>
758 &nbsp;&nbsp;
759 <button id="dbg_status" onClick='debug_remove_breakpoints();' title="Remove Breakpoints" alt="Remove Breakpoints">
760 <img src="http://opentextbook.info/icons/32x32/bin.png">
761 </button>
762 </div>
764 <div id="input_banner">INPUT</div>
765 <div id="input"><textarea id="code" rows="27" cols="38"></textarea></div>
767 <div id="ip_banner">INSTRUCTION POINTER</div>
768 <div id="instruction"><input onClick="select_all('ins_pointer_disp');" onBlur="ins_point_modify_by_address(disp_ins_pointer.value);" id="ins_pointer_disp" type="text" diabled value=0></div>
770 <div id="da_banner">DATA POINTER</div>
771 <div id="data"><input onClick="select_all('dat_pointer_disp');" onBlur="dat_point_modify_by_address(disp_dat_pointer.value);" id="dat_pointer_disp" type="text" diabled value=0></div>
773 <div id="ref_banner">INSTRUCTION REFERENCE</div>
774 <table id="reference">
775 <tr class="ref_even"><td class="ref_ins">+</td><td>increment byte at data pointer</td></tr>
776 <tr class="ref_odd" ><td class="ref_ins">-</td><td>decrement byte at data pointer</td></tr>
777 <tr class="ref_even"><td class="ref_ins">></td><td>increment data pointer</td></tr>
778 <tr class="ref_odd" ><td class="ref_ins"><</td><td>decrement data pointer</td></tr>
779 <tr class="ref_even"><td class="ref_ins">.</td><td>print byte at data pointer</td></tr>
780 <tr class="ref_odd" ><td class="ref_ins">,</td><td>accept one byte of input</td></tr>
781 <tr class="ref_even"><td class="ref_ins">*</td><td>set breakpoint</td></tr>
782 </table>
784 <div id="memory_banner">MEMORY</div>
785 <div id="ram_disp"></div>
786 <div id="output_banner">OUTPUT</div>
787 <div id="output">
788 <textarea name=code id=output_disp rows="10" cols="38" disabled ></textarea>
789 </div>
790 <div id="docs">
791 <div id="docs_top_banner">
792 Turing Tarpit Simulator Documentation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
793 <button id="docs_mnu_btn" onClick="docs_select('main');"><img src="http://opentextbook.info/icons/16x16/house.png">Main Menu</button>
794 <div id="docs_close_btn" onClick="hide_docs();"><img src="http://opentextbook.info/icons/16x16/cross.png"></div></div>
796 <div id="docs_content"></div>
797 </div>
799 <div id="docs_main" class="docs_hidden">
800 <div id="docs_link" onClick="docs_select('basic');">Basic Operation</div>
801 <div id="docs_link" onClick="docs_select('features');">Features and Hints</div>
802 <div id="docs_link" onClick="docs_select('examples');">Example Code 1</div>
803 <div id="docs_link" onClick="docs_select('examples2');">Example Code 2</div>
804 <div id="docs_link" onClick="docs_select('ascii');">ASCII Chart</div>
805 </div>
807 <div id="docs_basic" class="docs_hidden">
809 <b>Basic Operation</b>
811 <p>This Turing Tarpit is an abstract machine or a theoretical model of computer hardware. The machine has 64 bytes of memory (RAM) and an almost unlimited amount of program storage (ROM). The instruction set is very simple. A user can program the tool by performing one of seven operations:
813 <p>The <b>'>'</b> and <b>'<'</b> symbols modify the Data Pointer to point to a new location in the Memory. It is possible to set the Data Pointer to a byte outside the machine's Memory. This does not cause an error. If you attempt to modify the memory at this location, the computer will crash and reboot with a SEGFAULT error.
815 <p>The <b>'+'</b> and <b>'-'</b> symbols allow the user to increment and decrement the Memory at the Data Pointer. Only one byte of Memory can be modified at any time. The byte of memory has a minimum and maximum value. When you exceed this value, the byte wraps around to zero.
817 <p>Another instruction <b>'.'</b> prints the contents of the byte at the Data Pointer. These numerical values listed in the Memory are converted into ASCII and printed as characters in the OUTPUT. A small chart of common ASCII values can be found in this documentation.
819 <p>The computer can interactively request data from the user with the <b>','</b> instruction. This opens up a dialog to request one byte of data from the user.
821 <p>An additional instruction <b>'*'</b> halts the execution of the program to allow the user to examine the machine at that point. This is known as a BREAKPOINT. These breakpoints can be toggled on and off as well as automatically deleted from the code with the user interface below the INPUT.
823 <p>You can execute the program one step at a time or run the program at full speed until it needs user input or halts. Both methods are useful during development.
825 <p>More documentation is included in this manual. One section is dedicated to Features and Hints that will aid you in getting the most of this tool. Another section is devoted to working code examples that provide a tutorial on how to best make use of the language.
827 </div>
829 <div id="docs_features" class="docs_hidden">
831 <b>Features and Hints</b>
833 <p>All characters outside the Instruction Set are considered comments and will be skipped over during runtime.
835 <p>While program executes, the Input cursor is moved over the current instruction.
837 <p>User can change the address of the Data Pointer and Instruction Pointer at any time.
838 Memory and pointers that have been modified are highlighted in yellow until the next step.
840 <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.
842 <p>The Instruction Pointer can point to a location range of 1 to the number of characters in the input.
844 <p>Restarting the machine will reset all Memory, Data and Instruction Pointers to zero.
846 <p>The output of the program cannot be edited.
848 <p>A user can add a break instruction in the code using an asterisk <b>'*'</b>. 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.
850 <p>In this version the programs you type in are not saved to your computer. This must be done as a manual operation.
852 <p>As this program is reliant on the speed and efficiency of your browser's JavaScript implementation some computers will be able to execute programs faster than others.
854 <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).
856 <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.
858 <p>No server interaction or outside service is needed for this program to operate.
859 </div>
865 <div id="docs_examples" class="docs_hidden">
866 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.
868 <p><button id="docs_try" onClick="docs_try('docs_example_clear_btye');"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Clear Byte:</b>
869 Sets value at current Data Pointer to Zero.
870 <div class=docs_code_ex>
872 </div>
873 <p><button id="docs_try" onClick="docs_try('bad example');"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Clear Previous Cells:</b>
874 Sets value of all previous bytes including current byte to Zero.
875 <div class=docs_code_ex>
876 [[-]<]
877 </div>
878 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Rewind:</b>
879 Goes back to byte Zero.
880 <div class=docs_code_ex>
881 [<]>
882 </div>
883 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Fast-forward:</b>
884 Increments the data pointer until a 0 is found then decrements if until the current cell is non-zero.
885 <div class=docs_code_ex>
886 [>]<
887 </div>
888 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Simple Loop:</b>
889 Accepts input from the user and echos it to the screen, similar to the UNIX cat program.
890 <div class=docs_code_ex>
891 ,[.,]
892 </div>
893 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Moving the Data Pointer:</b>
894 Accepts input from the user and saves all input in the memory for future use.
895 <div class=docs_code_ex>
896 >,[.>,]
897 </div>
898 </div>
904 <div id="docs_examples2" class="docs_hidden">
905 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Add Two Bytes:</b>
906 Adds current location to the next location and leaves behind a Zero for the first value.
907 <div class=docs_code_ex>
908 [->+<]
909 </div>
910 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Lower To Upper:</b>
911 Accepts lower case input from the user and makes it uppercase. Stops when user presses the enter key.
912 <div class=docs_code_ex>
913 ,----------[----------------------.,----------]
914 </div>
915 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Copy Value:</b>
916 Copy value of byte Zero to byte One.
917 <div class=docs_code_ex>
918 >[-]>[-]<<[->+>+<<]>>[-<<+>>]<<
919 </div>
920 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Seek:</b>
921 Move Data Pointer forward until it lands on a byte with a value of 1, preserving all bytes it passes.
922 <div class=docs_code_ex>
923 -[+>-]+
924 </div>
925 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Single Digit Add:</b>
926 Adds two single digit numbers and display result. Works on one-digit results only.
927 <div class=docs_code_ex>
928 ,>++++++[<-------->-],[<+>-]<.
929 </div>
930 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Single Digit Multiplication:</b>
931 Multiply two single digit numbers and display result. Works on one-digit results only.
932 <div class=docs_code_ex>
933 ,>,>++++++++[<------<------>>-]
934 <<[>[>+>+<<-]>>[<<+>>-]<<<-]
935 >>>++++++[<++++++++>-]<.>.
936 </div>
937 <p><button id="docs_try" onClick="docs_try();"><img src="http://opentextbook.info/icons/16x16/bricks.png">Try</button><b>Single Digit Division:</b>
938 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.
939 <div class=docs_code_ex>
940 ,>,>++++++[-<--------<-------->>]<<[>[->+>+<<]>[-<<-[>]>>>[<[>>>-<<<[-]]>>]<<]>>>+<<[-<<+>>]<<<]>[-]>>>>[-<<<<<+>>>>>]<<<<++++++[-<++++++++>]<.
941 </div>
942 </div>
948 <div id="docs_example_clear_btye" class="docs_hidden">
950 This is an example of clearing a byte
952 update first byte to higher number
953 ++++++
955 set this byte to zero regardless of current value
958 </div>
960 <div id="docs_ascii" class="docs_hidden">
962 <table id="ascii" width="900px">
963 <caption><b>ASCII Chart</b></caption>
964 <tr><th class="val_col"></th><th class="dat_col"></th><th class="val_col"></th><th class="dat_col"></th><th class="val_col"></th><th class="dat_col"></th><th class="val_col"></th><th class="dat_col"></th><th class="val_col"></th><th class="dat_col"></th><th class="val_col"></th><th class="dat_col"></th><th class="val_col"></th><th class="dat_col"></th><th class="val_col"></th><th class="dat_col"></th></tr>
966 <tr class="ref_even"><td>0</td><td class="ctrl">NUL</td><td>16</td><td class="ctrl">DLE</td><td>32</td><td class="ctrl">SP</td><td>48</td><td>0</td><td>64</td><td>@</td><td>80</td><td>P</td><td>96</td><td>`</td><td>112</td><td>p</td></tr>
968 <tr class="ref_odd"><td>1</td><td class="ctrl">SOH</td><td>17</td><td class="ctrl">DC1</td><td>33</td><td>!</td><td>49</td><td>1</td><td>65</td><td>A</td><td>81</td><td>Q</td><td>97</td><td>a</td><td>113</td><td>q</td></tr>
970 <tr class="ref_even"><td>2</td><td class="ctrl">STX</td><td>18</td><td class="ctrl">DC2</td><td>34</td><td>"</td><td>50</td><td>2</td><td>66</td><td>B</td><td>82</td><td>R</td><td>98</td><td>b</td><td>114</td><td>r</td></tr>
972 <tr class="ref_odd"><td>3</td><td class="ctrl">ETX</td><td>19</td><td class="ctrl">DC3</td><td>35</td><td>#</td><td>51</td><td>3</td><td>67</td><td>C</td><td>83</td><td>S</td><td>99</td><td>c</td><td>115</td><td>s</td></tr>
974 <tr class="ref_even"><td>4</td><td class="ctrl">EOT</td><td>20</td><td class="ctrl">DC4</td><td>36</td><td>$</td><td>52</td><td>4</td><td>68</td><td>D</td><td>84</td><td>T</td><td>100</td><td>d</td><td>116</td><td>t</td></tr>
976 <tr class="ref_odd"><td>5</td><td class="ctrl">ENQ</td><td>21</td><td class="ctrl">NAK</td><td>37</td><td>%</td><td>53</td><td>5</td><td>69</td><td>E</td><td>85</td><td>U</td><td>101</td><td>e</td><td>117</td><td>u</td></tr>
978 <tr class="ref_even"><td>6</td><td class="ctrl">ACK</td><td>22</td><td class="ctrl">SYN</td><td>38</td><td>&amp;</td><td>54</td><td>6</td><td>70</td><td>F</td><td>86</td><td>V</td><td>102</td><td>f</td><td>118</td><td>v</td></tr>
979 <tr class="ref_odd"><td>7</td><td class="ctrl">BEL</td><td>23</td><td class="ctrl">ETB</td><td>39</td><td>'</td><td>55</td><td>7</td><td>71</td><td>G</td><td>87</td><td>W</td><td>103</td><td>g</td><td>119</td><td>w</td></tr>
981 <tr class="ref_even"><td>8</td><td class="ctrl">BS</td><td>24</td><td class="ctrl">CAN</td><td>40</td><td>(</td><td>56</td><td>8</td><td>72</td><td>H</td><td>88</td><td>X</td><td>104</td><td>h</td><td>120</td><td>x</td></tr>
983 <tr class="ref_odd"><td>9</td><td class="ctrl">HT</td><td>25</td><td class="ctrl">EM</td><td>41</td><td>)</td><td>57</td><td>9</td><td>73</td><td>I</td><td>89</td><td>Y</td><td>105</td><td>i</td><td>121</td><td>y</td></tr>
985 <tr class="ref_even"><td>10</td><td class="ctrl">LF</td><td>26</td><td class="ctrl">SUB</td><td>42</td><td>*</td><td>58</td><td>:</td><td>74</td><td>J</td><td>90</td><td>Z</td><td>106</td><td>j</td><td>122</td><td>z</td></tr>
987 <tr class="ref_odd"><td>11</td><td class="ctrl">VT</td><td>27</td><td class="ctrl">ESC</td><td>43</td><td>+</td><td>59</td><td>;</td><td>75</td><td>K</td><td>91</td><td>[</td><td>107</td><td>k</td><td>123</td><td>{</td></tr>
989 <tr class="ref_even"><td>12</td><td class="ctrl">FF</td><td>28</td><td class="ctrl">FS</td><td>44</td><td>,</td><td>60</td><td>&lt;</td><td>76</td><td>L</td><td>92</td><td>\</td><td>108</td><td>l</td><td>124</td><td>|</td></tr>
990 <tr class="ref_odd"><td>13</td><td class="ctrl">CR</td><td>29</td><td class="ctrl">GS</td><td>45</td><td>-</td><td>61</td><td>=</td><td>77</td><td>M</td><td>93</td><td>]</td><td>109</td><td>m</td><td>125</td><td>}</td></tr>
992 <tr class="ref_even"><td>14</td><td class="ctrl">SO</td><td>30</td><td class="ctrl">RS</td><td>46</td><td>.</td><td>62</td><td>></td><td>78</td><td>N</td><td>94</td><td>^</td><td>110</td><td>n</td><td>126</td><td>~</td></tr>
994 <tr class="ref_odd"><td>15</td><td class="ctrl">SI</td><td>31</td><td class="ctrl">US</td><td>47</td><td>/</td><td>63</td><td>?</td><td>79</td><td>O</td><td>95</td><td>_</td><td>111</td><td>o</td><td>127</td><td class="ctrl">DEL</td></tr>
996 </table>
997 </div>
999 </body>
1000 </html>