Examine individual changes

Abuse Filter navigation (Home | Recent filter changes | Examine past edits | Abuse log)
Jump to navigation Jump to search

This page allows you to examine the variables generated by the Abuse Filter for an individual change.

Variables generated for this change

VariableValue
Edit count of the user (user_editcount)
9
Name of the user account (user_name)
'Glax'
Age of the user account (user_age)
57379965
Groups (including implicit) the user is in (user_groups)
[ 0 => '*', 1 => 'user', 2 => 'autoconfirmed' ]
Page ID (page_id)
0
Page namespace (page_namespace)
0
Page title (without namespace) (page_title)
'AlphaStack'
Full page title (page_prefixedtitle)
'AlphaStack'
Action (action)
'edit'
Edit summary/reason (summary)
'Create AlphaStack'
Old content model (old_content_model)
''
New content model (new_content_model)
'wikitext'
Old page wikitext, before the edit (old_wikitext)
''
New page wikitext, after the edit (new_wikitext)
'{{infobox proglang |name=AlphaStack |paradigms=imperative |author=[[User:Glax]] |year=[[:Category:2026|2026]] |memsys=[[:Category:Stack-based|Stack-based]] |dimensions=one-dimensional |class=[[:Category:Turing complete|Turing complete]] |refimpl=[https://gitlab.com/mattia.basaglia/dragon.best/-/blob/master/media/scripts/alphastack/alphastack.py alphastack.py] }} [[Category:Languages]] [[Category:2026]] [[Category:Stack-based]] [[Category:Turing complete]] [[Category:Deterministic]] [[Category:Implemented]] <h2>Introduction</h2> <p><em>AlphaStack</em> is an stack-based language that uses only letters of the alphabet as values and instructions.</p> <p>Being stack based, the instructions typically pop their arguments from the stacks and push their results onto the stack.</p> <p>You can try this language at its official [https://dragon.best/alphastack/#playground web playground].</p> <h3>Examples</h3> <h4>Hello World</h4> <pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre> <h4>99 Bottles of beer</h4> <pre>vdyppsjepkkjesjeejesjdejidsjfexexjacjdjcsjfadaajasjbaabjpsppppppspsppspsppppspsp pppspspppspsppppspsjepkaptakecpwaponecpwapdowncpwappasscpwapitcpwaparoundepkjesj dejesjeejesjdejyyhesppppspsppspspppppppspsppppspsppsesjceapnocpwapmorecpwapbottx escpwapofcpwapbeerzeejyypsppppspspppspsppspsesjcecpwaponcpwapthecpwapwaxxepkzjyy ppppspsppspspppppppspsesjcecpwapbottxescpwapofcpwapbeerzjesjbejyysoassjanaakbxzb njyyppsjcpjppeesjaejsjzpjcjbjcjbjyyasjdaakjwjbdjpsjzpjasjeaakjcjbjcjbjynbqjkblao sdddddddlalr</pre> <h3 id="stack">Stacks and Procedures</h3> <p><em>AlphaStack</em> has two stacks:</p> <p>The value stack is where most operations happens, with individual letters being pushed and popped into it.</p> <p>The procedure stack contains procedures, the only instruction that can add to this stack is [[#d_-_Define|d]] and some other instructions can access the data stored there.</p> <p>A procedure is a sequence of letters that can be executed at a later time. Procedures only ever exist on the procedure stack.</p> <p>This manual will often show a summary of an operation as follows:</p> <table class="wikitable"> <tr><td><span class="operand">op1</span><span class="operand">op2</span></td> <td><code class="instruction">a</code></td> <td><span class="operand">result</span></td></tr> </table> <p>This shows the instruction <code class="instruction">a</code> and its effect on the stack. Values before it in the summary represent the top of the stack before the execution of that instruction. Values after it represent what the head of the stack has been replaced with. In this example, <code class="operand">op1</code> and <code class="operand">op2</code> will be popped off the stack and <code class="operand">result</code> will be popped onto the stack. </p> <h3 id="literal-mode">Literal Mode</h3> <p><em>AlphaStack</em> has two modes: literal mode and instruction mode.</p> <p>In literal mode all valid characters are pushed directly onto the stack until the mode is switched.</p> <p>In instruction mode, all charcters are interpreted as instructions and executed immediately.</p> <p>The instruction [[#l_-_Literal|l]] is used to switch between these two modes, and it's the only instruction to have an effect in literal mode.</p> <p>Program execution always starts in literal mode so you can add data before adding code.</p> <h3>Comments</h3> <p><em>AlphaStack</em> doesn't directly support comments but there are a few techniques to simulate them.</p> <p>All examples in this section are a print the characters <code>a</code> and <code>b</code> using <code>alp</code> and <code>lblp</code> respectively. <p>First of all, all characters that are not lower case ASCII characters are ignored, so you can always add spaces, upper case letter, and special character.</p> <pre>alp SPACES AND UPPER CASE LETTERS ARE IGNORED! lblp</pre> <p>Since yelling in every comment is considered ruse there's an alternative: using the [[#l_-_Literal|l]] instruction you can start pushing values onto the stack, then clear it with [[#u_-_Undo|u]]. Note that [[#u_-_Undo|u]] needs a marker (which can be any letter) to stop clearing the stack so you can't use that character in the comment.</p> <pre>alp lx this is pushed then popped from the stack, so it has no effect on the program xlu lblp</pre> <p>One side effect of this is that you can't use the marker letter (<code>x</code> in this example) nor single <code>l</code>s in this style of comment as those they will switch back to instruction mode. Pairs of <code>l</code>s will work as switching modes twice has no effect.</p> <pre>alp lx Hello comment! xlu lblp</pre> <h3>Numbers</h3> <p>In <em>AlphaStack</em> there are only letters, no numbers. However can consider interpret the letters as numbers based on their position in the alphabet. With this in mind, <code>a</code> can be thought as 0, <code>b</code> as 1 and so on.</p> <p>Similarly, the value <code>a</code> is considered false, while all other values are considered true.</p> <h3>Registers</h3> <p>Each letter has a register associated with it. These registered can be freely written to or read from (using [[#s_-_Set|s]] and [[#g_-_Get|g]]). Some instructions modify their behaviour based on the value of the corresponding register.</p> <p>At the start of a program all registers have a value of <code>a</code> (0).</p> <h2>Tutorial</h2> <p>This section will walk through the basics of <em>AlphaStack</em> with some practical examples. The tutorials assume you've been through the [[#Introduction|introduction]] fist.</p> <h3>Hello World</h3> <p>This tutorial shows the basics of printing text to standard output</p> <pre>abcd</pre> <p>Since a program starts in [[#Literal_Mode|literal mode]], this code pushes <code>abcd</code> onto the [[#Stacks_and_Procedures|value stack]]. <code>d</code> being at the top of the stack and <code>a</code> at the bottom.</p> <pre>abcd l</pre> <p>Any characters that are not letters are ignored, so the space does nothing. [[#l_-_Literal|l]] exits literal mode and enters instruction mode. This means after it letters will be executed as instructions rather than pushed onto the stack.</p> <pre>abcd l pppp</pre> <p>Here [[#p_-_Print|p]] is executed 4 times, printing 4 letters off the top of the stack. This clears the stack as each letter is popped before printing and outputs <code>dbca</code>. <br/> The order of the letters is reversed because they are printed from the top of the stack.</p> <p>Now, if we want to print <code>abcd</code> as numbers instead, we need to set the [[#p_-_Print_Mode_Register|p register]] to <code>c</code> first, this is done with the [[#s_-_Set|s]] command which pops a reister and its value off the stack:</p> <pre>abcd pc l s pppp</pre> <p>Here <code>pc</code> on the stack is consumed by [[#s_-_Set|s]] to do just that and the code outputs <code>3210</code>.</p> <p>Again, spaces are not meaningful in <em>AlphaStack</em> in the example they are used to highlight which literals are used by which instuction.</p> <p>If you want to enter values in literal mode and then print them in the same order as they were pushed onto the stack, you need to flip them around first:</p> <pre>abcd e l f pppp</pre> <p>Now [[#f_-_Flip|f]] pops <code>e</code> off the stack, this corresponds with the number 4, and flips that many items on the stack. In this case the stack ends up as <code>dbca</code>, printing <code>abcd</code>.</p> <p>Let's say we want to print the word "hello". There's an issue here, [[#l_-_Literal|l]] switches between literal mode and instruction mode so it can't be directly entered as a literal. To work around this we can push a value <code>l</code> onto the stack by performing a simple mathematical operation: </p> <pre>kb l a p</pre> <p>[[#a_-_Arithmetic_Operation|a]] pops two values off the stack and adds them together, in this case adds <code>b</code> (1) to <code>k</code>, obtaining <code>l</code>. Then [[#p_-_Print|p]] prints it.</p> <p>Now we can print hello like so:</p> <pre>o kb kb e h l p p ap ap p</pre> <p>The first two [[#p_-_Print|p]] print <code>h</code> and <code>e</code> respectively. Then [[#a_-_Arithmetic_Operation|a]] followed by [[#p_-_Print|p]] print an <code>l</code>, this is done twice. The final [[#p_-_Print|p]] prints the <code>o</code>.</p> <p>Replacing each <code>l</code> individually can become tedious so we can push a single one onto the stack and then replace a different character with it.</p> <code>oxxeh yxkb l a o ppppp</code> <p>Here [[#a_-_Arithmetic_Operation|a]] turns <code>kb</code> into <code>l</code> like before. [[#o_-_Overwrite|o]] then pops the 3 topmost items on the stack: <code>yxl</code>. It then performs a replacement of the values on the stack with as follows: all occurrences of <code>x</code> are replaced by <code>l</code> until the next <code>y</code> is reached. In this case there are no <code>y</code> values on the stack after the initial one so the entire stack is processed. Finally the five [[#p_-_Print|p]] print <code>hello</code>.</p> <p>We can combine all of this with different print modes to print <code>Hello World!</code>:</p> <pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre> <h3>Procedures and Loops</h3> <p>Let's say you don't want to type a [[#p_-_Print|p]] for every single letters you want to output. We can create a procedure that prints the stack until a condition is met.</p> <p>First we need to get a condition that checks the top of the stack for a given value and halts execution when found. Conditionals are handled by [[#i_-_If|i]], which needs a procedure to run when the condition is met. We start by defining the halting procedure:/p> <pre>xhx l d</pre> <p>[[#d_-_Define|d]] here uses <code>x</code> as a delimiter and pushes a procedure containing <code>h</code> on top of the procedure stack.</p> <p>Now we are ready to define the main procedure. Since we need literals in the main procedure we need to perform the usual trick to replace <code>j</code> with <code>l</code>:</p> <pre>xpikacjbzjx jbk ob xhx l d sao d</pre> <p>This code starts as before with [[#d_-_Define|d]] popping <code>xhx</code> from the value stack and pushing <code>h</code> onto the procedure stack. Then <code>sao</code> performs the <code>j</code> to <code>l</code> replacement: [[#s_-_Set|s]] pops <code>ob</code> to set the [[#o_-_Keep_Mark_Register|o register]] to keep the delimiter. [[#a_-_Arithmetic_Operation|a]] the pops <code>bk</code> to push a <code>l</code>. [[#o_-_Overwrite|o]] pops <code>jl</code> to replace all occurrences of <code>j</code> with <code>l</code> using <code>x</code> as a delimiter. Since we set the [[#o_-_Keep_Mark_Register|o register]] register to the value <code>b</code> using [[#s_-_Set|s]], the <code>x</code> delimiters are not removed from the stack. This allows [[#d_-_Define|d]] to use the same deimiter.</p> <p>Finally, [[#d_-_Define|d]] pops <code>xpikaclbzlx</code> from the value stack and pushes <code>lzblcakip</code> onto the procedure stack. Note that [[#d_-_Define|d]] removes the delimiters from the procedure and reverses the order of its letters so when you define procedures in literal mode, you need to flip them around.</p> <p>Now let's see that the code in the procedure does:</p> <pre>lzbl ca kip</pre> <p>[[#l_-_Literal|l]] toggles between modes so <code>lzbl</code> results in a literal pushing <code>z</code> and <code>b</code> onto the stack. [[#c_-_Copy|c]] then pops <code>b</code> from the stack, this is a value of 1 which means [[#c_-_Copy|c]] copies the next item on the stack, skipping the <code>z</code>. After [[#c_-_Copy|c]] the stack top of the contains a copy of the initial top of the stack followed by <code>z</code>. </p> <p>[[#a_-_Arithmetic_Operation|a]] then performs an operation on these two. The operation performed by [[#a_-_Arithmetic_Operation|a]] is determined by the value of the [[#a_-_Operation_Register|a register]]. The default operation is addition but it will need to be set to equality comparison before the procedure is executed. If the [[#a_-_Operation_Register|a register]] is set to comparison, [[#a_-_Arithmetic_Operation|a]] will pop the two letters off the top of the stack and push true (<code>b</code>) or false (<code>a</code>) depending whether they are the same.</p> <p>Follows [[#k_-_Keep|k]] which copies the top procedure from the procedure stack, this is requires to prevent [[#i_-_If|i]] from consuming it since we are looping. [[#i_-_If|i]] consumes the copied procedure and the result of the comparison, executing the procedure if the result is true (<code>b</code>). When the procedure is executed, the program halts (this procedure is <code>h</code>, which was defined at the start. Finally [[#p_-_Print|p]] pops and prints the top of the stack. This only happens if the condition was false as it means the program was not halted. </p> <p>Final bit of setup:</p> <pre>a af xpikacjbzjx jbk ob xhx l d sao d s r</pre> <p>Here is the same but there is more data onto the stack and two more instructions. The second [[#s_-_Set|s]] pops <code>af</code> to set the [[#a_-_Arithmetic_Operation|a]] to equality comparison mode. Then [[#r_-_Repeat|r]] will pop the remaining <code>a</code> which means it will loop forever (or in this case until halted.</p> <p>Now all that's needed is some data on the stack to be printed, using <code>z</code> as a delimiter (since it's the value we're comparing against on the procedure).</p> <pre>z kcatsehtgnitnirp a af xpikacjbzjx jbk ob xhx l d sao d s r</pre> Output: <pre>printingthestack</pre> <h2>Alphabet</h2> <p><em>AlphaStack</em> uses the 26 (lower case) letters of the Latin alphabet. All other characters are ignores, including upper case letters.</p> <table class="wikitable"> <tr><th>Letter</th><th>Numerical</th><th>Instruction</th><th>Register</th><th colspan='3'>Summary</th></tr> <tr><th>a</th><td class='letterval'>0</td> <td>[[#a_-_Arithmetic_Operation|Arithmetic Operation]]</td> <td>[[#a_-_Operation_Register|Operation]]</td> <td class='summary-col'><span class='operand'>num1</span><span class='operand'>num2</span></td> <td class='summary-col'><code class='instruction'>a</code></td> <td class='summary-col'><span class='operand'>num3</span></td></tr> <tr><th>b</th><td class='letterval'>1</td> <td>[[#b_-_Break|Break]]</td> <td></td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>b</code></td> <td class='summary-col'></td></tr> <tr><th>c</th><td class='letterval'>2</td> <td>[[#c_-_Copy|Copy]]</td> <td></td> <td class='summary-col'><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>index</span></td> <td class='summary-col'><code class='instruction'>c</code></td> <td class='summary-col'><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>val</span></td></tr> <tr><th>d</th><td class='letterval'>3</td> <td>[[#d_-_Define|Define]]</td> <td></td> <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td> <td class='summary-col'><code class='instruction'>d</code></td> <td class='summary-col'></td></tr> <tr><th>e</th><td class='letterval'>4</td> <td>[[#e_-_Execute_Specific|Execute Specific]]</td> <td>[[#e_-_Execute_Index_Register|Execute Index]]</td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>e</code></td> <td class='summary-col'></td></tr> <tr><th>f</th><td class='letterval'>5</td> <td>[[#f_-_Flip|Flip]]</td> <td></td> <td class='summary-col'><span class='operand'>...</span><span class='operand'>count</span></td> <td class='summary-col'><code class='instruction'>f</code></td> <td class='summary-col'><span class='operand'>...</span></td></tr> <tr><th>g</th><td class='letterval'>6</td> <td>[[#g_-_Get|Get]]</td> <td></td> <td class='summary-col'><span class='operand'>reg</span></td> <td class='summary-col'><code class='instruction'>g</code></td> <td class='summary-col'><span class='operand'>val</span></td></tr> <tr><th>h</th><td class='letterval'>7</td> <td>[[#h_-_Halt|Halt]]</td> <td></td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>h</code></td> <td class='summary-col'></td></tr> <tr><th>i</th><td class='letterval'>8</td> <td>[[#i_-_If|If]]</td> <td>[[#i_-_If_Else_Count_Register|If Else Count]]</td> <td class='summary-col'><span class='operand'>valn</span><span class='operand'>...</span><span class='operand'>val0</span></td> <td class='summary-col'><code class='instruction'>i</code></td> <td class='summary-col'></td></tr> <tr><th>j</th><td class='letterval'>9</td> <td></td> <td></td> <td class='summary-col'></td> <td class='summary-col'></td> <td class='summary-col'></td></tr> <tr><th>k</th><td class='letterval'>10</td> <td>[[#k_-_Keep|Keep]]</td> <td>[[#k_-_Keep_Count_Register|Keep Count]]</td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>k</code></td> <td class='summary-col'></td></tr> <tr><th>l</th><td class='letterval'>11</td> <td>[[#l_-_Literal|Literal]]</td> <td>[[#l_-_Mode_Register|Mode]]</td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>l</code></td> <td class='summary-col'></td></tr> <tr><th>m</th><td class='letterval'>12</td> <td>[[#m_-_Memory|Memory]]</td> <td>[[#m_-_Memory_Cell_Register|Memory Cell]]</td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>m</code></td> <td class='summary-col'><span class='operand'>val</span></td></tr> <tr><th>n</th><td class='letterval'>13</td> <td>[[#n_-_Number_of_Items|Number of Items]]</td> <td>[[#n_-_Number_Size_Register|Number Size]]</td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>n</code></td> <td class='summary-col'><span class='operand'>count</span></td></tr> <tr><th>o</th><td class='letterval'>14</td> <td>[[#o_-_Overwrite|Overwrite]]</td> <td>[[#o_-_Keep_Mark_Register|Keep Mark]]</td> <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span><span class='operand'>search</span><span class='operand'>replace</span></td> <td class='summary-col'><code class='instruction'>o</code></td> <td class='summary-col'><span class='operand'>...</span></td></tr> <tr><th>p</th><td class='letterval'>15</td> <td>[[#p_-_Print|Print]]</td> <td>[[#p_-_Print_Mode_Register|Print Mode]]</td> <td class='summary-col'><span class='operand'>val</span></td> <td class='summary-col'><code class='instruction'>p</code></td> <td class='summary-col'></td></tr> <tr><th>q</th><td class='letterval'>16</td> <td></td> <td></td> <td class='summary-col'></td> <td class='summary-col'></td> <td class='summary-col'></td></tr> <tr><th>r</th><td class='letterval'>17</td> <td>[[#r_-_Repeat|Repeat]]</td> <td></td> <td class='summary-col'><span class='operand'>count</span></td> <td class='summary-col'><code class='instruction'>r</code></td> <td class='summary-col'></td></tr> <tr><th>s</th><td class='letterval'>18</td> <td>[[#s_-_Set|Set]]</td> <td></td> <td class='summary-col'><span class='operand'>reg</span><span class='operand'>val</span></td> <td class='summary-col'><code class='instruction'>s</code></td> <td class='summary-col'></td></tr> <tr><th>t</th><td class='letterval'>19</td> <td>[[#t_-_Text_Input|Text Input]]</td> <td>[[#t_-_Read_Result_Register|Read Result]]</td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>t</code></td> <td class='summary-col'><span class='operand'>val?</span></td></tr> <tr><th>u</th><td class='letterval'>20</td> <td>[[#u_-_Undo|Undo]]</td> <td></td> <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td> <td class='summary-col'><code class='instruction'>u</code></td> <td class='summary-col'></td></tr> <tr><th>v</th><td class='letterval'>21</td> <td></td> <td></td> <td class='summary-col'></td> <td class='summary-col'></td> <td class='summary-col'></td></tr> <tr><th>w</th><td class='letterval'>22</td> <td>[[#w_-_Wrap|Wrap]]</td> <td></td> <td class='summary-col'><span class='operand'>...</span><span class='operand'>count</span><span class='operand'>steps</span></td> <td class='summary-col'><code class='instruction'>w</code></td> <td class='summary-col'><span class='operand'>...</span></td></tr> <tr><th>x</th><td class='letterval'>23</td> <td>[[#x_-_Execute|Execute]]</td> <td></td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>x</code></td> <td class='summary-col'></td></tr> <tr><th>y</th><td class='letterval'>24</td> <td>[[#y_-_Yield|Yield]]</td> <td></td> <td class='summary-col'></td> <td class='summary-col'><code class='instruction'>y</code></td> <td class='summary-col'></td></tr> <tr><th>z</th><td class='letterval'>25</td> <td></td> <td></td> <td class='summary-col'></td> <td class='summary-col'></td> <td class='summary-col'></td></tr> </table> <h2>Letter Details</h2> <h3 id='a-instruction'><span class='instruction'>a</span> - Arithmetic Operation</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>num1</span><span class='operand'>num2</span></td><td><code>a</code></td><td><span class='operand'>num3</span></td></tr></table> <p>The <span class="instruction">a</span> pops two values from the stack, performs a mathematical operation on them and pushes the result back onto the stack. In all cases <code class="operand">num1</code> is the left hand side operand and <code class="operand">num2</code> is the right hand side operand.</p> <p>The specific operation to be performed on the two operands depends on the value of the <span class="instruction">a</span> register.</p> <h3 id='a-register'><span class='instruction'>a</span> - Operation Register</h3> <table class="wikitable"> <tr> <th>Value</th> <th>Name</th> <th>Operation</th> </tr> <tr><th class='operand'>a</th><td>Addition</td><td class='operand'>val3 = val1 + val2</td></tr> <tr><th class='operand'>b</th><td>Subtraction</td><td class='operand'>val3 = val1 - val2</td></tr> <tr><th class='operand'>c</th><td>Multiplication</td><td class='operand'>val3 = val1 * val2</td></tr> <tr><th class='operand'>d</th><td>Integer division</td><td class='operand'>val3 = val1 / val2</td></tr> <tr><th class='operand'>e</th><td>Modulo</td><td class='operand'>val3 = val1 % val2</td></tr> <tr><th class='operand'>f</th><td>Equality comparison</td><td class='operand'>val3 = val1 == val2</td></tr> <tr><th class='operand'>g</th><td>Greater than</td><td class='operand'>val3 = val1 &gt; val2</td></tr> <tr><th class='operand'>h</th><td>Greater or equal</td><td class='operand'>val3 = val1 &gt;= val2</td></tr> <tr><th class='operand'>i</th><td>Less or equal</td><td class='operand'>val3 = val1 &lt;= val2</td></tr> <tr><th class='operand'>j</th><td>Less than</td><td class='operand'>val3 = val1 &lt; val2</td></tr> <tr><th class='operand'>k</th><td>Not equal</td><td class='operand'>val3 = val1 != val2</td></tr> </table> '''Examples''' Code: <pre>cdlap</pre> Output: <pre>f</pre> <p>The program starts in literal mode, so <code class="operand">c</code> and <code class="operand">d</code> are pushed onto the stack as data.<br/> [[#l_-_Literal|l]] disables literal mode, so [[#a_-_Arithmetic_Operation|a]] is executed as an instruction. It pops <code class="operand">c</code> (2) and <code class="operand">d</code> (3) from the stack calculates their sum, <code class="operand">f</code> (5), then pushes it onto the stack.<br/> Finally, [[#p_-_Print|p]] prints the top of the stack to standard output.</p> Code: <pre>czlap</pre> Output: <pre>b</pre> <p>This example adds <code class="operand">c</code> (2) and <code class="operand">z</code> (25). Ther output is <code class="operand">b</code> (1) because math operations are modulo 26.</p> Code: <pre>cdaclsap</pre> Output: <pre>g</pre> <p>This example multiplies <code class="operand">c</code> (2) and <code class="operand">d</code> (3). This is achieved by setting the [[#a_-_Operation_Register|a register]] to <code class="operand">c</code> using [[#s_-_Set|s]]. </p> <h3 id='b-instruction'><span class='instruction'>b</span> - Break</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>b</code></td><td></td></tr></table> <p>Breaks out of the current loop. Does not affect the stack.</p> '''Example''' <p>If we take this starting example:</p> <pre>xpkbl a labl c lxl d lal r</pre> <p>it will endlessly print <code>a</code>.</p> <p>The explanation chunk by chunk:</p> <pre>xpkbl a</pre> <p>Pushes <code>xpkb</code> onto the stack, then calls [[#a_-_Arithmetic_Operation|a]] to add <code>b</code> and <code>k</code> to obtain <code>l</code> since <code>l</code> can't be pushed onto the stack directly, obtaining <code>xpl</code>.</p> <pre>labl c</pre> <p>Pushes <code>a</code> and copies the <code>l</code> with [[#c_-_Copy|c]] resulting with the stack <code>xplal</code>.</p> <pre>lxl d</pre> <p>Pushes <code>x</code> as a marker, then [[#d_-_Define|d]] rolls the stack betwen the two <code>x</code> markers into a procedure. Note that the procedure will be reversed compared to the other of the stack. The procedure will be pushed into the procedure stack as <code>lalp</code>.</p> <pre>lal r</pre> <p>Pushes <code>a</code> onto the stack to create an infinite loop with [[#r_-_Repeat|r]], which will pop the created procedure and loop it indefinitely. The procedure just prints <code>a</code> every time. </p> If we add a break to the procedure the loop will stop after the first iteration: <pre>xbpkbl a labl c lxl d lal r</pre> Output: <pre>a</pre> <h3 id='c-instruction'><span class='instruction'>c</span> - Copy</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>index</span></td><td><code class='instruction'>c</code></td><td><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>val</span></td></tr></table> <p>Copies a value <code class="operand">index</code> positions into the stack.</p> <p>It pops <code class="operand">index</code>, looks into the stack from the top that many spaces, and pushes a copy of the corresponding value on top of the stack.</p> '''Example''' <pre>somedatafl c</pre> <p>This pushes <code>somedataf</code> onto the stack then executes [[#c_-_Copy|c]]. It will pop <code>f</code> (5), then look that many spaces down the remaining stack, find <code>m</code> and copy it on top of the stack. This results in a stack of <code>somedatam</code>. </p> <h3 id='d-instruction'><span class='instruction'>d</span> - Define</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td><td><code class='instruction'>d</code></td><td></td></tr></table> <p>Defines a procedure delimited by <code class="operand">mark</code> and pushes it on the procedure stack.</p> <p>It pops the first stack value, <code class="operand">mark</code> which can be anything, then keeps popping until another value equal to <code class="operand">mark</code> is found (or the stack is empty).</p> <p>The result is then pushed onto the procedure stack, with the values flipped compared to how they were in the initial stack. The flip happens because values are pushed onto the procedure as they are popped from the stack.</p> '''Example''' This example uses a procedure and a loop to print the contents of the stack until a delimiter (<code>z</code>) is reached. Code: <pre>zerudecorp a af xpikacjbzjx jbk xhx ob l sdaodsr</pre> Output: <pre>procedure</pre> <p>Before the [[#l_-_Literal|l]] all the letter are pushed onto the stack. then the following operations are performed:</p> <p>[[#s_-_Set|s]] pops <code>ob</code> and sets the [[#o_-_Keep_Mark_Register|o register]] is set to keep the delimiter.</p> <p>[[#d_-_Define|d]] pops <code>xhx</code> and pushes <code>h</code> as a procedure. Here we are using <code>x</code> as a delimiter but any letter works as delimiter, just ensure it isn't used with the procedure itself. </p> <p>[[#a_-_Arithmetic_Operation|a]] pops <code>bk</code>, adds them, and pushes <code>l</code> (this is because <code>l</code> cannot be used as a literal).</p> <p>[[#o_-_Overwrite|o]] pops <code>jl</code> and preforms a replacement from <code>j</code> to <code>l</code>. using <code>x</code> as delimiter. Results in changing the top of the stack from <code>xpikacjbzjx</code> to <code>xpikaclbzlx</code>. The <code>x</code> delimiters are preserved due to the value of [[#o_-_Keep_Mark_Register|o register]] that was set previously. </p> <p>[[#d_-_Define|d]] pops <code>xpikaclbzlx</code> and pushes <code>lzblcakip</code> as a procedure.</p> <p>[[#s_-_Set|s]] pops <code>af</code> and sets the [[#a_-_Operation_Register|a register]] to perform equality comparison.</p> <p>[[#r_-_Repeat|r]] pops <code>a</code> and performs the last procedure indefinitely.</p> The code in the procedure does the following: <pre>lzbl c akip</pre> <p><code>lzbl</code> pushes <code>zb</code> onto the stack.</p> <p>[[#c_-_Copy|c]] pops <code>b</code> and copies the item below the head of the stack back on top. This copies the value set at the start of the main code </p> <p>[[#a_-_Arithmetic_Operation|a]] pops the copied value and <code>b</code> from the stack pushing <code>b</code> (true) or <code>a</code> (false) based on their comparison (because [[#a_-_Operation_Register|a register]] is set to comparison.</p> <p>[[#k_-_Keep|k]] duplicates the top procedure. Note that [[#r_-_Repeat|r]] pops the procedure before looping so the top procedure is now <code>h</code>.</p> <p>[[#i_-_If|i]] pops the value left by [[#a_-_Arithmetic_Operation|a]] and the procedure duplicated by [[#k_-_Keep|k]]. If the result of the comparison is true, (the letter copied by [[#c_-_Copy|c]] is <code>z</code>), it will call the procedure which in turns halts the program using [[#h_-_Halt|h]]. If the condition is not true nothing else happens.</p> <p>[[#p_-_Print|p]] pops the top of the stack and prints it. This causes the stack size to decrease by one.</p> <p>After this [[#r_-_Repeat|r]] keeps repeating the procedure, which has the effect of printing the stack until the character <code>z</code> is reached.</p> <h3 id='e-instruction'><span class='instruction'>e</span> - Execute Specific</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>e</code></td><td></td></tr></table> <p>Executes a specific procedure based on [[#e_-_Execute_Index_Register|e register]], not affecting any of the stacks.</p> <p>This is handy to repeatedly calling a procedure without having to modify stack values.</p> <h3 id='e-register'><span class='instruction'>e</span> - Execute Index Register</h3> <p>Procedure index for [[#e_-_Execute_Specific|e]]. A value of <code>a</code> (0), which is the default means the first procedure.<p> <p>This index is counted from the bottom of the procedure stack.</p> '''Example''' Code: <pre>tset xqx xax xpx xhx eb l s dddd eeee</pre> Output: <pre>test</pre> <p>Values are pushed onto the stack until [[#l_-_Literal|l]].</p> <p>[[#s_-_Set|s]] pops <code>eb</code> and sets the [[#e_-_Execute_Index_Register|e register]] is set to <code>b</code> (1).</p> <p>[[#d_-_Define|d]] is called 4 times and it defines procedures based on the <code>x</code> delimiter. After this the procedure stack has these procedures: <code>h</code>, <code>p</code>, <code>a</code>, <code>q</code>. </p> <p>[[#e_-_Execute_Specific|e]] is called 4 times as well, each time executing the procedure at index 1, which just prints the top of the stack. Note that any procedure defined after the one with the given index doesn't matter as [[#e_-_Execute_Index_Register|e register]] refers to indices starting from the bottom of the procedure stack.</p> <h3 id='f-instruction'><span class='instruction'>f</span> - Flip</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>...</span><span class='operand'>count</span></td><td><code class='instruction'>f</code></td><td><span class='operand'>...</span></td></tr></table> <p>Reverses the order of <code class="operand">count</code> items on the top of the stack.</p> <p>Pops <code class="operand">count</code>, then pops that many other items off the top of the stack and pushes them back onto the stack but in reverse order.</p> '''Example''' Code: <pre>foobar d l f</pre> <p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>foobard</code>.</p> <p>[[#f_-_Flip|f]] pops <code>d</code> (3), then flips the next 3 items on the stack, resulting with a stack of <code>foorab</code>.</p> <h3 id='g-instruction'><span class='instruction'>g</span> - Get</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>reg</span></td><td><code class='instruction'>g</code></td><td><span class='operand'>val</span></td></tr></table> <p>Pops <code class="operand">reg</code> from the stack, then pushes the value of the corresponding register onto the stack.</p> '''Example''' Code: <pre>m mf l s g</pre> <p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>mmf</code>.</p> <p>[[#s_-_Set|s]] pops <code>mf</code> and sets the [[#m_-_Memory_Cell_Register|m register]] to <code>f</code>.</p> <p>[[#g_-_Get|g]] pops <code>m</code> and pushes its value (<code>f</code>) onto the stack, resulting in a stack with <code>f</code>.</p> <h3 id='h-instruction'><span class='instruction'>h</span> - Halt</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>h</code></td><td></td></tr></table> <p>Halts execution, without affecting the stack.</p> '''Example''' Code: <pre>abcd l p p h p p</pre> Output: <pre>dc</pre> <p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>abcd</code>.</p> <p>[[#p_-_Print|p]] is called twice popping <code>d</code> and <code>c</code> off the stack and printing them.</p> <p>[[#h_-_Halt|h]] halts execution so the remaining [[#p_-_Print|p]] calls are not executed.</p> <h3 id='i-instruction'><span class='instruction'>i</span> - If</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>valn</span><span class='operand'>...</span><span class='operand'>val0</span></td><td><code class='instruction'>i</code></td><td></td></tr></table> <p>Pops the top value from the stack and the top procedure off the top of the procedure stack. If the value is true (anything but <code>a</code>), the procedure is then executed.</p> <p>The value of the [[#i_-_If_Else_Count_Register|i register]] defines if-else chain, [[#i_-_If|i]] will pop enough values and procedure to satisfy that many conditions.</p> <h3 id='i-register'><span class='instruction'>i</span> - If Else Count Register</h3> <p>Determines how many if-else chains are present (if any).</p> <p>The default value of <code>a</code> (0), indicates there is no else to execute. [[#i_-_If|i]] will pop a single value and procedure.</p> <p>A value of <code>b</code>, indicates an else procedure. [[#i_-_If|i]] will pop one value and two procedures, the second procedure being executed if the condition is not true.</p> <p>For higher values of the [[#i_-_If_Else_Count_Register|i register]], [[#i_-_If|i]] will pop additional values off the stack and procedures, executing the procedure of the first matching condition (or the last procedure if no conditions match).</p> '''Examples''' Code: <pre>z xjajx yjkb l ao d t i p</pre> <p>Output: <code>a</code> or <code>z</code> based on user input.</p> <p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>zxjajxyjkb</code>.</p> <p>[[#a_-_Arithmetic_Operation|a]] pops <code>bk</code>, adds them, and pushes <code>l</code> (this is because <code>l</code> cannot be used as a literal).</p> <p>[[#o_-_Overwrite|o]] pops <code>yjl</code> and preforms a replacement from <code>j</code> to <code>l</code> until the end of the stack since there are no other <code>y</code> values on the stack. All this results with a stack of <code>zxlalx</code>.</p> <p>[[#d_-_Define|d]] pops <code>xlalx</code> and pushes <code>lal</code> as a procedure. This procedure just pushes <code>a</code> onto the stack.</p> <p>[[#t_-_Text_Input|t]] reads a character from the user, converts it into a letter, and pushes it onto the stack.</p> <p>[[#i_-_If|i]] pops this user-generated value, the procedure, and if the value is true, the procedure is executed. Now the stack is either <code>z</code> or <code>za</code>.</p> <p>[[#p_-_Print|p]] pops the top of the stack and prints it, printing <code>a</code> if the user input evaluated as true, and <code>z</code> otherwise.</p> Code: <pre>xjajx xjzjx yjkb ib l s ao dd t i p</pre> <p>This example has the same output as the previous one but it works slightly differently.</p> <p>The first operation after exiting literal mode is [[#s_-_Set|s]] to set [[#i_-_If_Else_Count_Register|i register]] to <code>b</code> (1). This indicates that [[#i_-_If_Else_Count_Register|i register]] should use an else procedure.</p> <p>Now the next difference is that there are two procedures in the procedure stack: <code>lzl</code> and <code>lal</code>, wich just push <code>z</code> or <code>a</code> onto the value stack. Note that <code>lal</code> is the procedure on top of the stack because it has been pushed last.</p> <p>[[#i_-_If|i]] now pops both procedures off the procedure stack, executing the first on true and the second on false.</p> Code: <pre>xjajx xjbjx xjcjx yjkb ic l s ao ddd tt lclf i p</pre> <p>This example takes 2 inputs from the user and selects one of 3 procedures to execute.</p> <p><code>tt</code> will read 2 inputs from the user and push them onto the stack. since this will cause the inputs to be in reverse order (the last input is on top of the stack) <code>lclf</code> uses [[#f_-_Flip|f]] to flip them back around. Now the first input is on top of the stack and the second input below it.</p> <p>The [[#i_-_If_Else_Count_Register|i register]] is set to <code>c</code> (2), indicating an else-if chain.</p> <p>[[#i_-_If|i]] now pops 2 values off the value stack and 3 procedures. It uses the first value from the stack as the first condition, if that is true the first procedure is executed. Otherwise, if the next value is true, the second procedure is executed. Finally, if both values are false, the third procedure is executed. </p> <h3 id='k-instruction'><span class='instruction'>k</span> - Keep</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>k</code></td><td></td></tr></table> <p>Duplicates the procedure on top of the procedure stack.</p> <p>This is useful if you want to run [[#i_-_If|i]] or [[#x_-_Execute|x]] while keeping the procedure on the stack for later use.</p> <h3 id='k-register'><span class='instruction'>k</span> - Keep Count Register</h3> <p>Determines the number of procedures [[#k_-_Keep|k]] will copy. The number is the value of this register plus one.</p> '''Example''' Code: <pre>xpppjfoojx yjkb l ao d kxx</pre> Output: <pre>foofoo</pre> <p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>xpppjfoojxyjkb</code>.</p> <p>[[#a_-_Arithmetic_Operation|a]] and [[#o_-_Overwrite|o]] ensure <code>j</code> values on the stack are replaced by <code>l</code> as <code>l</code> cannot be used as a literal. The stack after them is <code>xppplfoolx</code></p> <p>[[#d_-_Define|d]] defines the procedure <code>looflppp</code>, which prints the string "foo" to output.</p> <p>Finally [[#k_-_Keep|k]] duplicates this procedure, and [[#x_-_Execute|x]] is called twice, popping and executing the two copies of the procedure.</p> <h3 id='l-instruction'><span class='instruction'>l</span> - Literal</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>l</code></td><td></td></tr></table> <p>Switches between literal and instruction modes.</p> <p>Specifically it toggles the [[#l_-_Literal|l]] register between <code>a</code> (0), which indicated literal mode, and <code>b</code> (1), instruction mode.</p> <p>While in instruction mode all letters are executed as an instruction.</p> <p>In literal mode (which is the mode at the start of execution) letters are pushed onto the value stack.</p> <p>[[#l_-_Literal|l]] will keep its behaviour in both modes so the letter <code>l</code> cannot appear directly as a literal.</p> <h3 id='l-register'><span class='instruction'>l</span> - Mode Register</h3> <p>Determines whether the program is in literal mode or instruction mode.</p> <p>A value of <code>a</code> indicates literal mode, any other value is instruction mode.</p> <p>Generally it's toggled with [[#l_-_Literal|l]] but setting a value explicitly using [[#s_-_Set|s]] will also switch between modes.</p> '''Example''' Code: <pre>oof l ppp lrabl ppp</pre> Output: <pre>foobar</pre> <p><code>oof</code> are pushed onto the stack because the program starts in literal mode.</p> <p>[[#l_-_Literal|l]] enables instruction mode and [[#p_-_Print|p]] is called 3 times to print <code>foo</code> from the stack to the output.</p> <p>In <code>lrabl</code> literal mode is entered again to push <code>rab</code> onto the stack, the last [[#l_-_Literal|l]] goes back into instruction mode.</p> <p>Finally [[#p_-_Print|p]] is called again to print <code>bar</code>.</p> '''Adding <code class="instruction">l</code> onto the stack''' <p>Since [[#l_-_Literal|l]] ends literal mode, values of <code>l</code> cannot be directly added onto the stack, but some easy work-arounds are available.</p> <p>The most basic is to use addition to get an <code>l</code> from other values:</p> <pre>kb l a</pre> <p>Here [[#a_-_Arithmetic_Operation|a]] pops <code>k</code> and <code>b</code> from the stack, adds them together, and pushes <code>l</code> (the result of this addition) back onto the stack.</p> <p>Sometimes you might want multiple <code>l</code> on the stack, this is especially useful when defining procedures that need to output literal values on the stack. You can achieve this by combining the previous approach with the overwrite instruction ([[#l_-_Literal|l]]):</p> <pre>jjj x jjj x j bk l ao</pre> <p>Here [[#a_-_Arithmetic_Operation|a]] does the same as it did before, replacing <code>bk</code> with <code>l</code>.</p> <p>[[#o_-_Overwrite|o]] pops <code>xjl</code>. It preforms a replacement from <code>j</code> to <code>l</code> using <code>x</code> as delimiter. Both instances of the delimiter are removed from the stack.</p> <p>At the end the stack will be <code>jjjlll</code>, the first the <code>j</code> not being replaced because found after the delimiter when searching from the top of the stack.</p> <h3 id='m-instruction'><span class='instruction'>m</span> - Memory</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>m</code></td><td><span class='operand'>val</span></td></tr></table> <p>Pushes the value of the [[#m_-_Memory_Cell_Register|m register]] onto the stack.</p> <p>This can be useful if there is a value that needs to be pushed onto the stack multiple time.</p> <h3 id='m-register'><span class='instruction'>m</span> - Memory Cell Register</h3> <p>Doesn't have any special meaning, pushed onto the stack by [[#m_-_Memory|m]].</p> '''Examples''' Code: <pre>lmmmppp</pre> Output: <pre>aaa</pre> <p>[[#l_-_Literal|l]] enables instruction mode.</p> <p>[[#m_-_Memory|m]] is called 3 times and pushes the default value (<code>a</code>) onto the stack each time.</p> <p>[[#p_-_Print|p]] is called 3 times, popping the 3 values and printing them.</p> Code: <pre>mz l s mmmppp</pre> Output: <pre>zzz</pre> <p>Same as before but [[#s_-_Set|s]] uses the <code>z</code> and <code>m</code> values from the stack to set the [[#m_-_Memory_Cell_Register|m register]] to <code>z</code>.</p> <h3 id='n-instruction'><span class='instruction'>n</span> - Number of Items</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>n</code></td><td><span class='operand'>count</span></td></tr></table> <p>Pushed onto the stack the number of items currently on the stack</p> <h3 id='n-register'><span class='instruction'>n</span> - Number Size Register</h3> <p>Number of letters per number, see [[Multi-Letter_Numbers|multi-letter numbers]] in advanced concepts.</p> '''Examples''' Code: <pre>foobar l nf</pre> <p><code>foobar</code> is pushed onto the stack, then [[#n_-_Number_of_Items|n]] pushes the stack count <code>g</code> (6) onto the stack. Finally [[#f_-_Flip|f]] pops that value and flips the whole stack.</p> Code: <pre>foobar xpx l d n f n r</pre> Output: <pre>foobar</pre> <p><code>foobarxpx</code> is pushed onto the value stack, then [[#d_-_Define|d]] pops <code>xpx</code> to push <code>p</code> on the procedure stack.</p> <p>As before [[#n_-_Number_of_Items|n]] followed by [[#f_-_Flip|f]] flips the entire stack. Finally [[#n_-_Number_of_Items|n]] followed by [[#r_-_Repeat|r]] repeats the print procedure for each item on the stack.</p> <p>Note that this works up to a value of <code>z</code> (25).</p> <h3 id='o-instruction'><span class='instruction'>o</span> - Overwrite</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span><span class='operand'>search</span><span class='operand'>replace</span></td><td><code class='instruction'>o</code></td><td><span class='operand'>...</span></td></tr></table> <p>Replaces values on the stack until a delimiter is reached.</p> <p>Pops <code>replace</code> and <code>search</code> from the stack. Then replaces all instanced of <code>search</code> between the two <code>mark</code> with <code>replace</code>.</p> <p>If the second <code>mark</code> is not found, all occurrences of <code>search</code> will be replaced.</p> <p>The two <code>mark</code> are removed from the stack by default but they can be preserved depending on the value of the [[#o_-_Keep_Mark_Register|o register]].</p> <h3 id='o-register'><span class='instruction'>o</span> - Keep Mark Register</h3> <p>By default [[#o_-_Overwrite|o]] deleted the markers from the stack, if this register has a value other than <code>a</code>, they are kept.</p> '''Example''' Code: <pre>test x test x t b l o</pre> <p>All the values until [[#l_-_Literal|l]] are pushed onto the stack.</p> <p>[[#o_-_Overwrite|o]] pops <code>xtb</code> from the stack, and replaces all <code>t</code> into <code>b</code> until the next <code>x</code> is found.</p> <p>This results in the stack ending with <code>testbesb</code>.</p> <p>Note that the value <code>x</code> is arbitrary, any letter can work as a marker.</p> Code: <pre>test x test x t b ob l s o</pre> <p>Similar as before, now [[#s_-_Set|s]] pops <code>ob</code> and sets the [[#o_-_Keep_Mark_Register|o register]] to <code>b</code>.</p> <p>The rest works the same except the markers are kept, resulting in <code>testxbesbx</code>.</p> <h3 id='p-instruction'><span class='instruction'>p</span> - Print</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>val</span></td><td><code class='instruction'>p</code></td><td></td></tr></table> <p>Pops a letter from the stack and prints it to output.</p> <p>By default prints them as lower case letters but this can changed based on the value of the [[#p_-_Print_Mode_Register|p register]].</p> <h3 id='p-register'><span class='instruction'>p</span> - Print Mode Register</h3> <p>Specifies the print mode, depending on the mode letters are printed differently.</p> <p>Using the right combination of printed letter and mode, any ASCII character can be printed.</p> <table class="wikitable print-mode mono"> <caption>Print Modes</caption> <tr><th rowspan="2">Letter</th><th colspan="5">Mode</th></tr> <tr><th>a</th> <th>b</th> <th>c</th> <th>d</th> <th>e</th></tr> <tr><th>a</th><td class='print-mode'>a</td><td class='print-mode'>A</td><td class='print-mode'>0</td><td class='print-mode'>!</td><td class='print-mode'>NUL</td></tr> <tr><th>b</th><td class='print-mode'>b</td><td class='print-mode'>B</td><td class='print-mode'>1</td><td class='print-mode'>&quot;</td><td class='print-mode'>x01</td></tr> <tr><th>c</th><td class='print-mode'>c</td><td class='print-mode'>C</td><td class='print-mode'>2</td><td class='print-mode'>#</td><td class='print-mode'>x02</td></tr> <tr><th>d</th><td class='print-mode'>d</td><td class='print-mode'>D</td><td class='print-mode'>3</td><td class='print-mode'>$</td><td class='print-mode'>x03</td></tr> <tr><th>e</th><td class='print-mode'>e</td><td class='print-mode'>E</td><td class='print-mode'>4</td><td class='print-mode'>%</td><td class='print-mode'>x04</td></tr> <tr><th>f</th><td class='print-mode'>f</td><td class='print-mode'>F</td><td class='print-mode'>5</td><td class='print-mode'>&amp;</td><td class='print-mode'>x05</td></tr> <tr><th>g</th><td class='print-mode'>g</td><td class='print-mode'>G</td><td class='print-mode'>6</td><td class='print-mode'>&apos;</td><td class='print-mode'>x06</td></tr> <tr><th>h</th><td class='print-mode'>h</td><td class='print-mode'>H</td><td class='print-mode'>7</td><td class='print-mode'>(</td><td class='print-mode'>x07</td></tr> <tr><th>i</th><td class='print-mode'>i</td><td class='print-mode'>I</td><td class='print-mode'>8</td><td class='print-mode'>)</td><td class='print-mode'>x08</td></tr> <tr><th>j</th><td class='print-mode'>j</td><td class='print-mode'>J</td><td class='print-mode'>9</td><td class='print-mode'>*</td><td class='print-mode'>HT</td></tr> <tr><th>k</th><td class='print-mode'>k</td><td class='print-mode'>K</td><td class='print-mode'>:</td><td class='print-mode'>+</td><td class='print-mode'>LF</td></tr> <tr><th>l</th><td class='print-mode'>l</td><td class='print-mode'>L</td><td class='print-mode'>;</td><td class='print-mode'>,</td><td class='print-mode'>x0b</td></tr> <tr><th>m</th><td class='print-mode'>m</td><td class='print-mode'>M</td><td class='print-mode'>&lt;</td><td class='print-mode'>-</td><td class='print-mode'>x0c</td></tr> <tr><th>n</th><td class='print-mode'>n</td><td class='print-mode'>N</td><td class='print-mode'>=</td><td class='print-mode'>.</td><td class='print-mode'>CR</td></tr> <tr><th>o</th><td class='print-mode'>o</td><td class='print-mode'>O</td><td class='print-mode'>&gt;</td><td class='print-mode'>/</td><td class='print-mode'>x0e</td></tr> <tr><th>p</th><td class='print-mode'>p</td><td class='print-mode'>P</td><td class='print-mode'>?</td><td class='print-mode'>@</td><td class='print-mode'>x0f</td></tr> <tr><th>q</th><td class='print-mode'>q</td><td class='print-mode'>Q</td><td class='print-mode'>x1a</td><td class='print-mode'>[</td><td class='print-mode'>x10</td></tr> <tr><th>r</th><td class='print-mode'>r</td><td class='print-mode'>R</td><td class='print-mode'>ESC</td><td class='print-mode'>\</td><td class='print-mode'>x11</td></tr> <tr><th>s</th><td class='print-mode'>s</td><td class='print-mode'>S</td><td class='print-mode'>x1c</td><td class='print-mode'>]</td><td class='print-mode'>x12</td></tr> <tr><th>t</th><td class='print-mode'>t</td><td class='print-mode'>T</td><td class='print-mode'>x1d</td><td class='print-mode'>^</td><td class='print-mode'>x13</td></tr> <tr><th>u</th><td class='print-mode'>u</td><td class='print-mode'>U</td><td class='print-mode'>x1e</td><td class='print-mode'>_</td><td class='print-mode'>x14</td></tr> <tr><th>v</th><td class='print-mode'>v</td><td class='print-mode'>V</td><td class='print-mode'>x1f</td><td class='print-mode'>`</td><td class='print-mode'>x15</td></tr> <tr><th>w</th><td class='print-mode'>w</td><td class='print-mode'>W</td><td class='print-mode'>SP</td><td class='print-mode'>{</td><td class='print-mode'>x16</td></tr> <tr><th>x</th><td class='print-mode'>x</td><td class='print-mode'>X</td><td class='print-mode'>x7f</td><td class='print-mode'>|</td><td class='print-mode'>x17</td></tr> <tr><th>y</th><td class='print-mode'>y</td><td class='print-mode'>Y</td><td class='print-mode'></td><td class='print-mode'>}</td><td class='print-mode'>x18</td></tr> <tr><th>z</th><td class='print-mode'>z</td><td class='print-mode'>Z</td><td class='print-mode'></td><td class='print-mode'>~</td><td class='print-mode'>x19</td></tr> </table> <p>The special mode <code>z</code> will cause [[#p_-_Print_Mode_Register|p register]] to not print anything turning it into a pop operation.</p> '''Examples''' Code: <pre>tnirp l ppppp</pre> Output: <pre>print</pre> <p>All the values until [[#l_-_Literal|l]] are pushed onto the stack then [[#p_-_Print_Mode_Register|p register]] is called multiple times, each time it pops a value off the stack and prints it.</p> <p>Note that since [[#p_-_Print_Mode_Register|p register]] prints off the top of the stack, the stack values need to be in reverse order to be printed.</p> Code: <pre>tnirp pb l s ppppp</pre> Output: <pre>PRINT</pre> <p>Similar as before, now [[#s_-_Set|s]] pops <code>pb</code> and sets the [[#p_-_Print_Mode_Register|p register]] to <code>b</code>, switching to uppercase print mode.</p> Code: <pre>hddb pc l s pppp</pre> Output: <pre>1337</pre> <p>Print mode <code>c</code> can be used to print numbers.</p> Code: <pre>tnirp pz l s ppppp</pre> (No Output) <p>Print mode <code>z</code> can be used to pop values off the stack without printing them.</p> Code: <pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre> Output: <pre>Hello World!</pre> <p>Does the usual trick to replace <code>l</code> (see [[#l_-_Literal|l]] examples). Then keeps switching print modes and printing values from the stack.</p> <h3 id='r-instruction'><span class='instruction'>r</span> - Repeat</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>count</span></td><td><code class='instruction'>r</code></td><td></td></tr></table> <p>Pops <code>count</code> and the top procedure from the procedure stack and executes said procedure <code>count</code> times. A count of <code>a</code> (0) means infinite loop.</p> '''Example''' Code: <pre>tset e xpx l dr</pre> Output: <pre>test</pre> <p>After [[#l_-_Literal|l]] the stack contains <code>tsetexpx</code>.</p> <p>[[#d_-_Define|d]] pops <code>xpx</code> from the value stack and pushes <code>p</code> on the procedure stack.</code> <p>[[#r_-_Repeat|r]] pops <code>e</code> (4) from the value stack, the procedure from the procedure stack and repeats it 4 times, printing the 4 remaining letters on the stack.</p> <h3 id='s-instruction'><span class='instruction'>s</span> - Set</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>reg</span><span class='operand'>val</span></td><td><code class='instruction'>s</code></td><td></td></tr></table> <p>Pops <code class="operand">reg</code> and <code class="operand">val</code> from the stack, then sets the corresponding register to <code class="operand">val</code>.</p> '''Example''' Code: <pre>m mf l s g</pre> <p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>mmf</code>.</p> <p>[[#s_-_Set|s]] pops <code>mf</code> and sets the [[#m_-_Memory_Cell_Register|m register]] to <code>f</code>.</p> <p>[[#g_-_Get|g]] pops <code>m</code> and pushes its value (<code>f</code>) onto the stack, resulting in a stack with <code>f</code>.</p> <h3 id='t-instruction'><span class='instruction'>t</span> - Text Input</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>t</code></td><td><span class='operand'>val?</span></td></tr></table> <p>Pushes a letter onto the stack based on user input.</p> <p>Reads one character from the input stream, converts into a letter using the reverse operation of [[#p_-_Print|p]] and sets the [[#t_-_Read_Result_Register|t register]] to the print mode that would yield that character.</p> <p>On failure (end of file or invalid character) it sets the [[#t_-_Read_Result_Register|t register]] to <code>z</code> and doesn't push anything onto the stack.</p> <h3 id='t-register'><span class='instruction'>t</span> - Read Result Register</h3> <p>Holds the status of the last [[#t_-_Text_Input|t]] operation. Basically if you want to print back the same character you need to set the [[#p_-_Print_Mode_Register|p register]] to the value of the [[#t_-_Read_Result_Register|t register]]. The special value of <code>z</code> indicates an error. Refer to the documentation of the [[#p_-_Print_Mode_Register|p register]] for a description of values.</p> '''Example''' Code: <pre>lt</pre> <p>[[#l_-_Literal|l]] exits literal mode, then [[#t_-_Text_Input|t]] reads one character from input. Follow a few examples of the end state based on the input.</p> <p>If the user typed <code>h</code>, the [[#t_-_Read_Result_Register|t register]] holds the value <code>a</code> and the stack the value <code>h</code>.</p> <p>If the user typed <code>H</code>, the stack still holds the value <code>h</code> but now the [[#t_-_Read_Result_Register|t register]] has the value <code>b</code> which corresponds to the upper case print mode.</p> <p>If the user typed <code>3</code>, the stack still holds the value <code>d</code> but now the [[#t_-_Read_Result_Register|t register]] has the value <code>c</code> which corresponds to the number print mode.</p> <p>If the input reached end of file, the [[#t_-_Read_Result_Register|t register]] will have the value <code>z</code> and the stack will be empty.</p> <h3 id='u-instruction'><span class='instruction'>u</span> - Undo</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td><td><code class='instruction'>u</code></td><td></td></tr></table> <p>Pops everything on the stack until <code>mark</code> is found.</p> <p>Starts by popping <code>mark</code>, that can be any letter. Then it keeps popping until it finds another value of <code>mark</code> or the stack is empty.</p> '''Example''' Code: <pre>foobartest l u</pre> <p>Before [[#u_-_Undo|u]] is executed, the stack contains <code>foobartest</code>.</p> <p>[[#u_-_Undo|u]] pops a <code>t</code> then keeps popping until the following <code>t</code> is popped, then stops. At the end the stack holds <code>foobar</code></p> <h3 id='w-instruction'><span class='instruction'>w</span> - Wrap</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td><span class='operand'>...</span><span class='operand'>count</span><span class='operand'>steps</span></td><td><code class='instruction'>w</code></td><td><span class='operand'>...</span></td></tr></table> <p>Wraps the top <code>count</code> items of the stack by <code>steps</code> steps.</p> <p>Starts by popping <code>count</code> and <code>steps</code> from the value stack. Then it pops <code>count</code> more items, which will be the operands of the wrap operation.</p> <p>A wrap step consists on moving the first operand to the back of the list of operands. This is applied <code>steps</code> times.</p> <p>After all the steps, the operands are pushed back onto the stack in their new order.</p> '''Examples''' Code: <pre>foobar db l w</pre> <p>Here [[#w_-_Wrap|w]] performs <code>b</code> (1) step on the top <code>d</code> items, which are <code>bar</code>. This turns <code>bar</code> into <code>rba</code> as the <code>r</code> is moved to the back.</p> <p>At the end the stack contains <code>foorba</code>.</p> Code: <pre>foobar dc l w</pre> <p>The only change is the number of steps, resulting in a stack with <code>fooarb</code>.</p> <h3 id='x-instruction'><span class='instruction'>x</span> - Execute</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>x</code></td><td></td></tr></table> <p>Pops and executes the top procedure.</p> '''Example''' Code: <pre>abc qppq l d x p</pre> Output: <pre>cba</pre> <p>After [[#l_-_Literal|l]] the stack contains <code>abcqppq</code>.</p> <p>[[#d_-_Define|d]] pops <code>qppq</code> and pushes <code>pp</code> onto the procedure stack.</p> <p>[[#x_-_Execute|x]] pops this procedure and executes it. the procedure calls [[#p_-_Print|p]] twice printing <code>cb</code>.</p> <p>Finally execution continues after [[#x_-_Execute|x]], where an additional call to [[#p_-_Print|p]] prints <code>a</code>.</p> <h3 id='y-instruction'><span class='instruction'>y</span> - Yield</h3> '''Synopsis''' <table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>y</code></td><td></td></tr></table> <p>Stops execution of the current procedure, leaving the stack unchanged</p> '''Example''' Code: <pre>abc qpypq l d x p</pre> Output: <pre>cb</pre> <p>This is the same as the example for [[#x_-_Execute|x]] with the exception of the presence of [[#y_-_Yield|y]] in the middle of the procedure, which causes the second [[#p_-_Print|p]] to not be executed.</p> <h2>Advanced Concept</h2> <h3 id="multi-letter-numbers">Multi-Letter Numbers</h3> <p>By default each letter represents a number in base 26. Sometimes values between 0 and 25 are not enough. You can enable a mode that uses multiple letters per number by setting the [[#n_-_Number_Size_Register|n register]] to a higher value, the number of letters per numer is [[#n_-_Number_of_Items|n]] + 1.</p> <p>This affects the condition inputs for [[#i_-_If|i]], the output of [[#n_-_Number_of_Items|n]], and both inputs and outputs of [[#a_-_Arithmetic_Operation|a]].</p> <p>When multi-number letters are used, the most significant letter is on the stack. For example if the stack contains <code>te</code> (<code>e</code> being at the top of the stack) and there are 2 letters per number ([[#n_-_Number_Size_Register|n register]] set to <code>b</code>), The numerical value is calculated as <code>26 * e + t</code>, with all numbers <code>26 * 4 + 19</code>, which is 123.</p> <h2>External Links</h2> * [https://dragon.best/alphastack/#playground web-based playground] * [https://gitlab.com/mattia.basaglia/dragon.best/-/blob/master/media/scripts/alphastack/alphastack.py Python implementation]'
Unified diff of changes made by edit (edit_diff)
'@@ -1,0 +1,1263 @@ +{{infobox proglang +|name=AlphaStack +|paradigms=imperative +|author=[[User:Glax]] +|year=[[:Category:2026|2026]] +|memsys=[[:Category:Stack-based|Stack-based]] +|dimensions=one-dimensional +|class=[[:Category:Turing complete|Turing complete]] +|refimpl=[https://gitlab.com/mattia.basaglia/dragon.best/-/blob/master/media/scripts/alphastack/alphastack.py alphastack.py] +}} + +[[Category:Languages]] +[[Category:2026]] +[[Category:Stack-based]] +[[Category:Turing complete]] +[[Category:Deterministic]] +[[Category:Implemented]] + +<h2>Introduction</h2> + +<p><em>AlphaStack</em> is an stack-based language that uses only letters of the alphabet as values and instructions.</p> + +<p>Being stack based, the instructions typically pop their arguments from the stacks and push their results onto the stack.</p> + +<p>You can try this language at its official [https://dragon.best/alphastack/#playground web playground].</p> + +<h3>Examples</h3> + +<h4>Hello World</h4> + +<pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre> + +<h4>99 Bottles of beer</h4> + +<pre>vdyppsjepkkjesjeejesjdejidsjfexexjacjdjcsjfadaajasjbaabjpsppppppspsppspsppppspsp +pppspspppspsppppspsjepkaptakecpwaponecpwapdowncpwappasscpwapitcpwaparoundepkjesj +dejesjeejesjdejyyhesppppspsppspspppppppspsppppspsppsesjceapnocpwapmorecpwapbottx +escpwapofcpwapbeerzeejyypsppppspspppspsppspsesjcecpwaponcpwapthecpwapwaxxepkzjyy +ppppspsppspspppppppspsesjcecpwapbottxescpwapofcpwapbeerzjesjbejyysoassjanaakbxzb +njyyppsjcpjppeesjaejsjzpjcjbjcjbjyyasjdaakjwjbdjpsjzpjasjeaakjcjbjcjbjynbqjkblao +sdddddddlalr</pre> + +<h3 id="stack">Stacks and Procedures</h3> + +<p><em>AlphaStack</em> has two stacks:</p> + +<p>The value stack is where most operations happens, with individual letters being pushed and popped into it.</p> + +<p>The procedure stack contains procedures, the only instruction that can add to this stack is [[#d_-_Define|d]] and some other instructions can access the data stored there.</p> + +<p>A procedure is a sequence of letters that can be executed at a later time. +Procedures only ever exist on the procedure stack.</p> + +<p>This manual will often show a summary of an operation as follows:</p> + +<table class="wikitable"> + <tr><td><span class="operand">op1</span><span class="operand">op2</span></td> + <td><code class="instruction">a</code></td> + <td><span class="operand">result</span></td></tr> +</table> +<p>This shows the instruction <code class="instruction">a</code> and its effect on the stack. +Values before it in the summary represent the top of the stack before the execution of that instruction. +Values after it represent what the head of the stack has been replaced with. +In this example, <code class="operand">op1</code> and <code class="operand">op2</code> will be popped off the stack +and <code class="operand">result</code> will be popped onto the stack. +</p> + +<h3 id="literal-mode">Literal Mode</h3> + +<p><em>AlphaStack</em> has two modes: literal mode and instruction mode.</p> + +<p>In literal mode all valid characters are pushed directly onto the stack until the mode is switched.</p> + +<p>In instruction mode, all charcters are interpreted as instructions and executed immediately.</p> + +<p>The instruction [[#l_-_Literal|l]] is used to switch between these two modes, and it's the only +instruction to have an effect in literal mode.</p> + +<p>Program execution always starts in literal mode so you can add data before adding code.</p> + +<h3>Comments</h3> + +<p><em>AlphaStack</em> doesn't directly support comments but there are a few techniques to simulate them.</p> + +<p>All examples in this section are a print the characters <code>a</code> and <code>b</code> using +<code>alp</code> and <code>lblp</code> respectively. + +<p>First of all, all characters that are not lower case ASCII characters are ignored, so you can always add +spaces, upper case letter, and special character.</p> + +<pre>alp SPACES AND UPPER CASE LETTERS ARE IGNORED! lblp</pre> + +<p>Since yelling in every comment is considered ruse there's an alternative: +using the [[#l_-_Literal|l]] instruction you can start pushing values onto the stack, then +clear it with [[#u_-_Undo|u]]. Note that [[#u_-_Undo|u]] needs a marker (which can be any letter) +to stop clearing the stack so you can't use that character in the comment.</p> + +<pre>alp lx this is pushed then popped from the stack, so it has no effect on the program xlu lblp</pre> +<p>One side effect of this is that you can't use the marker letter (<code>x</code> in this example) nor single <code>l</code>s +in this style of comment as those they will switch back to instruction mode. +Pairs of <code>l</code>s will work as switching modes twice has no effect.</p> +<pre>alp lx Hello comment! xlu lblp</pre> + +<h3>Numbers</h3> + +<p>In <em>AlphaStack</em> there are only letters, no numbers. +However can consider interpret the letters as numbers based on their position in the alphabet. +With this in mind, <code>a</code> can be thought as 0, <code>b</code> as 1 and so on.</p> +<p>Similarly, the value <code>a</code> is considered false, while all other values are considered true.</p> + +<h3>Registers</h3> + +<p>Each letter has a register associated with it. These registered can be freely +written to or read from (using [[#s_-_Set|s]] and [[#g_-_Get|g]]). +Some instructions modify their behaviour based on the value of the corresponding register.</p> + +<p>At the start of a program all registers have a value of <code>a</code> (0).</p> + + +<h2>Tutorial</h2> + +<p>This section will walk through the basics of <em>AlphaStack</em> with some practical examples. +The tutorials assume you've been through the [[#Introduction|introduction]] fist.</p> + +<h3>Hello World</h3> + +<p>This tutorial shows the basics of printing text to standard output</p> + +<pre>abcd</pre> + +<p>Since a program starts in [[#Literal_Mode|literal mode]], +this code pushes <code>abcd</code> onto the [[#Stacks_and_Procedures|value stack]]. +<code>d</code> being at the top of the stack and <code>a</code> at the bottom.</p> + +<pre>abcd l</pre> + +<p>Any characters that are not letters are ignored, so the space does nothing. +[[#l_-_Literal|l]] exits literal mode and enters instruction mode. +This means after it letters will be executed as instructions rather than pushed onto the stack.</p> + +<pre>abcd l pppp</pre> + +<p>Here [[#p_-_Print|p]] is executed 4 times, printing 4 letters off the top of the stack. +This clears the stack as each letter is popped before printing and outputs <code>dbca</code>. <br/> +The order of the letters is reversed because they are printed from the top of the stack.</p> + +<p>Now, if we want to print <code>abcd</code> as numbers instead, we need to set the [[#p_-_Print_Mode_Register|p register]] to <code>c</code> first, this is done with the [[#s_-_Set|s]] command which pops a +reister and its value off the stack:</p> + +<pre>abcd pc l s pppp</pre> + +<p>Here <code>pc</code> on the stack is consumed by [[#s_-_Set|s]] to do just that +and the code outputs <code>3210</code>.</p> + +<p>Again, spaces are not meaningful in <em>AlphaStack</em> in the example they are used to +highlight which literals are used by which instuction.</p> + +<p>If you want to enter values in literal mode and then print them in the same order as +they were pushed onto the stack, you need to flip them around first:</p> + +<pre>abcd e l f pppp</pre> + +<p>Now [[#f_-_Flip|f]] pops <code>e</code> off the stack, this corresponds +with the number 4, and flips that many items on the stack. In this case the stack +ends up as <code>dbca</code>, printing <code>abcd</code>.</p> + +<p>Let's say we want to print the word "hello". There's an issue here, +[[#l_-_Literal|l]] switches between literal mode and instruction mode +so it can't be directly entered as a literal. +To work around this we can push a value <code>l</code> onto the stack by +performing a simple mathematical operation: +</p> + +<pre>kb l a p</pre> + +<p>[[#a_-_Arithmetic_Operation|a]] pops two values off the stack and adds them together, +in this case adds <code>b</code> (1) to <code>k</code>, obtaining <code>l</code>. +Then [[#p_-_Print|p]] prints it.</p> + +<p>Now we can print hello like so:</p> + +<pre>o kb kb e h l p p ap ap p</pre> + +<p>The first two [[#p_-_Print|p]] print <code>h</code> and <code>e</code> +respectively. Then [[#a_-_Arithmetic_Operation|a]] followed by [[#p_-_Print|p]] print an <code>l</code>, this is done twice. The final [[#p_-_Print|p]] prints +the <code>o</code>.</p> + +<p>Replacing each <code>l</code> individually can become tedious so we can push a single +one onto the stack and then replace a different character with it.</p> + +<code>oxxeh yxkb l a o ppppp</code> + +<p>Here [[#a_-_Arithmetic_Operation|a]] turns <code>kb</code> into <code>l</code> like before. +[[#o_-_Overwrite|o]] then pops the 3 topmost items on the stack: <code>yxl</code>. +It then performs a replacement of the values on the stack with as follows: +all occurrences of <code>x</code> are replaced by <code>l</code> until the next +<code>y</code> is reached. In this case there are no <code>y</code> values on the stack +after the initial one so the entire stack is processed. +Finally the five [[#p_-_Print|p]] print <code>hello</code>.</p> + +<p>We can combine all of this with different print modes to print <code>Hello World!</code>:</p> + +<pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre> + +<h3>Procedures and Loops</h3> + +<p>Let's say you don't want to type a [[#p_-_Print|p]] for every single letters you +want to output. We can create a procedure that prints the stack until a condition is met.</p> + +<p>First we need to get a condition that checks the top of the stack for a given value and +halts execution when found. +Conditionals are handled by [[#i_-_If|i]], which needs a procedure to run when the condition is met. +We start by defining the halting procedure:/p> + +<pre>xhx l d</pre> + +<p>[[#d_-_Define|d]] here uses <code>x</code> as a delimiter +and pushes a procedure containing <code>h</code> on top of the procedure stack.</p> + +<p>Now we are ready to define the main procedure. +Since we need literals in the main procedure we need to perform the usual trick to replace +<code>j</code> with <code>l</code>:</p> + +<pre>xpikacjbzjx jbk ob xhx l d sao d</pre> + +<p>This code starts as before with [[#d_-_Define|d]] popping <code>xhx</code> from the value +stack and pushing <code>h</code> onto the procedure stack. +Then <code>sao</code> performs the <code>j</code> to <code>l</code> replacement: +[[#s_-_Set|s]] pops <code>ob</code> to set the [[#o_-_Keep_Mark_Register|o register]] to keep the delimiter. +[[#a_-_Arithmetic_Operation|a]] the pops <code>bk</code> to push a <code>l</code>. +[[#o_-_Overwrite|o]] pops <code>jl</code> to replace all occurrences of <code>j</code> with <code>l</code> +using <code>x</code> as a delimiter. Since we set the [[#o_-_Keep_Mark_Register|o register]] register to the value +<code>b</code> using [[#s_-_Set|s]], the <code>x</code> delimiters are not removed from the stack. +This allows [[#d_-_Define|d]] to use the same deimiter.</p> + +<p>Finally, [[#d_-_Define|d]] pops <code>xpikaclbzlx</code> from the value stack and pushes +<code>lzblcakip</code> onto the procedure stack. +Note that [[#d_-_Define|d]] removes the delimiters from the procedure and reverses the order of its letters +so when you define procedures in literal mode, you need to flip them around.</p> + +<p>Now let's see that the code in the procedure does:</p> +<pre>lzbl ca kip</pre> + +<p>[[#l_-_Literal|l]] toggles between modes so <code>lzbl</code> results in a literal +pushing <code>z</code> and <code>b</code> onto the stack. +[[#c_-_Copy|c]] then pops <code>b</code> from the stack, this is a value of 1 +which means [[#c_-_Copy|c]] copies the next item on the stack, skipping the <code>z</code>. +After [[#c_-_Copy|c]] the stack top of the contains a copy of the initial top of the stack followed by <code>z</code>. +</p> + +<p>[[#a_-_Arithmetic_Operation|a]] then performs an operation on these two. +The operation performed by [[#a_-_Arithmetic_Operation|a]] is determined by the value of the [[#a_-_Operation_Register|a register]]. +The default operation is addition but it will need to be set to equality comparison before the procedure is executed. +If the [[#a_-_Operation_Register|a register]] is set to comparison, [[#a_-_Arithmetic_Operation|a]] will pop the two letters off the top +of the stack and push true (<code>b</code>) or false (<code>a</code>) depending whether they are the same.</p> + +<p>Follows [[#k_-_Keep|k]] which copies the top procedure from the procedure stack, this is requires to prevent +[[#i_-_If|i]] from consuming it since we are looping. +[[#i_-_If|i]] consumes the copied procedure and the result of the comparison, executing the procedure if the +result is true (<code>b</code>). When the procedure is executed, the program halts (this procedure is <code>h</code>, which was defined +at the start. +Finally [[#p_-_Print|p]] pops and prints the top of the stack. This only happens if the condition was false as it means the program +was not halted. +</p> + +<p>Final bit of setup:</p> +<pre>a af xpikacjbzjx jbk ob xhx l d sao d s r</pre> + +<p>Here is the same but there is more data onto the stack and two more instructions. +The second [[#s_-_Set|s]] pops <code>af</code> to set the [[#a_-_Arithmetic_Operation|a]] to equality +comparison mode. Then [[#r_-_Repeat|r]] will pop the remaining <code>a</code> which means it will loop +forever (or in this case until halted.</p> + +<p>Now all that's needed is some data on the stack to be printed, using <code>z</code> as a delimiter +(since it's the value we're comparing against on the procedure).</p> + +<pre>z kcatsehtgnitnirp a af xpikacjbzjx jbk ob xhx l d sao d s r</pre> + +Output: +<pre>printingthestack</pre> + +<h2>Alphabet</h2> + +<p><em>AlphaStack</em> uses the 26 (lower case) letters of the Latin alphabet. +All other characters are ignores, including upper case letters.</p> + +<table class="wikitable"> + <tr><th>Letter</th><th>Numerical</th><th>Instruction</th><th>Register</th><th colspan='3'>Summary</th></tr> + <tr><th>a</th><td class='letterval'>0</td> + <td>[[#a_-_Arithmetic_Operation|Arithmetic Operation]]</td> + <td>[[#a_-_Operation_Register|Operation]]</td> + <td class='summary-col'><span class='operand'>num1</span><span class='operand'>num2</span></td> + <td class='summary-col'><code class='instruction'>a</code></td> + <td class='summary-col'><span class='operand'>num3</span></td></tr> + <tr><th>b</th><td class='letterval'>1</td> + <td>[[#b_-_Break|Break]]</td> + <td></td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>b</code></td> + <td class='summary-col'></td></tr> + <tr><th>c</th><td class='letterval'>2</td> + <td>[[#c_-_Copy|Copy]]</td> + <td></td> + <td class='summary-col'><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>index</span></td> + <td class='summary-col'><code class='instruction'>c</code></td> + <td class='summary-col'><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>val</span></td></tr> + <tr><th>d</th><td class='letterval'>3</td> + <td>[[#d_-_Define|Define]]</td> + <td></td> + <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td> + <td class='summary-col'><code class='instruction'>d</code></td> + <td class='summary-col'></td></tr> + <tr><th>e</th><td class='letterval'>4</td> + <td>[[#e_-_Execute_Specific|Execute Specific]]</td> + <td>[[#e_-_Execute_Index_Register|Execute Index]]</td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>e</code></td> + <td class='summary-col'></td></tr> + <tr><th>f</th><td class='letterval'>5</td> + <td>[[#f_-_Flip|Flip]]</td> + <td></td> + <td class='summary-col'><span class='operand'>...</span><span class='operand'>count</span></td> + <td class='summary-col'><code class='instruction'>f</code></td> + <td class='summary-col'><span class='operand'>...</span></td></tr> + <tr><th>g</th><td class='letterval'>6</td> + <td>[[#g_-_Get|Get]]</td> + <td></td> + <td class='summary-col'><span class='operand'>reg</span></td> + <td class='summary-col'><code class='instruction'>g</code></td> + <td class='summary-col'><span class='operand'>val</span></td></tr> + <tr><th>h</th><td class='letterval'>7</td> + <td>[[#h_-_Halt|Halt]]</td> + <td></td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>h</code></td> + <td class='summary-col'></td></tr> + <tr><th>i</th><td class='letterval'>8</td> + <td>[[#i_-_If|If]]</td> + <td>[[#i_-_If_Else_Count_Register|If Else Count]]</td> + <td class='summary-col'><span class='operand'>valn</span><span class='operand'>...</span><span class='operand'>val0</span></td> + <td class='summary-col'><code class='instruction'>i</code></td> + <td class='summary-col'></td></tr> + <tr><th>j</th><td class='letterval'>9</td> + <td></td> + <td></td> + <td class='summary-col'></td> + <td class='summary-col'></td> + <td class='summary-col'></td></tr> + <tr><th>k</th><td class='letterval'>10</td> + <td>[[#k_-_Keep|Keep]]</td> + <td>[[#k_-_Keep_Count_Register|Keep Count]]</td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>k</code></td> + <td class='summary-col'></td></tr> + <tr><th>l</th><td class='letterval'>11</td> + <td>[[#l_-_Literal|Literal]]</td> + <td>[[#l_-_Mode_Register|Mode]]</td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>l</code></td> + <td class='summary-col'></td></tr> + <tr><th>m</th><td class='letterval'>12</td> + <td>[[#m_-_Memory|Memory]]</td> + <td>[[#m_-_Memory_Cell_Register|Memory Cell]]</td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>m</code></td> + <td class='summary-col'><span class='operand'>val</span></td></tr> + <tr><th>n</th><td class='letterval'>13</td> + <td>[[#n_-_Number_of_Items|Number of Items]]</td> + <td>[[#n_-_Number_Size_Register|Number Size]]</td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>n</code></td> + <td class='summary-col'><span class='operand'>count</span></td></tr> + <tr><th>o</th><td class='letterval'>14</td> + <td>[[#o_-_Overwrite|Overwrite]]</td> + <td>[[#o_-_Keep_Mark_Register|Keep Mark]]</td> + <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span><span class='operand'>search</span><span class='operand'>replace</span></td> + <td class='summary-col'><code class='instruction'>o</code></td> + <td class='summary-col'><span class='operand'>...</span></td></tr> + <tr><th>p</th><td class='letterval'>15</td> + <td>[[#p_-_Print|Print]]</td> + <td>[[#p_-_Print_Mode_Register|Print Mode]]</td> + <td class='summary-col'><span class='operand'>val</span></td> + <td class='summary-col'><code class='instruction'>p</code></td> + <td class='summary-col'></td></tr> + <tr><th>q</th><td class='letterval'>16</td> + <td></td> + <td></td> + <td class='summary-col'></td> + <td class='summary-col'></td> + <td class='summary-col'></td></tr> + <tr><th>r</th><td class='letterval'>17</td> + <td>[[#r_-_Repeat|Repeat]]</td> + <td></td> + <td class='summary-col'><span class='operand'>count</span></td> + <td class='summary-col'><code class='instruction'>r</code></td> + <td class='summary-col'></td></tr> + <tr><th>s</th><td class='letterval'>18</td> + <td>[[#s_-_Set|Set]]</td> + <td></td> + <td class='summary-col'><span class='operand'>reg</span><span class='operand'>val</span></td> + <td class='summary-col'><code class='instruction'>s</code></td> + <td class='summary-col'></td></tr> + <tr><th>t</th><td class='letterval'>19</td> + <td>[[#t_-_Text_Input|Text Input]]</td> + <td>[[#t_-_Read_Result_Register|Read Result]]</td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>t</code></td> + <td class='summary-col'><span class='operand'>val?</span></td></tr> + <tr><th>u</th><td class='letterval'>20</td> + <td>[[#u_-_Undo|Undo]]</td> + <td></td> + <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td> + <td class='summary-col'><code class='instruction'>u</code></td> + <td class='summary-col'></td></tr> + <tr><th>v</th><td class='letterval'>21</td> + <td></td> + <td></td> + <td class='summary-col'></td> + <td class='summary-col'></td> + <td class='summary-col'></td></tr> + <tr><th>w</th><td class='letterval'>22</td> + <td>[[#w_-_Wrap|Wrap]]</td> + <td></td> + <td class='summary-col'><span class='operand'>...</span><span class='operand'>count</span><span class='operand'>steps</span></td> + <td class='summary-col'><code class='instruction'>w</code></td> + <td class='summary-col'><span class='operand'>...</span></td></tr> + <tr><th>x</th><td class='letterval'>23</td> + <td>[[#x_-_Execute|Execute]]</td> + <td></td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>x</code></td> + <td class='summary-col'></td></tr> + <tr><th>y</th><td class='letterval'>24</td> + <td>[[#y_-_Yield|Yield]]</td> + <td></td> + <td class='summary-col'></td> + <td class='summary-col'><code class='instruction'>y</code></td> + <td class='summary-col'></td></tr> + <tr><th>z</th><td class='letterval'>25</td> + <td></td> + <td></td> + <td class='summary-col'></td> + <td class='summary-col'></td> + <td class='summary-col'></td></tr> +</table> + +<h2>Letter Details</h2> + +<h3 id='a-instruction'><span class='instruction'>a</span> - Arithmetic Operation</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>num1</span><span class='operand'>num2</span></td><td><code>a</code></td><td><span class='operand'>num3</span></td></tr></table> +<p>The <span class="instruction">a</span> pops two values from the stack, +performs a mathematical operation on them and pushes the result back onto the stack. +In all cases <code class="operand">num1</code> is the left hand side operand and +<code class="operand">num2</code> is the right hand side operand.</p> + +<p>The specific operation to be performed on the two operands depends on the value of the <span class="instruction">a</span> register.</p> +<h3 id='a-register'><span class='instruction'>a</span> - Operation Register</h3> +<table class="wikitable"> + <tr> + <th>Value</th> + <th>Name</th> + <th>Operation</th> + </tr> + <tr><th class='operand'>a</th><td>Addition</td><td class='operand'>val3 = val1 + val2</td></tr> + <tr><th class='operand'>b</th><td>Subtraction</td><td class='operand'>val3 = val1 - val2</td></tr> + <tr><th class='operand'>c</th><td>Multiplication</td><td class='operand'>val3 = val1 * val2</td></tr> + <tr><th class='operand'>d</th><td>Integer division</td><td class='operand'>val3 = val1 / val2</td></tr> + <tr><th class='operand'>e</th><td>Modulo</td><td class='operand'>val3 = val1 % val2</td></tr> + <tr><th class='operand'>f</th><td>Equality comparison</td><td class='operand'>val3 = val1 == val2</td></tr> + <tr><th class='operand'>g</th><td>Greater than</td><td class='operand'>val3 = val1 &gt; val2</td></tr> + <tr><th class='operand'>h</th><td>Greater or equal</td><td class='operand'>val3 = val1 &gt;= val2</td></tr> + <tr><th class='operand'>i</th><td>Less or equal</td><td class='operand'>val3 = val1 &lt;= val2</td></tr> + <tr><th class='operand'>j</th><td>Less than</td><td class='operand'>val3 = val1 &lt; val2</td></tr> + <tr><th class='operand'>k</th><td>Not equal</td><td class='operand'>val3 = val1 != val2</td></tr> +</table> + +'''Examples''' + +Code: +<pre>cdlap</pre> + +Output: +<pre>f</pre> + +<p>The program starts in literal mode, so <code class="operand">c</code> and <code class="operand">d</code> +are pushed onto the stack as data.<br/> +[[#l_-_Literal|l]] disables literal mode, so [[#a_-_Arithmetic_Operation|a]] is executed as an instruction. It pops <code class="operand">c</code> (2) and <code class="operand">d</code> (3) +from the stack calculates their sum, <code class="operand">f</code> (5), then pushes it onto the stack.<br/> +Finally, [[#p_-_Print|p]] prints the top of the stack to standard output.</p> + +Code: +<pre>czlap</pre> + +Output: +<pre>b</pre> + +<p>This example adds <code class="operand">c</code> (2) and <code class="operand">z</code> (25). Ther output is +<code class="operand">b</code> (1) because math operations are modulo 26.</p> + + +Code: +<pre>cdaclsap</pre> + +Output: +<pre>g</pre> + +<p>This example multiplies <code class="operand">c</code> (2) and <code class="operand">d</code> (3). +This is achieved by setting the [[#a_-_Operation_Register|a register]] to <code class="operand">c</code> using [[#s_-_Set|s]]. +</p> + +<h3 id='b-instruction'><span class='instruction'>b</span> - Break</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>b</code></td><td></td></tr></table> +<p>Breaks out of the current loop. Does not affect the stack.</p> + +'''Example''' + +<p>If we take this starting example:</p> + +<pre>xpkbl a labl c lxl d lal r</pre> + +<p>it will endlessly print <code>a</code>.</p> + +<p>The explanation chunk by chunk:</p> + +<pre>xpkbl a</pre> + +<p>Pushes <code>xpkb</code> onto the stack, then calls [[#a_-_Arithmetic_Operation|a]] to add <code>b</code> and <code>k</code> to obtain <code>l</code> since <code>l</code> +can't be pushed onto the stack directly, obtaining <code>xpl</code>.</p> + +<pre>labl c</pre> +<p>Pushes <code>a</code> and copies the <code>l</code> with [[#c_-_Copy|c]] resulting with the stack <code>xplal</code>.</p> + +<pre>lxl d</pre> +<p>Pushes <code>x</code> as a marker, then [[#d_-_Define|d]] rolls the stack betwen the two +<code>x</code> markers into a procedure. Note that the procedure will be reversed compared to the other of the stack. +The procedure will be pushed into the procedure stack as <code>lalp</code>.</p> + +<pre>lal r</pre> +<p>Pushes <code>a</code> onto the stack to create an infinite loop with [[#r_-_Repeat|r]], which +will pop the created procedure and loop it indefinitely. The procedure just prints <code>a</code> every time. +</p> + +If we add a break to the procedure the loop will stop after the first iteration: + +<pre>xbpkbl a labl c lxl d lal r</pre> + +Output: +<pre>a</pre> + +<h3 id='c-instruction'><span class='instruction'>c</span> - Copy</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>index</span></td><td><code class='instruction'>c</code></td><td><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>val</span></td></tr></table> +<p>Copies a value <code class="operand">index</code> positions into the stack.</p> + +<p>It pops <code class="operand">index</code>, looks into the stack from the top +that many spaces, and pushes a copy of the corresponding value on top of the stack.</p> + +'''Example''' + +<pre>somedatafl c</pre> + +<p>This pushes <code>somedataf</code> onto the stack then executes [[#c_-_Copy|c]]. +It will pop <code>f</code> (5), then look that many spaces down the remaining stack, find +<code>m</code> and copy it on top of the stack. This results in a stack of <code>somedatam</code>. +</p> + +<h3 id='d-instruction'><span class='instruction'>d</span> - Define</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td><td><code class='instruction'>d</code></td><td></td></tr></table> +<p>Defines a procedure delimited by <code class="operand">mark</code> and pushes it on the procedure stack.</p> + +<p>It pops the first stack value, <code class="operand">mark</code> which can be anything, then keeps popping +until another value equal to <code class="operand">mark</code> is found (or the stack is empty).</p> + +<p>The result is then pushed onto the procedure stack, with the values flipped compared to how they were in the initial stack. +The flip happens because values are pushed onto the procedure as they are popped from the stack.</p> + + +'''Example''' + +This example uses a procedure and a loop to print the contents of the stack until a delimiter (<code>z</code>) is reached. + +Code: +<pre>zerudecorp a af xpikacjbzjx jbk xhx ob l sdaodsr</pre> + +Output: +<pre>procedure</pre> + +<p>Before the [[#l_-_Literal|l]] all the letter are pushed onto the stack. then the following operations are performed:</p> + +<p>[[#s_-_Set|s]] pops <code>ob</code> and sets the [[#o_-_Keep_Mark_Register|o register]] is set to keep the delimiter.</p> +<p>[[#d_-_Define|d]] pops <code>xhx</code> and pushes <code>h</code> as a procedure. +Here we are using <code>x</code> as a delimiter but any letter works as delimiter, just ensure it isn't used with the procedure itself. +</p> +<p>[[#a_-_Arithmetic_Operation|a]] pops <code>bk</code>, adds them, and pushes <code>l</code> (this is because <code>l</code> cannot be used as a literal).</p> +<p>[[#o_-_Overwrite|o]] pops <code>jl</code> and preforms a replacement from <code>j</code> to <code>l</code>. +using <code>x</code> as delimiter. Results in changing the top of the stack from +<code>xpikacjbzjx</code> to <code>xpikaclbzlx</code>. The <code>x</code> delimiters are preserved due to the value of +[[#o_-_Keep_Mark_Register|o register]] that was set previously. +</p> +<p>[[#d_-_Define|d]] pops <code>xpikaclbzlx</code> and pushes <code>lzblcakip</code> as a procedure.</p> +<p>[[#s_-_Set|s]] pops <code>af</code> and sets the [[#a_-_Operation_Register|a register]] to perform equality comparison.</p> +<p>[[#r_-_Repeat|r]] pops <code>a</code> and performs the last procedure indefinitely.</p> + +The code in the procedure does the following: +<pre>lzbl c akip</pre> + +<p><code>lzbl</code> pushes <code>zb</code> onto the stack.</p> +<p>[[#c_-_Copy|c]] pops <code>b</code> and copies the item below the head of the stack back on top. +This copies the value set at the start of the main code +</p> +<p>[[#a_-_Arithmetic_Operation|a]] pops the copied value and <code>b</code> from the stack pushing <code>b</code> (true) +or <code>a</code> (false) based on their comparison (because [[#a_-_Operation_Register|a register]] is set to comparison.</p> +<p>[[#k_-_Keep|k]] duplicates the top procedure. +Note that [[#r_-_Repeat|r]] pops the procedure before looping so the top procedure is now <code>h</code>.</p> +<p>[[#i_-_If|i]] pops the value left by [[#a_-_Arithmetic_Operation|a]] and the procedure duplicated by [[#k_-_Keep|k]]. +If the result of the comparison is true, (the letter copied by [[#c_-_Copy|c]] is <code>z</code>), it will call the procedure +which in turns halts the program using [[#h_-_Halt|h]]. +If the condition is not true nothing else happens.</p> +<p>[[#p_-_Print|p]] pops the top of the stack and prints it. This causes the stack size to decrease by one.</p> +<p>After this [[#r_-_Repeat|r]] keeps repeating the procedure, which has the effect of printing the stack +until the character <code>z</code> is reached.</p> + +<h3 id='e-instruction'><span class='instruction'>e</span> - Execute Specific</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>e</code></td><td></td></tr></table> +<p>Executes a specific procedure based on [[#e_-_Execute_Index_Register|e register]], not affecting any of the stacks.</p> + +<p>This is handy to repeatedly calling a procedure without having to modify stack values.</p> + +<h3 id='e-register'><span class='instruction'>e</span> - Execute Index Register</h3> <p>Procedure index for [[#e_-_Execute_Specific|e]]. A value of <code>a</code> (0), which is the default +means the first procedure.<p> + +<p>This index is counted from the bottom of the procedure stack.</p> + +'''Example''' + +Code: +<pre>tset xqx xax xpx xhx eb l s dddd eeee</pre> + +Output: +<pre>test</pre> + +<p>Values are pushed onto the stack until [[#l_-_Literal|l]].</p> +<p>[[#s_-_Set|s]] pops <code>eb</code> and sets the [[#e_-_Execute_Index_Register|e register]] is set to <code>b</code> (1).</p> +<p>[[#d_-_Define|d]] is called 4 times and it defines procedures based on the <code>x</code> delimiter. +After this the procedure stack has these procedures: <code>h</code>, <code>p</code>, <code>a</code>, <code>q</code>. +</p> +<p>[[#e_-_Execute_Specific|e]] is called 4 times as well, each time executing the procedure at index 1, which just prints the top of the stack. +Note that any procedure defined after the one with the given index doesn't matter as [[#e_-_Execute_Index_Register|e register]] refers to indices +starting from the bottom of the procedure stack.</p> + + +<h3 id='f-instruction'><span class='instruction'>f</span> - Flip</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>...</span><span class='operand'>count</span></td><td><code class='instruction'>f</code></td><td><span class='operand'>...</span></td></tr></table> +<p>Reverses the order of <code class="operand">count</code> items on the top of the stack.</p> + +<p>Pops <code class="operand">count</code>, then pops that many other items off the top of the stack +and pushes them back onto the stack but in reverse order.</p> + +'''Example''' + +Code: +<pre>foobar d l f</pre> + +<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>foobard</code>.</p> +<p>[[#f_-_Flip|f]] pops <code>d</code> (3), then flips the next 3 items on the stack, resulting with a stack of <code>foorab</code>.</p> + + +<h3 id='g-instruction'><span class='instruction'>g</span> - Get</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>reg</span></td><td><code class='instruction'>g</code></td><td><span class='operand'>val</span></td></tr></table> +<p>Pops <code class="operand">reg</code> from the stack, then pushes the value of the corresponding register onto the stack.</p> + +'''Example''' + +Code: +<pre>m mf l s g</pre> +<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>mmf</code>.</p> +<p>[[#s_-_Set|s]] pops <code>mf</code> and sets the [[#m_-_Memory_Cell_Register|m register]] to <code>f</code>.</p> +<p>[[#g_-_Get|g]] pops <code>m</code> and pushes its value (<code>f</code>) onto the stack, resulting in a stack with <code>f</code>.</p> + +<h3 id='h-instruction'><span class='instruction'>h</span> - Halt</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>h</code></td><td></td></tr></table> +<p>Halts execution, without affecting the stack.</p> + +'''Example''' + +Code: +<pre>abcd l p p h p p</pre> + +Output: +<pre>dc</pre> + +<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>abcd</code>.</p> +<p>[[#p_-_Print|p]] is called twice popping <code>d</code> and <code>c</code> off the stack and printing them.</p> +<p>[[#h_-_Halt|h]] halts execution so the remaining [[#p_-_Print|p]] calls are not executed.</p> + +<h3 id='i-instruction'><span class='instruction'>i</span> - If</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>valn</span><span class='operand'>...</span><span class='operand'>val0</span></td><td><code class='instruction'>i</code></td><td></td></tr></table> +<p>Pops the top value from the stack and the top procedure off the top of the procedure stack. +If the value is true (anything but <code>a</code>), the procedure is then executed.</p> + +<p>The value of the [[#i_-_If_Else_Count_Register|i register]] defines if-else chain, [[#i_-_If|i]] will pop enough values and procedure to satisfy that many conditions.</p> + + +<h3 id='i-register'><span class='instruction'>i</span> - If Else Count Register</h3> <p>Determines how many if-else chains are present (if any).</p> +<p>The default value of <code>a</code> (0), indicates there is no else to execute. +[[#i_-_If|i]] will pop a single value and procedure.</p> +<p>A value of <code>b</code>, indicates an else procedure. +[[#i_-_If|i]] will pop one value and two procedures, the second procedure +being executed if the condition is not true.</p> +<p>For higher values of the [[#i_-_If_Else_Count_Register|i register]], [[#i_-_If|i]] will +pop additional values off the stack and procedures, executing the procedure of the first +matching condition (or the last procedure if no conditions match).</p> + +'''Examples''' + +Code: +<pre>z xjajx yjkb l ao d t i p</pre> + +<p>Output: <code>a</code> or <code>z</code> based on user input.</p> + +<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>zxjajxyjkb</code>.</p> +<p>[[#a_-_Arithmetic_Operation|a]] pops <code>bk</code>, adds them, and pushes <code>l</code> (this is because <code>l</code> cannot be used as a literal).</p> +<p>[[#o_-_Overwrite|o]] pops <code>yjl</code> and preforms a replacement from <code>j</code> to <code>l</code> +until the end of the stack since there are no other <code>y</code> values on the stack. +All this results with a stack of <code>zxlalx</code>.</p> +<p>[[#d_-_Define|d]] pops <code>xlalx</code> and pushes <code>lal</code> as a procedure. This procedure just pushes <code>a</code> onto the stack.</p> +<p>[[#t_-_Text_Input|t]] reads a character from the user, converts it into a letter, and pushes it onto the stack.</p> +<p>[[#i_-_If|i]] pops this user-generated value, the procedure, and if the value is true, the procedure is executed. +Now the stack is either <code>z</code> or <code>za</code>.</p> +<p>[[#p_-_Print|p]] pops the top of the stack and prints it, printing <code>a</code> if +the user input evaluated as true, and <code>z</code> otherwise.</p> + +Code: +<pre>xjajx xjzjx yjkb ib l s ao dd t i p</pre> + +<p>This example has the same output as the previous one but it works slightly differently.</p> +<p>The first operation after exiting literal mode is [[#s_-_Set|s]] to set [[#i_-_If_Else_Count_Register|i register]] to <code>b</code> (1). +This indicates that [[#i_-_If_Else_Count_Register|i register]] should use an else procedure.</p> +<p>Now the next difference is that there are two procedures in the procedure stack: <code>lzl</code> and <code>lal</code>, +wich just push <code>z</code> or <code>a</code> onto the value stack. +Note that <code>lal</code> is the procedure on top of the stack because it has been pushed last.</p> +<p>[[#i_-_If|i]] now pops both procedures off the procedure stack, executing the first on true and the second on false.</p> + +Code: +<pre>xjajx xjbjx xjcjx yjkb ic l s ao ddd tt lclf i p</pre> + +<p>This example takes 2 inputs from the user and selects one of 3 procedures to execute.</p> +<p><code>tt</code> will read 2 inputs from the user and push them onto the stack. +since this will cause the inputs to be in reverse order (the last input is on top of the stack) +<code>lclf</code> uses [[#f_-_Flip|f]] to flip them back around. Now the first +input is on top of the stack and the second input below it.</p> +<p>The [[#i_-_If_Else_Count_Register|i register]] is set to <code>c</code> (2), indicating an else-if chain.</p> +<p>[[#i_-_If|i]] now pops 2 values off the value stack and 3 procedures. +It uses the first value from the stack as the first condition, if that is true the first procedure is executed. +Otherwise, if the next value is true, the second procedure is executed. +Finally, if both values are false, the third procedure is executed. +</p> + +<h3 id='k-instruction'><span class='instruction'>k</span> - Keep</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>k</code></td><td></td></tr></table> +<p>Duplicates the procedure on top of the procedure stack.</p> + +<p>This is useful if you want to run [[#i_-_If|i]] or [[#x_-_Execute|x]] while keeping the procedure on the stack for later use.</p> + +<h3 id='k-register'><span class='instruction'>k</span> - Keep Count Register</h3> <p>Determines the number of procedures [[#k_-_Keep|k]] will copy. +The number is the value of this register plus one.</p> + +'''Example''' + +Code: +<pre>xpppjfoojx yjkb l ao d kxx</pre> + +Output: +<pre>foofoo</pre> + +<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>xpppjfoojxyjkb</code>.</p> +<p>[[#a_-_Arithmetic_Operation|a]] and [[#o_-_Overwrite|o]] ensure <code>j</code> values on the stack are replaced by <code>l</code> as +<code>l</code> cannot be used as a literal. The stack after them is <code>xppplfoolx</code></p> +<p>[[#d_-_Define|d]] defines the procedure <code>looflppp</code>, which prints the string "foo" to output.</p> + +<p>Finally [[#k_-_Keep|k]] duplicates this procedure, and [[#x_-_Execute|x]] is called twice, popping and +executing the two copies of the procedure.</p> + +<h3 id='l-instruction'><span class='instruction'>l</span> - Literal</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>l</code></td><td></td></tr></table> +<p>Switches between literal and instruction modes.</p> +<p>Specifically it toggles the [[#l_-_Literal|l]] register between +<code>a</code> (0), which indicated literal mode, and <code>b</code> (1), instruction mode.</p> + +<p>While in instruction mode all letters are executed as an instruction.</p> +<p>In literal mode (which is the mode at the start of execution) letters are +pushed onto the value stack.</p> + +<p>[[#l_-_Literal|l]] will keep its behaviour in both modes so the letter <code>l</code> +cannot appear directly as a literal.</p> + +<h3 id='l-register'><span class='instruction'>l</span> - Mode Register</h3> <p>Determines whether the program is in literal mode or instruction mode.</p> + +<p>A value of <code>a</code> indicates literal mode, any other value is instruction mode.</p> + +<p>Generally it's toggled with [[#l_-_Literal|l]] but setting a value explicitly +using [[#s_-_Set|s]] will also switch between modes.</p> + +'''Example''' + +Code: +<pre>oof l ppp lrabl ppp</pre> + +Output: +<pre>foobar</pre> + +<p><code>oof</code> are pushed onto the stack because the program starts in literal mode.</p> +<p>[[#l_-_Literal|l]] enables instruction mode and [[#p_-_Print|p]] is called 3 times +to print <code>foo</code> from the stack to the output.</p> +<p>In <code>lrabl</code> literal mode is entered again to push <code>rab</code> +onto the stack, the last [[#l_-_Literal|l]] goes back into instruction mode.</p> +<p>Finally [[#p_-_Print|p]] is called again to print <code>bar</code>.</p> + +'''Adding <code class="instruction">l</code> onto the stack''' + +<p>Since [[#l_-_Literal|l]] ends literal mode, values of <code>l</code> +cannot be directly added onto the stack, but some easy work-arounds are available.</p> + +<p>The most basic is to use addition to get an <code>l</code> from other values:</p> + +<pre>kb l a</pre> +<p>Here [[#a_-_Arithmetic_Operation|a]] pops <code>k</code> and <code>b</code> from the stack, +adds them together, and pushes <code>l</code> (the result of this addition) back onto the stack.</p> + +<p>Sometimes you might want multiple <code>l</code> on the stack, this is especially useful when +defining procedures that need to output literal values on the stack. +You can achieve this by combining the previous approach with the overwrite instruction ([[#l_-_Literal|l]]):</p> + +<pre>jjj x jjj x j bk l ao</pre> +<p>Here [[#a_-_Arithmetic_Operation|a]] does the same as it did before, replacing <code>bk</code> with <code>l</code>.</p> +<p>[[#o_-_Overwrite|o]] pops <code>xjl</code>. It preforms a replacement from <code>j</code> to <code>l</code> +using <code>x</code> as delimiter. Both instances of the delimiter are removed from the stack.</p> +<p>At the end the stack will be <code>jjjlll</code>, the first the <code>j</code> not being replaced because found +after the delimiter when searching from the top of the stack.</p> + +<h3 id='m-instruction'><span class='instruction'>m</span> - Memory</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>m</code></td><td><span class='operand'>val</span></td></tr></table> +<p>Pushes the value of the [[#m_-_Memory_Cell_Register|m register]] onto the stack.</p> +<p>This can be useful if there is a value that needs to be pushed onto the stack multiple time.</p> + +<h3 id='m-register'><span class='instruction'>m</span> - Memory Cell Register</h3> <p>Doesn't have any special meaning, pushed onto the stack by [[#m_-_Memory|m]].</p> + +'''Examples''' + +Code: +<pre>lmmmppp</pre> + +Output: +<pre>aaa</pre> + +<p>[[#l_-_Literal|l]] enables instruction mode.</p> +<p>[[#m_-_Memory|m]] is called 3 times and pushes the default value (<code>a</code>) onto the stack each time.</p> +<p>[[#p_-_Print|p]] is called 3 times, popping the 3 values and printing them.</p> + +Code: +<pre>mz l s mmmppp</pre> + +Output: +<pre>zzz</pre> + +<p>Same as before but [[#s_-_Set|s]] uses the <code>z</code> and <code>m</code> values +from the stack to set the [[#m_-_Memory_Cell_Register|m register]] to <code>z</code>.</p> + +<h3 id='n-instruction'><span class='instruction'>n</span> - Number of Items</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>n</code></td><td><span class='operand'>count</span></td></tr></table> +<p>Pushed onto the stack the number of items currently on the stack</p> + +<h3 id='n-register'><span class='instruction'>n</span> - Number Size Register</h3> + +<p>Number of letters per number, see [[Multi-Letter_Numbers|multi-letter numbers]] in advanced concepts.</p> + +'''Examples''' + +Code: +<pre>foobar l nf</pre> + +<p><code>foobar</code> is pushed onto the stack, then [[#n_-_Number_of_Items|n]] pushes +the stack count <code>g</code> (6) onto the stack. +Finally [[#f_-_Flip|f]] pops that value and flips the whole stack.</p> + +Code: +<pre>foobar xpx l d n f n r</pre> + +Output: +<pre>foobar</pre> + +<p><code>foobarxpx</code> is pushed onto the value stack, then [[#d_-_Define|d]] pops <code>xpx</code> to push <code>p</code> on the procedure stack.</p> +<p>As before [[#n_-_Number_of_Items|n]] followed by [[#f_-_Flip|f]] flips the entire stack. +Finally [[#n_-_Number_of_Items|n]] followed by [[#r_-_Repeat|r]] repeats the print +procedure for each item on the stack.</p> + +<p>Note that this works up to a value of <code>z</code> (25).</p> + +<h3 id='o-instruction'><span class='instruction'>o</span> - Overwrite</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span><span class='operand'>search</span><span class='operand'>replace</span></td><td><code class='instruction'>o</code></td><td><span class='operand'>...</span></td></tr></table> +<p>Replaces values on the stack until a delimiter is reached.</p> + +<p>Pops <code>replace</code> and <code>search</code> from the stack. +Then replaces all instanced of <code>search</code> between the two <code>mark</code> +with <code>replace</code>.</p> + +<p>If the second <code>mark</code> is not found, all occurrences of <code>search</code> will be replaced.</p> + +<p>The two <code>mark</code> are removed from the stack by default but they can be preserved +depending on the value of the [[#o_-_Keep_Mark_Register|o register]].</p> + +<h3 id='o-register'><span class='instruction'>o</span> - Keep Mark Register</h3> <p>By default [[#o_-_Overwrite|o]] deleted the markers from the stack, if this +register has a value other than <code>a</code>, they are kept.</p> + +'''Example''' + +Code: +<pre>test x test x t b l o</pre> + +<p>All the values until [[#l_-_Literal|l]] are pushed onto the stack.</p> +<p>[[#o_-_Overwrite|o]] pops <code>xtb</code> from the stack, and replaces +all <code>t</code> into <code>b</code> until the next <code>x</code> is found.</p> +<p>This results in the stack ending with <code>testbesb</code>.</p> +<p>Note that the value <code>x</code> is arbitrary, any letter can work as a marker.</p> + + +Code: +<pre>test x test x t b ob l s o</pre> + +<p>Similar as before, now [[#s_-_Set|s]] pops <code>ob</code> +and sets the [[#o_-_Keep_Mark_Register|o register]] to <code>b</code>.</p> + +<p>The rest works the same except the markers are kept, resulting in <code>testxbesbx</code>.</p> + +<h3 id='p-instruction'><span class='instruction'>p</span> - Print</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>val</span></td><td><code class='instruction'>p</code></td><td></td></tr></table> +<p>Pops a letter from the stack and prints it to output.</p> + +<p>By default prints them as lower case letters but this can changed based on the value of the [[#p_-_Print_Mode_Register|p register]].</p> + +<h3 id='p-register'><span class='instruction'>p</span> - Print Mode Register</h3> <p>Specifies the print mode, depending on the mode letters are printed differently.</p> +<p>Using the right combination of printed letter and mode, any ASCII character can be printed.</p> + +<table class="wikitable print-mode mono"> + <caption>Print Modes</caption> + <tr><th rowspan="2">Letter</th><th colspan="5">Mode</th></tr> + <tr><th>a</th> <th>b</th> <th>c</th> <th>d</th> <th>e</th></tr> + <tr><th>a</th><td class='print-mode'>a</td><td class='print-mode'>A</td><td class='print-mode'>0</td><td class='print-mode'>!</td><td class='print-mode'>NUL</td></tr> + <tr><th>b</th><td class='print-mode'>b</td><td class='print-mode'>B</td><td class='print-mode'>1</td><td class='print-mode'>&quot;</td><td class='print-mode'>x01</td></tr> + <tr><th>c</th><td class='print-mode'>c</td><td class='print-mode'>C</td><td class='print-mode'>2</td><td class='print-mode'>#</td><td class='print-mode'>x02</td></tr> + <tr><th>d</th><td class='print-mode'>d</td><td class='print-mode'>D</td><td class='print-mode'>3</td><td class='print-mode'>$</td><td class='print-mode'>x03</td></tr> + <tr><th>e</th><td class='print-mode'>e</td><td class='print-mode'>E</td><td class='print-mode'>4</td><td class='print-mode'>%</td><td class='print-mode'>x04</td></tr> + <tr><th>f</th><td class='print-mode'>f</td><td class='print-mode'>F</td><td class='print-mode'>5</td><td class='print-mode'>&amp;</td><td class='print-mode'>x05</td></tr> + <tr><th>g</th><td class='print-mode'>g</td><td class='print-mode'>G</td><td class='print-mode'>6</td><td class='print-mode'>&apos;</td><td class='print-mode'>x06</td></tr> + <tr><th>h</th><td class='print-mode'>h</td><td class='print-mode'>H</td><td class='print-mode'>7</td><td class='print-mode'>(</td><td class='print-mode'>x07</td></tr> + <tr><th>i</th><td class='print-mode'>i</td><td class='print-mode'>I</td><td class='print-mode'>8</td><td class='print-mode'>)</td><td class='print-mode'>x08</td></tr> + <tr><th>j</th><td class='print-mode'>j</td><td class='print-mode'>J</td><td class='print-mode'>9</td><td class='print-mode'>*</td><td class='print-mode'>HT</td></tr> + <tr><th>k</th><td class='print-mode'>k</td><td class='print-mode'>K</td><td class='print-mode'>:</td><td class='print-mode'>+</td><td class='print-mode'>LF</td></tr> + <tr><th>l</th><td class='print-mode'>l</td><td class='print-mode'>L</td><td class='print-mode'>;</td><td class='print-mode'>,</td><td class='print-mode'>x0b</td></tr> + <tr><th>m</th><td class='print-mode'>m</td><td class='print-mode'>M</td><td class='print-mode'>&lt;</td><td class='print-mode'>-</td><td class='print-mode'>x0c</td></tr> + <tr><th>n</th><td class='print-mode'>n</td><td class='print-mode'>N</td><td class='print-mode'>=</td><td class='print-mode'>.</td><td class='print-mode'>CR</td></tr> + <tr><th>o</th><td class='print-mode'>o</td><td class='print-mode'>O</td><td class='print-mode'>&gt;</td><td class='print-mode'>/</td><td class='print-mode'>x0e</td></tr> + <tr><th>p</th><td class='print-mode'>p</td><td class='print-mode'>P</td><td class='print-mode'>?</td><td class='print-mode'>@</td><td class='print-mode'>x0f</td></tr> + <tr><th>q</th><td class='print-mode'>q</td><td class='print-mode'>Q</td><td class='print-mode'>x1a</td><td class='print-mode'>[</td><td class='print-mode'>x10</td></tr> + <tr><th>r</th><td class='print-mode'>r</td><td class='print-mode'>R</td><td class='print-mode'>ESC</td><td class='print-mode'>\</td><td class='print-mode'>x11</td></tr> + <tr><th>s</th><td class='print-mode'>s</td><td class='print-mode'>S</td><td class='print-mode'>x1c</td><td class='print-mode'>]</td><td class='print-mode'>x12</td></tr> + <tr><th>t</th><td class='print-mode'>t</td><td class='print-mode'>T</td><td class='print-mode'>x1d</td><td class='print-mode'>^</td><td class='print-mode'>x13</td></tr> + <tr><th>u</th><td class='print-mode'>u</td><td class='print-mode'>U</td><td class='print-mode'>x1e</td><td class='print-mode'>_</td><td class='print-mode'>x14</td></tr> + <tr><th>v</th><td class='print-mode'>v</td><td class='print-mode'>V</td><td class='print-mode'>x1f</td><td class='print-mode'>`</td><td class='print-mode'>x15</td></tr> + <tr><th>w</th><td class='print-mode'>w</td><td class='print-mode'>W</td><td class='print-mode'>SP</td><td class='print-mode'>{</td><td class='print-mode'>x16</td></tr> + <tr><th>x</th><td class='print-mode'>x</td><td class='print-mode'>X</td><td class='print-mode'>x7f</td><td class='print-mode'>|</td><td class='print-mode'>x17</td></tr> + <tr><th>y</th><td class='print-mode'>y</td><td class='print-mode'>Y</td><td class='print-mode'></td><td class='print-mode'>}</td><td class='print-mode'>x18</td></tr> + <tr><th>z</th><td class='print-mode'>z</td><td class='print-mode'>Z</td><td class='print-mode'></td><td class='print-mode'>~</td><td class='print-mode'>x19</td></tr> </table> + +<p>The special mode <code>z</code> will cause [[#p_-_Print_Mode_Register|p register]] to not +print anything turning it into a pop operation.</p> + +'''Examples''' + +Code: +<pre>tnirp l ppppp</pre> + +Output: +<pre>print</pre> + +<p>All the values until [[#l_-_Literal|l]] are pushed onto the stack +then [[#p_-_Print_Mode_Register|p register]] is called multiple times, each time +it pops a value off the stack and prints it.</p> +<p>Note that since [[#p_-_Print_Mode_Register|p register]] prints off the top of the stack, +the stack values need to be in reverse order to be printed.</p> + +Code: +<pre>tnirp pb l s ppppp</pre> + +Output: +<pre>PRINT</pre> + +<p>Similar as before, now [[#s_-_Set|s]] pops <code>pb</code> +and sets the [[#p_-_Print_Mode_Register|p register]] to <code>b</code>, switching to uppercase print mode.</p> + +Code: +<pre>hddb pc l s pppp</pre> + +Output: +<pre>1337</pre> + +<p>Print mode <code>c</code> can be used to print numbers.</p> + +Code: +<pre>tnirp pz l s ppppp</pre> + +(No Output) + +<p>Print mode <code>z</code> can be used to pop values off the stack without printing them.</p> + +Code: +<pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre> + +Output: +<pre>Hello World!</pre> + +<p>Does the usual trick to replace <code>l</code> (see [[#l_-_Literal|l]] examples). +Then keeps switching print modes and printing values from the stack.</p> + +<h3 id='r-instruction'><span class='instruction'>r</span> - Repeat</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>count</span></td><td><code class='instruction'>r</code></td><td></td></tr></table> +<p>Pops <code>count</code> and the top procedure from the procedure stack and executes +said procedure <code>count</code> times. A count of <code>a</code> (0) means infinite loop.</p> + +'''Example''' + +Code: +<pre>tset e xpx l dr</pre> + +Output: +<pre>test</pre> + +<p>After [[#l_-_Literal|l]] the stack contains <code>tsetexpx</code>.</p> +<p>[[#d_-_Define|d]] pops <code>xpx</code> from the value stack and pushes <code>p</code> on the procedure stack.</code> +<p>[[#r_-_Repeat|r]] pops <code>e</code> (4) from the value stack, +the procedure from the procedure stack and repeats it 4 times, printing the 4 remaining letters on the stack.</p> + +<h3 id='s-instruction'><span class='instruction'>s</span> - Set</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>reg</span><span class='operand'>val</span></td><td><code class='instruction'>s</code></td><td></td></tr></table> +<p>Pops <code class="operand">reg</code> and <code class="operand">val</code> from the stack, +then sets the corresponding register to <code class="operand">val</code>.</p> + +'''Example''' + +Code: +<pre>m mf l s g</pre> +<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>mmf</code>.</p> +<p>[[#s_-_Set|s]] pops <code>mf</code> and sets the [[#m_-_Memory_Cell_Register|m register]] to <code>f</code>.</p> +<p>[[#g_-_Get|g]] pops <code>m</code> and pushes its value (<code>f</code>) onto the stack, resulting in a stack with <code>f</code>.</p> + + +<h3 id='t-instruction'><span class='instruction'>t</span> - Text Input</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>t</code></td><td><span class='operand'>val?</span></td></tr></table> +<p>Pushes a letter onto the stack based on user input.</p> + +<p>Reads one character from the input stream, converts into a +letter using the reverse operation of [[#p_-_Print|p]] and sets the [[#t_-_Read_Result_Register|t register]] to the print mode that would +yield that character.</p> + +<p>On failure (end of file or invalid character) it sets the +[[#t_-_Read_Result_Register|t register]] to <code>z</code> and doesn't push anything +onto the stack.</p> + +<h3 id='t-register'><span class='instruction'>t</span> - Read Result Register</h3> <p>Holds the status of the last [[#t_-_Text_Input|t]] operation. +Basically if you want to print back the same character you need to set +the [[#p_-_Print_Mode_Register|p register]] to the value of the [[#t_-_Read_Result_Register|t register]]. +The special value of <code>z</code> indicates an error. +Refer to the documentation of the [[#p_-_Print_Mode_Register|p register]] for a description of values.</p> + +'''Example''' + +Code: +<pre>lt</pre> + +<p>[[#l_-_Literal|l]] exits literal mode, then [[#t_-_Text_Input|t]] reads one character +from input. Follow a few examples of the end state based on the input.</p> + +<p>If the user typed <code>h</code>, the [[#t_-_Read_Result_Register|t register]] holds the value <code>a</code> and +the stack the value <code>h</code>.</p> + +<p>If the user typed <code>H</code>, the stack still holds the value <code>h</code> +but now the [[#t_-_Read_Result_Register|t register]] has the value <code>b</code> which corresponds to the +upper case print mode.</p> + +<p>If the user typed <code>3</code>, the stack still holds the value <code>d</code> +but now the [[#t_-_Read_Result_Register|t register]] has the value <code>c</code> which corresponds to the +number print mode.</p> + +<p>If the input reached end of file, the [[#t_-_Read_Result_Register|t register]] will have the value <code>z</code> +and the stack will be empty.</p> + +<h3 id='u-instruction'><span class='instruction'>u</span> - Undo</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td><td><code class='instruction'>u</code></td><td></td></tr></table> +<p>Pops everything on the stack until <code>mark</code> is found.</p> + +<p>Starts by popping <code>mark</code>, that can be any letter. +Then it keeps popping until it finds another value of <code>mark</code> +or the stack is empty.</p> + +'''Example''' + +Code: +<pre>foobartest l u</pre> + +<p>Before [[#u_-_Undo|u]] is executed, the stack contains <code>foobartest</code>.</p> +<p>[[#u_-_Undo|u]] pops a <code>t</code> then keeps popping until the following +<code>t</code> is popped, then stops. At the end the stack holds <code>foobar</code></p> + +<h3 id='w-instruction'><span class='instruction'>w</span> - Wrap</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td><span class='operand'>...</span><span class='operand'>count</span><span class='operand'>steps</span></td><td><code class='instruction'>w</code></td><td><span class='operand'>...</span></td></tr></table> +<p>Wraps the top <code>count</code> items of the stack by <code>steps</code> steps.</p> + +<p>Starts by popping <code>count</code> and <code>steps</code> from the value stack. +Then it pops <code>count</code> more items, which will be the operands of the wrap operation.</p> + +<p>A wrap step consists on moving the first operand to the back of the list of operands. +This is applied <code>steps</code> times.</p> + +<p>After all the steps, the operands are pushed back onto the stack in their new order.</p> + +'''Examples''' + +Code: +<pre>foobar db l w</pre> + +<p>Here [[#w_-_Wrap|w]] performs <code>b</code> (1) step on +the top <code>d</code> items, which are <code>bar</code>. +This turns <code>bar</code> into <code>rba</code> as the <code>r</code> +is moved to the back.</p> + +<p>At the end the stack contains <code>foorba</code>.</p> + +Code: +<pre>foobar dc l w</pre> + +<p>The only change is the number of steps, resulting in a stack with <code>fooarb</code>.</p> + +<h3 id='x-instruction'><span class='instruction'>x</span> - Execute</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>x</code></td><td></td></tr></table> +<p>Pops and executes the top procedure.</p> + +'''Example''' + +Code: +<pre>abc qppq l d x p</pre> + +Output: +<pre>cba</pre> + +<p>After [[#l_-_Literal|l]] the stack contains <code>abcqppq</code>.</p> +<p>[[#d_-_Define|d]] pops <code>qppq</code> and pushes <code>pp</code> +onto the procedure stack.</p> +<p>[[#x_-_Execute|x]] pops this procedure and executes it. +the procedure calls [[#p_-_Print|p]] twice printing <code>cb</code>.</p> +<p>Finally execution continues after [[#x_-_Execute|x]], where an additional +call to [[#p_-_Print|p]] prints <code>a</code>.</p> + + +<h3 id='y-instruction'><span class='instruction'>y</span> - Yield</h3> + +'''Synopsis''' + +<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>y</code></td><td></td></tr></table> +<p>Stops execution of the current procedure, leaving the stack unchanged</p> + +'''Example''' + +Code: +<pre>abc qpypq l d x p</pre> + +Output: +<pre>cb</pre> + +<p>This is the same as the example for [[#x_-_Execute|x]] with the exception of the presence of [[#y_-_Yield|y]] in the middle of the procedure, which causes the second [[#p_-_Print|p]] to not be executed.</p> + +<h2>Advanced Concept</h2> + +<h3 id="multi-letter-numbers">Multi-Letter Numbers</h3> + +<p>By default each letter represents a number in base 26. +Sometimes values between 0 and 25 are not enough. +You can enable a mode that uses multiple letters per number by setting the [[#n_-_Number_Size_Register|n register]] to +a higher value, the number of letters per numer is [[#n_-_Number_of_Items|n]] + 1.</p> + +<p>This affects the condition inputs for [[#i_-_If|i]], the output of [[#n_-_Number_of_Items|n]], and +both inputs and outputs of [[#a_-_Arithmetic_Operation|a]].</p> + +<p>When multi-number letters are used, the most significant letter is on the stack. +For example if the stack contains <code>te</code> (<code>e</code> being at the top of the stack) +and there are 2 letters per number ([[#n_-_Number_Size_Register|n register]] set to <code>b</code>), +The numerical value is calculated as <code>26 * e + t</code>, with all numbers <code>26 * 4 + 19</code>, which is 123.</p> + +<h2>External Links</h2> + +* [https://dragon.best/alphastack/#playground web-based playground] +* [https://gitlab.com/mattia.basaglia/dragon.best/-/blob/master/media/scripts/alphastack/alphastack.py Python implementation] '
New page size (new_size)
64333
Old page size (old_size)
0
Lines added in edit (added_lines)
[ 0 => '{{infobox proglang', 1 => '|name=AlphaStack', 2 => '|paradigms=imperative', 3 => '|author=[[User:Glax]]', 4 => '|year=[[:Category:2026|2026]]', 5 => '|memsys=[[:Category:Stack-based|Stack-based]]', 6 => '|dimensions=one-dimensional', 7 => '|class=[[:Category:Turing complete|Turing complete]]', 8 => '|refimpl=[https://gitlab.com/mattia.basaglia/dragon.best/-/blob/master/media/scripts/alphastack/alphastack.py alphastack.py]', 9 => '}}', 10 => '', 11 => '[[Category:Languages]]', 12 => '[[Category:2026]]', 13 => '[[Category:Stack-based]]', 14 => '[[Category:Turing complete]]', 15 => '[[Category:Deterministic]]', 16 => '[[Category:Implemented]]', 17 => '', 18 => '<h2>Introduction</h2>', 19 => '', 20 => '<p><em>AlphaStack</em> is an stack-based language that uses only letters of the alphabet as values and instructions.</p>', 21 => '', 22 => '<p>Being stack based, the instructions typically pop their arguments from the stacks and push their results onto the stack.</p>', 23 => '', 24 => '<p>You can try this language at its official [https://dragon.best/alphastack/#playground web playground].</p>', 25 => '', 26 => '<h3>Examples</h3>', 27 => '', 28 => '<h4>Hello World</h4>', 29 => '', 30 => '<pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre>', 31 => '', 32 => '<h4>99 Bottles of beer</h4>', 33 => '', 34 => '<pre>vdyppsjepkkjesjeejesjdejidsjfexexjacjdjcsjfadaajasjbaabjpsppppppspsppspsppppspsp', 35 => 'pppspspppspsppppspsjepkaptakecpwaponecpwapdowncpwappasscpwapitcpwaparoundepkjesj', 36 => 'dejesjeejesjdejyyhesppppspsppspspppppppspsppppspsppsesjceapnocpwapmorecpwapbottx', 37 => 'escpwapofcpwapbeerzeejyypsppppspspppspsppspsesjcecpwaponcpwapthecpwapwaxxepkzjyy', 38 => 'ppppspsppspspppppppspsesjcecpwapbottxescpwapofcpwapbeerzjesjbejyysoassjanaakbxzb', 39 => 'njyyppsjcpjppeesjaejsjzpjcjbjcjbjyyasjdaakjwjbdjpsjzpjasjeaakjcjbjcjbjynbqjkblao', 40 => 'sdddddddlalr</pre>', 41 => '', 42 => '<h3 id="stack">Stacks and Procedures</h3>', 43 => '', 44 => '<p><em>AlphaStack</em> has two stacks:</p>', 45 => '', 46 => '<p>The value stack is where most operations happens, with individual letters being pushed and popped into it.</p>', 47 => '', 48 => '<p>The procedure stack contains procedures, the only instruction that can add to this stack is [[#d_-_Define|d]] and some other instructions can access the data stored there.</p>', 49 => '', 50 => '<p>A procedure is a sequence of letters that can be executed at a later time.', 51 => 'Procedures only ever exist on the procedure stack.</p>', 52 => '', 53 => '<p>This manual will often show a summary of an operation as follows:</p>', 54 => '', 55 => '<table class="wikitable">', 56 => ' <tr><td><span class="operand">op1</span><span class="operand">op2</span></td>', 57 => ' <td><code class="instruction">a</code></td>', 58 => ' <td><span class="operand">result</span></td></tr>', 59 => '</table>', 60 => '<p>This shows the instruction <code class="instruction">a</code> and its effect on the stack.', 61 => 'Values before it in the summary represent the top of the stack before the execution of that instruction.', 62 => 'Values after it represent what the head of the stack has been replaced with.', 63 => 'In this example, <code class="operand">op1</code> and <code class="operand">op2</code> will be popped off the stack', 64 => 'and <code class="operand">result</code> will be popped onto the stack.', 65 => '</p>', 66 => '', 67 => '<h3 id="literal-mode">Literal Mode</h3>', 68 => '', 69 => '<p><em>AlphaStack</em> has two modes: literal mode and instruction mode.</p>', 70 => '', 71 => '<p>In literal mode all valid characters are pushed directly onto the stack until the mode is switched.</p>', 72 => '', 73 => '<p>In instruction mode, all charcters are interpreted as instructions and executed immediately.</p>', 74 => '', 75 => '<p>The instruction [[#l_-_Literal|l]] is used to switch between these two modes, and it's the only', 76 => 'instruction to have an effect in literal mode.</p>', 77 => '', 78 => '<p>Program execution always starts in literal mode so you can add data before adding code.</p>', 79 => '', 80 => '<h3>Comments</h3>', 81 => '', 82 => '<p><em>AlphaStack</em> doesn't directly support comments but there are a few techniques to simulate them.</p>', 83 => '', 84 => '<p>All examples in this section are a print the characters <code>a</code> and <code>b</code> using', 85 => '<code>alp</code> and <code>lblp</code> respectively.', 86 => '', 87 => '<p>First of all, all characters that are not lower case ASCII characters are ignored, so you can always add', 88 => 'spaces, upper case letter, and special character.</p>', 89 => '', 90 => '<pre>alp SPACES AND UPPER CASE LETTERS ARE IGNORED! lblp</pre>', 91 => '', 92 => '<p>Since yelling in every comment is considered ruse there's an alternative:', 93 => 'using the [[#l_-_Literal|l]] instruction you can start pushing values onto the stack, then', 94 => 'clear it with [[#u_-_Undo|u]]. Note that [[#u_-_Undo|u]] needs a marker (which can be any letter)', 95 => 'to stop clearing the stack so you can't use that character in the comment.</p>', 96 => '', 97 => '<pre>alp lx this is pushed then popped from the stack, so it has no effect on the program xlu lblp</pre>', 98 => '<p>One side effect of this is that you can't use the marker letter (<code>x</code> in this example) nor single <code>l</code>s', 99 => 'in this style of comment as those they will switch back to instruction mode.', 100 => 'Pairs of <code>l</code>s will work as switching modes twice has no effect.</p>', 101 => '<pre>alp lx Hello comment! xlu lblp</pre>', 102 => '', 103 => '<h3>Numbers</h3>', 104 => '', 105 => '<p>In <em>AlphaStack</em> there are only letters, no numbers.', 106 => 'However can consider interpret the letters as numbers based on their position in the alphabet.', 107 => 'With this in mind, <code>a</code> can be thought as 0, <code>b</code> as 1 and so on.</p>', 108 => '<p>Similarly, the value <code>a</code> is considered false, while all other values are considered true.</p>', 109 => '', 110 => '<h3>Registers</h3>', 111 => '', 112 => '<p>Each letter has a register associated with it. These registered can be freely', 113 => 'written to or read from (using [[#s_-_Set|s]] and [[#g_-_Get|g]]).', 114 => 'Some instructions modify their behaviour based on the value of the corresponding register.</p>', 115 => '', 116 => '<p>At the start of a program all registers have a value of <code>a</code> (0).</p>', 117 => '', 118 => '', 119 => '<h2>Tutorial</h2>', 120 => '', 121 => '<p>This section will walk through the basics of <em>AlphaStack</em> with some practical examples.', 122 => 'The tutorials assume you've been through the [[#Introduction|introduction]] fist.</p>', 123 => '', 124 => '<h3>Hello World</h3>', 125 => '', 126 => '<p>This tutorial shows the basics of printing text to standard output</p>', 127 => '', 128 => '<pre>abcd</pre>', 129 => '', 130 => '<p>Since a program starts in [[#Literal_Mode|literal mode]],', 131 => 'this code pushes <code>abcd</code> onto the [[#Stacks_and_Procedures|value stack]].', 132 => '<code>d</code> being at the top of the stack and <code>a</code> at the bottom.</p>', 133 => '', 134 => '<pre>abcd l</pre>', 135 => '', 136 => '<p>Any characters that are not letters are ignored, so the space does nothing.', 137 => '[[#l_-_Literal|l]] exits literal mode and enters instruction mode.', 138 => 'This means after it letters will be executed as instructions rather than pushed onto the stack.</p>', 139 => '', 140 => '<pre>abcd l pppp</pre>', 141 => '', 142 => '<p>Here [[#p_-_Print|p]] is executed 4 times, printing 4 letters off the top of the stack.', 143 => 'This clears the stack as each letter is popped before printing and outputs <code>dbca</code>. <br/>', 144 => 'The order of the letters is reversed because they are printed from the top of the stack.</p>', 145 => '', 146 => '<p>Now, if we want to print <code>abcd</code> as numbers instead, we need to set the [[#p_-_Print_Mode_Register|p register]] to <code>c</code> first, this is done with the [[#s_-_Set|s]] command which pops a', 147 => 'reister and its value off the stack:</p>', 148 => '', 149 => '<pre>abcd pc l s pppp</pre>', 150 => '', 151 => '<p>Here <code>pc</code> on the stack is consumed by [[#s_-_Set|s]] to do just that', 152 => 'and the code outputs <code>3210</code>.</p>', 153 => '', 154 => '<p>Again, spaces are not meaningful in <em>AlphaStack</em> in the example they are used to', 155 => 'highlight which literals are used by which instuction.</p>', 156 => '', 157 => '<p>If you want to enter values in literal mode and then print them in the same order as', 158 => 'they were pushed onto the stack, you need to flip them around first:</p>', 159 => '', 160 => '<pre>abcd e l f pppp</pre>', 161 => '', 162 => '<p>Now [[#f_-_Flip|f]] pops <code>e</code> off the stack, this corresponds', 163 => 'with the number 4, and flips that many items on the stack. In this case the stack', 164 => 'ends up as <code>dbca</code>, printing <code>abcd</code>.</p>', 165 => '', 166 => '<p>Let's say we want to print the word "hello". There's an issue here,', 167 => '[[#l_-_Literal|l]] switches between literal mode and instruction mode', 168 => 'so it can't be directly entered as a literal.', 169 => 'To work around this we can push a value <code>l</code> onto the stack by', 170 => 'performing a simple mathematical operation:', 171 => '</p>', 172 => '', 173 => '<pre>kb l a p</pre>', 174 => '', 175 => '<p>[[#a_-_Arithmetic_Operation|a]] pops two values off the stack and adds them together,', 176 => 'in this case adds <code>b</code> (1) to <code>k</code>, obtaining <code>l</code>.', 177 => 'Then [[#p_-_Print|p]] prints it.</p>', 178 => '', 179 => '<p>Now we can print hello like so:</p>', 180 => '', 181 => '<pre>o kb kb e h l p p ap ap p</pre>', 182 => '', 183 => '<p>The first two [[#p_-_Print|p]] print <code>h</code> and <code>e</code>', 184 => 'respectively. Then [[#a_-_Arithmetic_Operation|a]] followed by [[#p_-_Print|p]] print an <code>l</code>, this is done twice. The final [[#p_-_Print|p]] prints', 185 => 'the <code>o</code>.</p>', 186 => '', 187 => '<p>Replacing each <code>l</code> individually can become tedious so we can push a single', 188 => 'one onto the stack and then replace a different character with it.</p>', 189 => '', 190 => '<code>oxxeh yxkb l a o ppppp</code>', 191 => '', 192 => '<p>Here [[#a_-_Arithmetic_Operation|a]] turns <code>kb</code> into <code>l</code> like before.', 193 => '[[#o_-_Overwrite|o]] then pops the 3 topmost items on the stack: <code>yxl</code>.', 194 => 'It then performs a replacement of the values on the stack with as follows:', 195 => 'all occurrences of <code>x</code> are replaced by <code>l</code> until the next', 196 => '<code>y</code> is reached. In this case there are no <code>y</code> values on the stack', 197 => 'after the initial one so the entire stack is processed.', 198 => 'Finally the five [[#p_-_Print|p]] print <code>hello</code>.</p>', 199 => '', 200 => '<p>We can combine all of this with different print modes to print <code>Hello World!</code>:</p>', 201 => '', 202 => '<pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre>', 203 => '', 204 => '<h3>Procedures and Loops</h3>', 205 => '', 206 => '<p>Let's say you don't want to type a [[#p_-_Print|p]] for every single letters you', 207 => 'want to output. We can create a procedure that prints the stack until a condition is met.</p>', 208 => '', 209 => '<p>First we need to get a condition that checks the top of the stack for a given value and', 210 => 'halts execution when found.', 211 => 'Conditionals are handled by [[#i_-_If|i]], which needs a procedure to run when the condition is met.', 212 => 'We start by defining the halting procedure:/p>', 213 => '', 214 => '<pre>xhx l d</pre>', 215 => '', 216 => '<p>[[#d_-_Define|d]] here uses <code>x</code> as a delimiter', 217 => 'and pushes a procedure containing <code>h</code> on top of the procedure stack.</p>', 218 => '', 219 => '<p>Now we are ready to define the main procedure.', 220 => 'Since we need literals in the main procedure we need to perform the usual trick to replace', 221 => '<code>j</code> with <code>l</code>:</p>', 222 => '', 223 => '<pre>xpikacjbzjx jbk ob xhx l d sao d</pre>', 224 => '', 225 => '<p>This code starts as before with [[#d_-_Define|d]] popping <code>xhx</code> from the value', 226 => 'stack and pushing <code>h</code> onto the procedure stack.', 227 => 'Then <code>sao</code> performs the <code>j</code> to <code>l</code> replacement:', 228 => '[[#s_-_Set|s]] pops <code>ob</code> to set the [[#o_-_Keep_Mark_Register|o register]] to keep the delimiter.', 229 => '[[#a_-_Arithmetic_Operation|a]] the pops <code>bk</code> to push a <code>l</code>.', 230 => '[[#o_-_Overwrite|o]] pops <code>jl</code> to replace all occurrences of <code>j</code> with <code>l</code>', 231 => 'using <code>x</code> as a delimiter. Since we set the [[#o_-_Keep_Mark_Register|o register]] register to the value', 232 => '<code>b</code> using [[#s_-_Set|s]], the <code>x</code> delimiters are not removed from the stack.', 233 => 'This allows [[#d_-_Define|d]] to use the same deimiter.</p>', 234 => '', 235 => '<p>Finally, [[#d_-_Define|d]] pops <code>xpikaclbzlx</code> from the value stack and pushes', 236 => '<code>lzblcakip</code> onto the procedure stack.', 237 => 'Note that [[#d_-_Define|d]] removes the delimiters from the procedure and reverses the order of its letters', 238 => 'so when you define procedures in literal mode, you need to flip them around.</p>', 239 => '', 240 => '<p>Now let's see that the code in the procedure does:</p>', 241 => '<pre>lzbl ca kip</pre>', 242 => '', 243 => '<p>[[#l_-_Literal|l]] toggles between modes so <code>lzbl</code> results in a literal', 244 => 'pushing <code>z</code> and <code>b</code> onto the stack.', 245 => '[[#c_-_Copy|c]] then pops <code>b</code> from the stack, this is a value of 1', 246 => 'which means [[#c_-_Copy|c]] copies the next item on the stack, skipping the <code>z</code>.', 247 => 'After [[#c_-_Copy|c]] the stack top of the contains a copy of the initial top of the stack followed by <code>z</code>.', 248 => '</p>', 249 => '', 250 => '<p>[[#a_-_Arithmetic_Operation|a]] then performs an operation on these two.', 251 => 'The operation performed by [[#a_-_Arithmetic_Operation|a]] is determined by the value of the [[#a_-_Operation_Register|a register]].', 252 => 'The default operation is addition but it will need to be set to equality comparison before the procedure is executed.', 253 => 'If the [[#a_-_Operation_Register|a register]] is set to comparison, [[#a_-_Arithmetic_Operation|a]] will pop the two letters off the top', 254 => 'of the stack and push true (<code>b</code>) or false (<code>a</code>) depending whether they are the same.</p>', 255 => '', 256 => '<p>Follows [[#k_-_Keep|k]] which copies the top procedure from the procedure stack, this is requires to prevent', 257 => '[[#i_-_If|i]] from consuming it since we are looping.', 258 => '[[#i_-_If|i]] consumes the copied procedure and the result of the comparison, executing the procedure if the', 259 => 'result is true (<code>b</code>). When the procedure is executed, the program halts (this procedure is <code>h</code>, which was defined', 260 => 'at the start.', 261 => 'Finally [[#p_-_Print|p]] pops and prints the top of the stack. This only happens if the condition was false as it means the program', 262 => 'was not halted.', 263 => '</p>', 264 => '', 265 => '<p>Final bit of setup:</p>', 266 => '<pre>a af xpikacjbzjx jbk ob xhx l d sao d s r</pre>', 267 => '', 268 => '<p>Here is the same but there is more data onto the stack and two more instructions.', 269 => 'The second [[#s_-_Set|s]] pops <code>af</code> to set the [[#a_-_Arithmetic_Operation|a]] to equality', 270 => 'comparison mode. Then [[#r_-_Repeat|r]] will pop the remaining <code>a</code> which means it will loop', 271 => 'forever (or in this case until halted.</p>', 272 => '', 273 => '<p>Now all that's needed is some data on the stack to be printed, using <code>z</code> as a delimiter', 274 => '(since it's the value we're comparing against on the procedure).</p>', 275 => '', 276 => '<pre>z kcatsehtgnitnirp a af xpikacjbzjx jbk ob xhx l d sao d s r</pre>', 277 => '', 278 => 'Output:', 279 => '<pre>printingthestack</pre>', 280 => '', 281 => '<h2>Alphabet</h2>', 282 => '', 283 => '<p><em>AlphaStack</em> uses the 26 (lower case) letters of the Latin alphabet.', 284 => 'All other characters are ignores, including upper case letters.</p>', 285 => '', 286 => '<table class="wikitable">', 287 => ' <tr><th>Letter</th><th>Numerical</th><th>Instruction</th><th>Register</th><th colspan='3'>Summary</th></tr>', 288 => ' <tr><th>a</th><td class='letterval'>0</td>', 289 => ' <td>[[#a_-_Arithmetic_Operation|Arithmetic Operation]]</td>', 290 => ' <td>[[#a_-_Operation_Register|Operation]]</td>', 291 => ' <td class='summary-col'><span class='operand'>num1</span><span class='operand'>num2</span></td>', 292 => ' <td class='summary-col'><code class='instruction'>a</code></td>', 293 => ' <td class='summary-col'><span class='operand'>num3</span></td></tr>', 294 => ' <tr><th>b</th><td class='letterval'>1</td>', 295 => ' <td>[[#b_-_Break|Break]]</td>', 296 => ' <td></td>', 297 => ' <td class='summary-col'></td>', 298 => ' <td class='summary-col'><code class='instruction'>b</code></td>', 299 => ' <td class='summary-col'></td></tr>', 300 => ' <tr><th>c</th><td class='letterval'>2</td>', 301 => ' <td>[[#c_-_Copy|Copy]]</td>', 302 => ' <td></td>', 303 => ' <td class='summary-col'><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>index</span></td>', 304 => ' <td class='summary-col'><code class='instruction'>c</code></td>', 305 => ' <td class='summary-col'><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>val</span></td></tr>', 306 => ' <tr><th>d</th><td class='letterval'>3</td>', 307 => ' <td>[[#d_-_Define|Define]]</td>', 308 => ' <td></td>', 309 => ' <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td>', 310 => ' <td class='summary-col'><code class='instruction'>d</code></td>', 311 => ' <td class='summary-col'></td></tr>', 312 => ' <tr><th>e</th><td class='letterval'>4</td>', 313 => ' <td>[[#e_-_Execute_Specific|Execute Specific]]</td>', 314 => ' <td>[[#e_-_Execute_Index_Register|Execute Index]]</td>', 315 => ' <td class='summary-col'></td>', 316 => ' <td class='summary-col'><code class='instruction'>e</code></td>', 317 => ' <td class='summary-col'></td></tr>', 318 => ' <tr><th>f</th><td class='letterval'>5</td>', 319 => ' <td>[[#f_-_Flip|Flip]]</td>', 320 => ' <td></td>', 321 => ' <td class='summary-col'><span class='operand'>...</span><span class='operand'>count</span></td>', 322 => ' <td class='summary-col'><code class='instruction'>f</code></td>', 323 => ' <td class='summary-col'><span class='operand'>...</span></td></tr>', 324 => ' <tr><th>g</th><td class='letterval'>6</td>', 325 => ' <td>[[#g_-_Get|Get]]</td>', 326 => ' <td></td>', 327 => ' <td class='summary-col'><span class='operand'>reg</span></td>', 328 => ' <td class='summary-col'><code class='instruction'>g</code></td>', 329 => ' <td class='summary-col'><span class='operand'>val</span></td></tr>', 330 => ' <tr><th>h</th><td class='letterval'>7</td>', 331 => ' <td>[[#h_-_Halt|Halt]]</td>', 332 => ' <td></td>', 333 => ' <td class='summary-col'></td>', 334 => ' <td class='summary-col'><code class='instruction'>h</code></td>', 335 => ' <td class='summary-col'></td></tr>', 336 => ' <tr><th>i</th><td class='letterval'>8</td>', 337 => ' <td>[[#i_-_If|If]]</td>', 338 => ' <td>[[#i_-_If_Else_Count_Register|If Else Count]]</td>', 339 => ' <td class='summary-col'><span class='operand'>valn</span><span class='operand'>...</span><span class='operand'>val0</span></td>', 340 => ' <td class='summary-col'><code class='instruction'>i</code></td>', 341 => ' <td class='summary-col'></td></tr>', 342 => ' <tr><th>j</th><td class='letterval'>9</td>', 343 => ' <td></td>', 344 => ' <td></td>', 345 => ' <td class='summary-col'></td>', 346 => ' <td class='summary-col'></td>', 347 => ' <td class='summary-col'></td></tr>', 348 => ' <tr><th>k</th><td class='letterval'>10</td>', 349 => ' <td>[[#k_-_Keep|Keep]]</td>', 350 => ' <td>[[#k_-_Keep_Count_Register|Keep Count]]</td>', 351 => ' <td class='summary-col'></td>', 352 => ' <td class='summary-col'><code class='instruction'>k</code></td>', 353 => ' <td class='summary-col'></td></tr>', 354 => ' <tr><th>l</th><td class='letterval'>11</td>', 355 => ' <td>[[#l_-_Literal|Literal]]</td>', 356 => ' <td>[[#l_-_Mode_Register|Mode]]</td>', 357 => ' <td class='summary-col'></td>', 358 => ' <td class='summary-col'><code class='instruction'>l</code></td>', 359 => ' <td class='summary-col'></td></tr>', 360 => ' <tr><th>m</th><td class='letterval'>12</td>', 361 => ' <td>[[#m_-_Memory|Memory]]</td>', 362 => ' <td>[[#m_-_Memory_Cell_Register|Memory Cell]]</td>', 363 => ' <td class='summary-col'></td>', 364 => ' <td class='summary-col'><code class='instruction'>m</code></td>', 365 => ' <td class='summary-col'><span class='operand'>val</span></td></tr>', 366 => ' <tr><th>n</th><td class='letterval'>13</td>', 367 => ' <td>[[#n_-_Number_of_Items|Number of Items]]</td>', 368 => ' <td>[[#n_-_Number_Size_Register|Number Size]]</td>', 369 => ' <td class='summary-col'></td>', 370 => ' <td class='summary-col'><code class='instruction'>n</code></td>', 371 => ' <td class='summary-col'><span class='operand'>count</span></td></tr>', 372 => ' <tr><th>o</th><td class='letterval'>14</td>', 373 => ' <td>[[#o_-_Overwrite|Overwrite]]</td>', 374 => ' <td>[[#o_-_Keep_Mark_Register|Keep Mark]]</td>', 375 => ' <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span><span class='operand'>search</span><span class='operand'>replace</span></td>', 376 => ' <td class='summary-col'><code class='instruction'>o</code></td>', 377 => ' <td class='summary-col'><span class='operand'>...</span></td></tr>', 378 => ' <tr><th>p</th><td class='letterval'>15</td>', 379 => ' <td>[[#p_-_Print|Print]]</td>', 380 => ' <td>[[#p_-_Print_Mode_Register|Print Mode]]</td>', 381 => ' <td class='summary-col'><span class='operand'>val</span></td>', 382 => ' <td class='summary-col'><code class='instruction'>p</code></td>', 383 => ' <td class='summary-col'></td></tr>', 384 => ' <tr><th>q</th><td class='letterval'>16</td>', 385 => ' <td></td>', 386 => ' <td></td>', 387 => ' <td class='summary-col'></td>', 388 => ' <td class='summary-col'></td>', 389 => ' <td class='summary-col'></td></tr>', 390 => ' <tr><th>r</th><td class='letterval'>17</td>', 391 => ' <td>[[#r_-_Repeat|Repeat]]</td>', 392 => ' <td></td>', 393 => ' <td class='summary-col'><span class='operand'>count</span></td>', 394 => ' <td class='summary-col'><code class='instruction'>r</code></td>', 395 => ' <td class='summary-col'></td></tr>', 396 => ' <tr><th>s</th><td class='letterval'>18</td>', 397 => ' <td>[[#s_-_Set|Set]]</td>', 398 => ' <td></td>', 399 => ' <td class='summary-col'><span class='operand'>reg</span><span class='operand'>val</span></td>', 400 => ' <td class='summary-col'><code class='instruction'>s</code></td>', 401 => ' <td class='summary-col'></td></tr>', 402 => ' <tr><th>t</th><td class='letterval'>19</td>', 403 => ' <td>[[#t_-_Text_Input|Text Input]]</td>', 404 => ' <td>[[#t_-_Read_Result_Register|Read Result]]</td>', 405 => ' <td class='summary-col'></td>', 406 => ' <td class='summary-col'><code class='instruction'>t</code></td>', 407 => ' <td class='summary-col'><span class='operand'>val?</span></td></tr>', 408 => ' <tr><th>u</th><td class='letterval'>20</td>', 409 => ' <td>[[#u_-_Undo|Undo]]</td>', 410 => ' <td></td>', 411 => ' <td class='summary-col'><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td>', 412 => ' <td class='summary-col'><code class='instruction'>u</code></td>', 413 => ' <td class='summary-col'></td></tr>', 414 => ' <tr><th>v</th><td class='letterval'>21</td>', 415 => ' <td></td>', 416 => ' <td></td>', 417 => ' <td class='summary-col'></td>', 418 => ' <td class='summary-col'></td>', 419 => ' <td class='summary-col'></td></tr>', 420 => ' <tr><th>w</th><td class='letterval'>22</td>', 421 => ' <td>[[#w_-_Wrap|Wrap]]</td>', 422 => ' <td></td>', 423 => ' <td class='summary-col'><span class='operand'>...</span><span class='operand'>count</span><span class='operand'>steps</span></td>', 424 => ' <td class='summary-col'><code class='instruction'>w</code></td>', 425 => ' <td class='summary-col'><span class='operand'>...</span></td></tr>', 426 => ' <tr><th>x</th><td class='letterval'>23</td>', 427 => ' <td>[[#x_-_Execute|Execute]]</td>', 428 => ' <td></td>', 429 => ' <td class='summary-col'></td>', 430 => ' <td class='summary-col'><code class='instruction'>x</code></td>', 431 => ' <td class='summary-col'></td></tr>', 432 => ' <tr><th>y</th><td class='letterval'>24</td>', 433 => ' <td>[[#y_-_Yield|Yield]]</td>', 434 => ' <td></td>', 435 => ' <td class='summary-col'></td>', 436 => ' <td class='summary-col'><code class='instruction'>y</code></td>', 437 => ' <td class='summary-col'></td></tr>', 438 => ' <tr><th>z</th><td class='letterval'>25</td>', 439 => ' <td></td>', 440 => ' <td></td>', 441 => ' <td class='summary-col'></td>', 442 => ' <td class='summary-col'></td>', 443 => ' <td class='summary-col'></td></tr>', 444 => '</table>', 445 => '', 446 => '<h2>Letter Details</h2>', 447 => '', 448 => '<h3 id='a-instruction'><span class='instruction'>a</span> - Arithmetic Operation</h3>', 449 => '', 450 => ''''Synopsis'''', 451 => '', 452 => '<table class="wikitable synopsis"><tr><td><span class='operand'>num1</span><span class='operand'>num2</span></td><td><code>a</code></td><td><span class='operand'>num3</span></td></tr></table>', 453 => '<p>The <span class="instruction">a</span> pops two values from the stack,', 454 => 'performs a mathematical operation on them and pushes the result back onto the stack.', 455 => 'In all cases <code class="operand">num1</code> is the left hand side operand and', 456 => '<code class="operand">num2</code> is the right hand side operand.</p>', 457 => '', 458 => '<p>The specific operation to be performed on the two operands depends on the value of the <span class="instruction">a</span> register.</p>', 459 => '<h3 id='a-register'><span class='instruction'>a</span> - Operation Register</h3>', 460 => '<table class="wikitable">', 461 => ' <tr>', 462 => ' <th>Value</th>', 463 => ' <th>Name</th>', 464 => ' <th>Operation</th>', 465 => ' </tr>', 466 => ' <tr><th class='operand'>a</th><td>Addition</td><td class='operand'>val3 = val1 + val2</td></tr>', 467 => ' <tr><th class='operand'>b</th><td>Subtraction</td><td class='operand'>val3 = val1 - val2</td></tr>', 468 => ' <tr><th class='operand'>c</th><td>Multiplication</td><td class='operand'>val3 = val1 * val2</td></tr>', 469 => ' <tr><th class='operand'>d</th><td>Integer division</td><td class='operand'>val3 = val1 / val2</td></tr>', 470 => ' <tr><th class='operand'>e</th><td>Modulo</td><td class='operand'>val3 = val1 % val2</td></tr>', 471 => ' <tr><th class='operand'>f</th><td>Equality comparison</td><td class='operand'>val3 = val1 == val2</td></tr>', 472 => ' <tr><th class='operand'>g</th><td>Greater than</td><td class='operand'>val3 = val1 &gt; val2</td></tr>', 473 => ' <tr><th class='operand'>h</th><td>Greater or equal</td><td class='operand'>val3 = val1 &gt;= val2</td></tr>', 474 => ' <tr><th class='operand'>i</th><td>Less or equal</td><td class='operand'>val3 = val1 &lt;= val2</td></tr>', 475 => ' <tr><th class='operand'>j</th><td>Less than</td><td class='operand'>val3 = val1 &lt; val2</td></tr>', 476 => ' <tr><th class='operand'>k</th><td>Not equal</td><td class='operand'>val3 = val1 != val2</td></tr>', 477 => '</table>', 478 => '', 479 => ''''Examples'''', 480 => '', 481 => 'Code:', 482 => '<pre>cdlap</pre>', 483 => '', 484 => 'Output:', 485 => '<pre>f</pre>', 486 => '', 487 => '<p>The program starts in literal mode, so <code class="operand">c</code> and <code class="operand">d</code>', 488 => 'are pushed onto the stack as data.<br/>', 489 => '[[#l_-_Literal|l]] disables literal mode, so [[#a_-_Arithmetic_Operation|a]] is executed as an instruction. It pops <code class="operand">c</code> (2) and <code class="operand">d</code> (3)', 490 => 'from the stack calculates their sum, <code class="operand">f</code> (5), then pushes it onto the stack.<br/>', 491 => 'Finally, [[#p_-_Print|p]] prints the top of the stack to standard output.</p>', 492 => '', 493 => 'Code:', 494 => '<pre>czlap</pre>', 495 => '', 496 => 'Output:', 497 => '<pre>b</pre>', 498 => '', 499 => '<p>This example adds <code class="operand">c</code> (2) and <code class="operand">z</code> (25). Ther output is', 500 => '<code class="operand">b</code> (1) because math operations are modulo 26.</p>', 501 => '', 502 => '', 503 => 'Code:', 504 => '<pre>cdaclsap</pre>', 505 => '', 506 => 'Output:', 507 => '<pre>g</pre>', 508 => '', 509 => '<p>This example multiplies <code class="operand">c</code> (2) and <code class="operand">d</code> (3).', 510 => 'This is achieved by setting the [[#a_-_Operation_Register|a register]] to <code class="operand">c</code> using [[#s_-_Set|s]].', 511 => '</p>', 512 => '', 513 => '<h3 id='b-instruction'><span class='instruction'>b</span> - Break</h3>', 514 => '', 515 => ''''Synopsis'''', 516 => '', 517 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>b</code></td><td></td></tr></table>', 518 => '<p>Breaks out of the current loop. Does not affect the stack.</p>', 519 => '', 520 => ''''Example'''', 521 => '', 522 => '<p>If we take this starting example:</p>', 523 => '', 524 => '<pre>xpkbl a labl c lxl d lal r</pre>', 525 => '', 526 => '<p>it will endlessly print <code>a</code>.</p>', 527 => '', 528 => '<p>The explanation chunk by chunk:</p>', 529 => '', 530 => '<pre>xpkbl a</pre>', 531 => '', 532 => '<p>Pushes <code>xpkb</code> onto the stack, then calls [[#a_-_Arithmetic_Operation|a]] to add <code>b</code> and <code>k</code> to obtain <code>l</code> since <code>l</code>', 533 => 'can't be pushed onto the stack directly, obtaining <code>xpl</code>.</p>', 534 => '', 535 => '<pre>labl c</pre>', 536 => '<p>Pushes <code>a</code> and copies the <code>l</code> with [[#c_-_Copy|c]] resulting with the stack <code>xplal</code>.</p>', 537 => '', 538 => '<pre>lxl d</pre>', 539 => '<p>Pushes <code>x</code> as a marker, then [[#d_-_Define|d]] rolls the stack betwen the two', 540 => '<code>x</code> markers into a procedure. Note that the procedure will be reversed compared to the other of the stack.', 541 => 'The procedure will be pushed into the procedure stack as <code>lalp</code>.</p>', 542 => '', 543 => '<pre>lal r</pre>', 544 => '<p>Pushes <code>a</code> onto the stack to create an infinite loop with [[#r_-_Repeat|r]], which', 545 => 'will pop the created procedure and loop it indefinitely. The procedure just prints <code>a</code> every time.', 546 => '</p>', 547 => '', 548 => 'If we add a break to the procedure the loop will stop after the first iteration:', 549 => '', 550 => '<pre>xbpkbl a labl c lxl d lal r</pre>', 551 => '', 552 => 'Output:', 553 => '<pre>a</pre>', 554 => '', 555 => '<h3 id='c-instruction'><span class='instruction'>c</span> - Copy</h3>', 556 => '', 557 => ''''Synopsis'''', 558 => '', 559 => '<table class="wikitable synopsis"><tr><td><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>index</span></td><td><code class='instruction'>c</code></td><td><span class='operand'>val</span><span class='operand'>...</span><span class='operand'>val</span></td></tr></table>', 560 => '<p>Copies a value <code class="operand">index</code> positions into the stack.</p>', 561 => '', 562 => '<p>It pops <code class="operand">index</code>, looks into the stack from the top', 563 => 'that many spaces, and pushes a copy of the corresponding value on top of the stack.</p>', 564 => '', 565 => ''''Example'''', 566 => '', 567 => '<pre>somedatafl c</pre>', 568 => '', 569 => '<p>This pushes <code>somedataf</code> onto the stack then executes [[#c_-_Copy|c]].', 570 => 'It will pop <code>f</code> (5), then look that many spaces down the remaining stack, find', 571 => '<code>m</code> and copy it on top of the stack. This results in a stack of <code>somedatam</code>.', 572 => '</p>', 573 => '', 574 => '<h3 id='d-instruction'><span class='instruction'>d</span> - Define</h3>', 575 => '', 576 => ''''Synopsis'''', 577 => '', 578 => '<table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td><td><code class='instruction'>d</code></td><td></td></tr></table>', 579 => '<p>Defines a procedure delimited by <code class="operand">mark</code> and pushes it on the procedure stack.</p>', 580 => '', 581 => '<p>It pops the first stack value, <code class="operand">mark</code> which can be anything, then keeps popping', 582 => 'until another value equal to <code class="operand">mark</code> is found (or the stack is empty).</p>', 583 => '', 584 => '<p>The result is then pushed onto the procedure stack, with the values flipped compared to how they were in the initial stack.', 585 => 'The flip happens because values are pushed onto the procedure as they are popped from the stack.</p>', 586 => '', 587 => '', 588 => ''''Example'''', 589 => '', 590 => 'This example uses a procedure and a loop to print the contents of the stack until a delimiter (<code>z</code>) is reached.', 591 => '', 592 => 'Code:', 593 => '<pre>zerudecorp a af xpikacjbzjx jbk xhx ob l sdaodsr</pre>', 594 => '', 595 => 'Output:', 596 => '<pre>procedure</pre>', 597 => '', 598 => '<p>Before the [[#l_-_Literal|l]] all the letter are pushed onto the stack. then the following operations are performed:</p>', 599 => '', 600 => '<p>[[#s_-_Set|s]] pops <code>ob</code> and sets the [[#o_-_Keep_Mark_Register|o register]] is set to keep the delimiter.</p>', 601 => '<p>[[#d_-_Define|d]] pops <code>xhx</code> and pushes <code>h</code> as a procedure.', 602 => 'Here we are using <code>x</code> as a delimiter but any letter works as delimiter, just ensure it isn't used with the procedure itself.', 603 => '</p>', 604 => '<p>[[#a_-_Arithmetic_Operation|a]] pops <code>bk</code>, adds them, and pushes <code>l</code> (this is because <code>l</code> cannot be used as a literal).</p>', 605 => '<p>[[#o_-_Overwrite|o]] pops <code>jl</code> and preforms a replacement from <code>j</code> to <code>l</code>.', 606 => 'using <code>x</code> as delimiter. Results in changing the top of the stack from', 607 => '<code>xpikacjbzjx</code> to <code>xpikaclbzlx</code>. The <code>x</code> delimiters are preserved due to the value of', 608 => '[[#o_-_Keep_Mark_Register|o register]] that was set previously.', 609 => '</p>', 610 => '<p>[[#d_-_Define|d]] pops <code>xpikaclbzlx</code> and pushes <code>lzblcakip</code> as a procedure.</p>', 611 => '<p>[[#s_-_Set|s]] pops <code>af</code> and sets the [[#a_-_Operation_Register|a register]] to perform equality comparison.</p>', 612 => '<p>[[#r_-_Repeat|r]] pops <code>a</code> and performs the last procedure indefinitely.</p>', 613 => '', 614 => 'The code in the procedure does the following:', 615 => '<pre>lzbl c akip</pre>', 616 => '', 617 => '<p><code>lzbl</code> pushes <code>zb</code> onto the stack.</p>', 618 => '<p>[[#c_-_Copy|c]] pops <code>b</code> and copies the item below the head of the stack back on top.', 619 => 'This copies the value set at the start of the main code', 620 => '</p>', 621 => '<p>[[#a_-_Arithmetic_Operation|a]] pops the copied value and <code>b</code> from the stack pushing <code>b</code> (true)', 622 => 'or <code>a</code> (false) based on their comparison (because [[#a_-_Operation_Register|a register]] is set to comparison.</p>', 623 => '<p>[[#k_-_Keep|k]] duplicates the top procedure.', 624 => 'Note that [[#r_-_Repeat|r]] pops the procedure before looping so the top procedure is now <code>h</code>.</p>', 625 => '<p>[[#i_-_If|i]] pops the value left by [[#a_-_Arithmetic_Operation|a]] and the procedure duplicated by [[#k_-_Keep|k]].', 626 => 'If the result of the comparison is true, (the letter copied by [[#c_-_Copy|c]] is <code>z</code>), it will call the procedure', 627 => 'which in turns halts the program using [[#h_-_Halt|h]].', 628 => 'If the condition is not true nothing else happens.</p>', 629 => '<p>[[#p_-_Print|p]] pops the top of the stack and prints it. This causes the stack size to decrease by one.</p>', 630 => '<p>After this [[#r_-_Repeat|r]] keeps repeating the procedure, which has the effect of printing the stack', 631 => 'until the character <code>z</code> is reached.</p>', 632 => '', 633 => '<h3 id='e-instruction'><span class='instruction'>e</span> - Execute Specific</h3>', 634 => '', 635 => ''''Synopsis'''', 636 => '', 637 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>e</code></td><td></td></tr></table>', 638 => '<p>Executes a specific procedure based on [[#e_-_Execute_Index_Register|e register]], not affecting any of the stacks.</p>', 639 => '', 640 => '<p>This is handy to repeatedly calling a procedure without having to modify stack values.</p>', 641 => '', 642 => '<h3 id='e-register'><span class='instruction'>e</span> - Execute Index Register</h3> <p>Procedure index for [[#e_-_Execute_Specific|e]]. A value of <code>a</code> (0), which is the default', 643 => 'means the first procedure.<p>', 644 => '', 645 => '<p>This index is counted from the bottom of the procedure stack.</p>', 646 => '', 647 => ''''Example'''', 648 => '', 649 => 'Code:', 650 => '<pre>tset xqx xax xpx xhx eb l s dddd eeee</pre>', 651 => '', 652 => 'Output:', 653 => '<pre>test</pre>', 654 => '', 655 => '<p>Values are pushed onto the stack until [[#l_-_Literal|l]].</p>', 656 => '<p>[[#s_-_Set|s]] pops <code>eb</code> and sets the [[#e_-_Execute_Index_Register|e register]] is set to <code>b</code> (1).</p>', 657 => '<p>[[#d_-_Define|d]] is called 4 times and it defines procedures based on the <code>x</code> delimiter.', 658 => 'After this the procedure stack has these procedures: <code>h</code>, <code>p</code>, <code>a</code>, <code>q</code>.', 659 => '</p>', 660 => '<p>[[#e_-_Execute_Specific|e]] is called 4 times as well, each time executing the procedure at index 1, which just prints the top of the stack.', 661 => 'Note that any procedure defined after the one with the given index doesn't matter as [[#e_-_Execute_Index_Register|e register]] refers to indices', 662 => 'starting from the bottom of the procedure stack.</p>', 663 => '', 664 => '', 665 => '<h3 id='f-instruction'><span class='instruction'>f</span> - Flip</h3>', 666 => '', 667 => ''''Synopsis'''', 668 => '', 669 => '<table class="wikitable synopsis"><tr><td><span class='operand'>...</span><span class='operand'>count</span></td><td><code class='instruction'>f</code></td><td><span class='operand'>...</span></td></tr></table>', 670 => '<p>Reverses the order of <code class="operand">count</code> items on the top of the stack.</p>', 671 => '', 672 => '<p>Pops <code class="operand">count</code>, then pops that many other items off the top of the stack', 673 => 'and pushes them back onto the stack but in reverse order.</p>', 674 => '', 675 => ''''Example'''', 676 => '', 677 => 'Code:', 678 => '<pre>foobar d l f</pre>', 679 => '', 680 => '<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>foobard</code>.</p>', 681 => '<p>[[#f_-_Flip|f]] pops <code>d</code> (3), then flips the next 3 items on the stack, resulting with a stack of <code>foorab</code>.</p>', 682 => '', 683 => '', 684 => '<h3 id='g-instruction'><span class='instruction'>g</span> - Get</h3>', 685 => '', 686 => ''''Synopsis'''', 687 => '', 688 => '<table class="wikitable synopsis"><tr><td><span class='operand'>reg</span></td><td><code class='instruction'>g</code></td><td><span class='operand'>val</span></td></tr></table>', 689 => '<p>Pops <code class="operand">reg</code> from the stack, then pushes the value of the corresponding register onto the stack.</p>', 690 => '', 691 => ''''Example'''', 692 => '', 693 => 'Code:', 694 => '<pre>m mf l s g</pre>', 695 => '<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>mmf</code>.</p>', 696 => '<p>[[#s_-_Set|s]] pops <code>mf</code> and sets the [[#m_-_Memory_Cell_Register|m register]] to <code>f</code>.</p>', 697 => '<p>[[#g_-_Get|g]] pops <code>m</code> and pushes its value (<code>f</code>) onto the stack, resulting in a stack with <code>f</code>.</p>', 698 => '', 699 => '<h3 id='h-instruction'><span class='instruction'>h</span> - Halt</h3>', 700 => '', 701 => ''''Synopsis'''', 702 => '', 703 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>h</code></td><td></td></tr></table>', 704 => '<p>Halts execution, without affecting the stack.</p>', 705 => '', 706 => ''''Example'''', 707 => '', 708 => 'Code:', 709 => '<pre>abcd l p p h p p</pre>', 710 => '', 711 => 'Output:', 712 => '<pre>dc</pre>', 713 => '', 714 => '<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>abcd</code>.</p>', 715 => '<p>[[#p_-_Print|p]] is called twice popping <code>d</code> and <code>c</code> off the stack and printing them.</p>', 716 => '<p>[[#h_-_Halt|h]] halts execution so the remaining [[#p_-_Print|p]] calls are not executed.</p>', 717 => '', 718 => '<h3 id='i-instruction'><span class='instruction'>i</span> - If</h3>', 719 => '', 720 => ''''Synopsis'''', 721 => '', 722 => '<table class="wikitable synopsis"><tr><td><span class='operand'>valn</span><span class='operand'>...</span><span class='operand'>val0</span></td><td><code class='instruction'>i</code></td><td></td></tr></table>', 723 => '<p>Pops the top value from the stack and the top procedure off the top of the procedure stack.', 724 => 'If the value is true (anything but <code>a</code>), the procedure is then executed.</p>', 725 => '', 726 => '<p>The value of the [[#i_-_If_Else_Count_Register|i register]] defines if-else chain, [[#i_-_If|i]] will pop enough values and procedure to satisfy that many conditions.</p>', 727 => '', 728 => '', 729 => '<h3 id='i-register'><span class='instruction'>i</span> - If Else Count Register</h3> <p>Determines how many if-else chains are present (if any).</p>', 730 => '<p>The default value of <code>a</code> (0), indicates there is no else to execute.', 731 => '[[#i_-_If|i]] will pop a single value and procedure.</p>', 732 => '<p>A value of <code>b</code>, indicates an else procedure.', 733 => '[[#i_-_If|i]] will pop one value and two procedures, the second procedure', 734 => 'being executed if the condition is not true.</p>', 735 => '<p>For higher values of the [[#i_-_If_Else_Count_Register|i register]], [[#i_-_If|i]] will', 736 => 'pop additional values off the stack and procedures, executing the procedure of the first', 737 => 'matching condition (or the last procedure if no conditions match).</p>', 738 => '', 739 => ''''Examples'''', 740 => '', 741 => 'Code:', 742 => '<pre>z xjajx yjkb l ao d t i p</pre>', 743 => '', 744 => '<p>Output: <code>a</code> or <code>z</code> based on user input.</p>', 745 => '', 746 => '<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>zxjajxyjkb</code>.</p>', 747 => '<p>[[#a_-_Arithmetic_Operation|a]] pops <code>bk</code>, adds them, and pushes <code>l</code> (this is because <code>l</code> cannot be used as a literal).</p>', 748 => '<p>[[#o_-_Overwrite|o]] pops <code>yjl</code> and preforms a replacement from <code>j</code> to <code>l</code>', 749 => 'until the end of the stack since there are no other <code>y</code> values on the stack.', 750 => 'All this results with a stack of <code>zxlalx</code>.</p>', 751 => '<p>[[#d_-_Define|d]] pops <code>xlalx</code> and pushes <code>lal</code> as a procedure. This procedure just pushes <code>a</code> onto the stack.</p>', 752 => '<p>[[#t_-_Text_Input|t]] reads a character from the user, converts it into a letter, and pushes it onto the stack.</p>', 753 => '<p>[[#i_-_If|i]] pops this user-generated value, the procedure, and if the value is true, the procedure is executed.', 754 => 'Now the stack is either <code>z</code> or <code>za</code>.</p>', 755 => '<p>[[#p_-_Print|p]] pops the top of the stack and prints it, printing <code>a</code> if', 756 => 'the user input evaluated as true, and <code>z</code> otherwise.</p>', 757 => '', 758 => 'Code:', 759 => '<pre>xjajx xjzjx yjkb ib l s ao dd t i p</pre>', 760 => '', 761 => '<p>This example has the same output as the previous one but it works slightly differently.</p>', 762 => '<p>The first operation after exiting literal mode is [[#s_-_Set|s]] to set [[#i_-_If_Else_Count_Register|i register]] to <code>b</code> (1).', 763 => 'This indicates that [[#i_-_If_Else_Count_Register|i register]] should use an else procedure.</p>', 764 => '<p>Now the next difference is that there are two procedures in the procedure stack: <code>lzl</code> and <code>lal</code>,', 765 => 'wich just push <code>z</code> or <code>a</code> onto the value stack.', 766 => 'Note that <code>lal</code> is the procedure on top of the stack because it has been pushed last.</p>', 767 => '<p>[[#i_-_If|i]] now pops both procedures off the procedure stack, executing the first on true and the second on false.</p>', 768 => '', 769 => 'Code:', 770 => '<pre>xjajx xjbjx xjcjx yjkb ic l s ao ddd tt lclf i p</pre>', 771 => '', 772 => '<p>This example takes 2 inputs from the user and selects one of 3 procedures to execute.</p>', 773 => '<p><code>tt</code> will read 2 inputs from the user and push them onto the stack.', 774 => 'since this will cause the inputs to be in reverse order (the last input is on top of the stack)', 775 => '<code>lclf</code> uses [[#f_-_Flip|f]] to flip them back around. Now the first', 776 => 'input is on top of the stack and the second input below it.</p>', 777 => '<p>The [[#i_-_If_Else_Count_Register|i register]] is set to <code>c</code> (2), indicating an else-if chain.</p>', 778 => '<p>[[#i_-_If|i]] now pops 2 values off the value stack and 3 procedures.', 779 => 'It uses the first value from the stack as the first condition, if that is true the first procedure is executed.', 780 => 'Otherwise, if the next value is true, the second procedure is executed.', 781 => 'Finally, if both values are false, the third procedure is executed.', 782 => '</p>', 783 => '', 784 => '<h3 id='k-instruction'><span class='instruction'>k</span> - Keep</h3>', 785 => '', 786 => ''''Synopsis'''', 787 => '', 788 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>k</code></td><td></td></tr></table>', 789 => '<p>Duplicates the procedure on top of the procedure stack.</p>', 790 => '', 791 => '<p>This is useful if you want to run [[#i_-_If|i]] or [[#x_-_Execute|x]] while keeping the procedure on the stack for later use.</p>', 792 => '', 793 => '<h3 id='k-register'><span class='instruction'>k</span> - Keep Count Register</h3> <p>Determines the number of procedures [[#k_-_Keep|k]] will copy.', 794 => 'The number is the value of this register plus one.</p>', 795 => '', 796 => ''''Example'''', 797 => '', 798 => 'Code:', 799 => '<pre>xpppjfoojx yjkb l ao d kxx</pre>', 800 => '', 801 => 'Output:', 802 => '<pre>foofoo</pre>', 803 => '', 804 => '<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>xpppjfoojxyjkb</code>.</p>', 805 => '<p>[[#a_-_Arithmetic_Operation|a]] and [[#o_-_Overwrite|o]] ensure <code>j</code> values on the stack are replaced by <code>l</code> as', 806 => '<code>l</code> cannot be used as a literal. The stack after them is <code>xppplfoolx</code></p>', 807 => '<p>[[#d_-_Define|d]] defines the procedure <code>looflppp</code>, which prints the string "foo" to output.</p>', 808 => '', 809 => '<p>Finally [[#k_-_Keep|k]] duplicates this procedure, and [[#x_-_Execute|x]] is called twice, popping and', 810 => 'executing the two copies of the procedure.</p>', 811 => '', 812 => '<h3 id='l-instruction'><span class='instruction'>l</span> - Literal</h3>', 813 => '', 814 => ''''Synopsis'''', 815 => '', 816 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>l</code></td><td></td></tr></table>', 817 => '<p>Switches between literal and instruction modes.</p>', 818 => '<p>Specifically it toggles the [[#l_-_Literal|l]] register between', 819 => '<code>a</code> (0), which indicated literal mode, and <code>b</code> (1), instruction mode.</p>', 820 => '', 821 => '<p>While in instruction mode all letters are executed as an instruction.</p>', 822 => '<p>In literal mode (which is the mode at the start of execution) letters are', 823 => 'pushed onto the value stack.</p>', 824 => '', 825 => '<p>[[#l_-_Literal|l]] will keep its behaviour in both modes so the letter <code>l</code>', 826 => 'cannot appear directly as a literal.</p>', 827 => '', 828 => '<h3 id='l-register'><span class='instruction'>l</span> - Mode Register</h3> <p>Determines whether the program is in literal mode or instruction mode.</p>', 829 => '', 830 => '<p>A value of <code>a</code> indicates literal mode, any other value is instruction mode.</p>', 831 => '', 832 => '<p>Generally it's toggled with [[#l_-_Literal|l]] but setting a value explicitly', 833 => 'using [[#s_-_Set|s]] will also switch between modes.</p>', 834 => '', 835 => ''''Example'''', 836 => '', 837 => 'Code:', 838 => '<pre>oof l ppp lrabl ppp</pre>', 839 => '', 840 => 'Output:', 841 => '<pre>foobar</pre>', 842 => '', 843 => '<p><code>oof</code> are pushed onto the stack because the program starts in literal mode.</p>', 844 => '<p>[[#l_-_Literal|l]] enables instruction mode and [[#p_-_Print|p]] is called 3 times', 845 => 'to print <code>foo</code> from the stack to the output.</p>', 846 => '<p>In <code>lrabl</code> literal mode is entered again to push <code>rab</code>', 847 => 'onto the stack, the last [[#l_-_Literal|l]] goes back into instruction mode.</p>', 848 => '<p>Finally [[#p_-_Print|p]] is called again to print <code>bar</code>.</p>', 849 => '', 850 => ''''Adding <code class="instruction">l</code> onto the stack'''', 851 => '', 852 => '<p>Since [[#l_-_Literal|l]] ends literal mode, values of <code>l</code>', 853 => 'cannot be directly added onto the stack, but some easy work-arounds are available.</p>', 854 => '', 855 => '<p>The most basic is to use addition to get an <code>l</code> from other values:</p>', 856 => '', 857 => '<pre>kb l a</pre>', 858 => '<p>Here [[#a_-_Arithmetic_Operation|a]] pops <code>k</code> and <code>b</code> from the stack,', 859 => 'adds them together, and pushes <code>l</code> (the result of this addition) back onto the stack.</p>', 860 => '', 861 => '<p>Sometimes you might want multiple <code>l</code> on the stack, this is especially useful when', 862 => 'defining procedures that need to output literal values on the stack.', 863 => 'You can achieve this by combining the previous approach with the overwrite instruction ([[#l_-_Literal|l]]):</p>', 864 => '', 865 => '<pre>jjj x jjj x j bk l ao</pre>', 866 => '<p>Here [[#a_-_Arithmetic_Operation|a]] does the same as it did before, replacing <code>bk</code> with <code>l</code>.</p>', 867 => '<p>[[#o_-_Overwrite|o]] pops <code>xjl</code>. It preforms a replacement from <code>j</code> to <code>l</code>', 868 => 'using <code>x</code> as delimiter. Both instances of the delimiter are removed from the stack.</p>', 869 => '<p>At the end the stack will be <code>jjjlll</code>, the first the <code>j</code> not being replaced because found', 870 => 'after the delimiter when searching from the top of the stack.</p>', 871 => '', 872 => '<h3 id='m-instruction'><span class='instruction'>m</span> - Memory</h3>', 873 => '', 874 => ''''Synopsis'''', 875 => '', 876 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>m</code></td><td><span class='operand'>val</span></td></tr></table>', 877 => '<p>Pushes the value of the [[#m_-_Memory_Cell_Register|m register]] onto the stack.</p>', 878 => '<p>This can be useful if there is a value that needs to be pushed onto the stack multiple time.</p>', 879 => '', 880 => '<h3 id='m-register'><span class='instruction'>m</span> - Memory Cell Register</h3> <p>Doesn't have any special meaning, pushed onto the stack by [[#m_-_Memory|m]].</p>', 881 => '', 882 => ''''Examples'''', 883 => '', 884 => 'Code:', 885 => '<pre>lmmmppp</pre>', 886 => '', 887 => 'Output:', 888 => '<pre>aaa</pre>', 889 => '', 890 => '<p>[[#l_-_Literal|l]] enables instruction mode.</p>', 891 => '<p>[[#m_-_Memory|m]] is called 3 times and pushes the default value (<code>a</code>) onto the stack each time.</p>', 892 => '<p>[[#p_-_Print|p]] is called 3 times, popping the 3 values and printing them.</p>', 893 => '', 894 => 'Code:', 895 => '<pre>mz l s mmmppp</pre>', 896 => '', 897 => 'Output:', 898 => '<pre>zzz</pre>', 899 => '', 900 => '<p>Same as before but [[#s_-_Set|s]] uses the <code>z</code> and <code>m</code> values', 901 => 'from the stack to set the [[#m_-_Memory_Cell_Register|m register]] to <code>z</code>.</p>', 902 => '', 903 => '<h3 id='n-instruction'><span class='instruction'>n</span> - Number of Items</h3>', 904 => '', 905 => ''''Synopsis'''', 906 => '', 907 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>n</code></td><td><span class='operand'>count</span></td></tr></table>', 908 => '<p>Pushed onto the stack the number of items currently on the stack</p>', 909 => '', 910 => '<h3 id='n-register'><span class='instruction'>n</span> - Number Size Register</h3>', 911 => '', 912 => '<p>Number of letters per number, see [[Multi-Letter_Numbers|multi-letter numbers]] in advanced concepts.</p>', 913 => '', 914 => ''''Examples'''', 915 => '', 916 => 'Code:', 917 => '<pre>foobar l nf</pre>', 918 => '', 919 => '<p><code>foobar</code> is pushed onto the stack, then [[#n_-_Number_of_Items|n]] pushes', 920 => 'the stack count <code>g</code> (6) onto the stack.', 921 => 'Finally [[#f_-_Flip|f]] pops that value and flips the whole stack.</p>', 922 => '', 923 => 'Code:', 924 => '<pre>foobar xpx l d n f n r</pre>', 925 => '', 926 => 'Output:', 927 => '<pre>foobar</pre>', 928 => '', 929 => '<p><code>foobarxpx</code> is pushed onto the value stack, then [[#d_-_Define|d]] pops <code>xpx</code> to push <code>p</code> on the procedure stack.</p>', 930 => '<p>As before [[#n_-_Number_of_Items|n]] followed by [[#f_-_Flip|f]] flips the entire stack.', 931 => 'Finally [[#n_-_Number_of_Items|n]] followed by [[#r_-_Repeat|r]] repeats the print', 932 => 'procedure for each item on the stack.</p>', 933 => '', 934 => '<p>Note that this works up to a value of <code>z</code> (25).</p>', 935 => '', 936 => '<h3 id='o-instruction'><span class='instruction'>o</span> - Overwrite</h3>', 937 => '', 938 => ''''Synopsis'''', 939 => '', 940 => '<table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span><span class='operand'>search</span><span class='operand'>replace</span></td><td><code class='instruction'>o</code></td><td><span class='operand'>...</span></td></tr></table>', 941 => '<p>Replaces values on the stack until a delimiter is reached.</p>', 942 => '', 943 => '<p>Pops <code>replace</code> and <code>search</code> from the stack.', 944 => 'Then replaces all instanced of <code>search</code> between the two <code>mark</code>', 945 => 'with <code>replace</code>.</p>', 946 => '', 947 => '<p>If the second <code>mark</code> is not found, all occurrences of <code>search</code> will be replaced.</p>', 948 => '', 949 => '<p>The two <code>mark</code> are removed from the stack by default but they can be preserved', 950 => 'depending on the value of the [[#o_-_Keep_Mark_Register|o register]].</p>', 951 => '', 952 => '<h3 id='o-register'><span class='instruction'>o</span> - Keep Mark Register</h3> <p>By default [[#o_-_Overwrite|o]] deleted the markers from the stack, if this', 953 => 'register has a value other than <code>a</code>, they are kept.</p>', 954 => '', 955 => ''''Example'''', 956 => '', 957 => 'Code:', 958 => '<pre>test x test x t b l o</pre>', 959 => '', 960 => '<p>All the values until [[#l_-_Literal|l]] are pushed onto the stack.</p>', 961 => '<p>[[#o_-_Overwrite|o]] pops <code>xtb</code> from the stack, and replaces', 962 => 'all <code>t</code> into <code>b</code> until the next <code>x</code> is found.</p>', 963 => '<p>This results in the stack ending with <code>testbesb</code>.</p>', 964 => '<p>Note that the value <code>x</code> is arbitrary, any letter can work as a marker.</p>', 965 => '', 966 => '', 967 => 'Code:', 968 => '<pre>test x test x t b ob l s o</pre>', 969 => '', 970 => '<p>Similar as before, now [[#s_-_Set|s]] pops <code>ob</code>', 971 => 'and sets the [[#o_-_Keep_Mark_Register|o register]] to <code>b</code>.</p>', 972 => '', 973 => '<p>The rest works the same except the markers are kept, resulting in <code>testxbesbx</code>.</p>', 974 => '', 975 => '<h3 id='p-instruction'><span class='instruction'>p</span> - Print</h3>', 976 => '', 977 => ''''Synopsis'''', 978 => '', 979 => '<table class="wikitable synopsis"><tr><td><span class='operand'>val</span></td><td><code class='instruction'>p</code></td><td></td></tr></table>', 980 => '<p>Pops a letter from the stack and prints it to output.</p>', 981 => '', 982 => '<p>By default prints them as lower case letters but this can changed based on the value of the [[#p_-_Print_Mode_Register|p register]].</p>', 983 => '', 984 => '<h3 id='p-register'><span class='instruction'>p</span> - Print Mode Register</h3> <p>Specifies the print mode, depending on the mode letters are printed differently.</p>', 985 => '<p>Using the right combination of printed letter and mode, any ASCII character can be printed.</p>', 986 => '', 987 => '<table class="wikitable print-mode mono">', 988 => ' <caption>Print Modes</caption>', 989 => ' <tr><th rowspan="2">Letter</th><th colspan="5">Mode</th></tr>', 990 => ' <tr><th>a</th> <th>b</th> <th>c</th> <th>d</th> <th>e</th></tr>', 991 => ' <tr><th>a</th><td class='print-mode'>a</td><td class='print-mode'>A</td><td class='print-mode'>0</td><td class='print-mode'>!</td><td class='print-mode'>NUL</td></tr>', 992 => ' <tr><th>b</th><td class='print-mode'>b</td><td class='print-mode'>B</td><td class='print-mode'>1</td><td class='print-mode'>&quot;</td><td class='print-mode'>x01</td></tr>', 993 => ' <tr><th>c</th><td class='print-mode'>c</td><td class='print-mode'>C</td><td class='print-mode'>2</td><td class='print-mode'>#</td><td class='print-mode'>x02</td></tr>', 994 => ' <tr><th>d</th><td class='print-mode'>d</td><td class='print-mode'>D</td><td class='print-mode'>3</td><td class='print-mode'>$</td><td class='print-mode'>x03</td></tr>', 995 => ' <tr><th>e</th><td class='print-mode'>e</td><td class='print-mode'>E</td><td class='print-mode'>4</td><td class='print-mode'>%</td><td class='print-mode'>x04</td></tr>', 996 => ' <tr><th>f</th><td class='print-mode'>f</td><td class='print-mode'>F</td><td class='print-mode'>5</td><td class='print-mode'>&amp;</td><td class='print-mode'>x05</td></tr>', 997 => ' <tr><th>g</th><td class='print-mode'>g</td><td class='print-mode'>G</td><td class='print-mode'>6</td><td class='print-mode'>&apos;</td><td class='print-mode'>x06</td></tr>', 998 => ' <tr><th>h</th><td class='print-mode'>h</td><td class='print-mode'>H</td><td class='print-mode'>7</td><td class='print-mode'>(</td><td class='print-mode'>x07</td></tr>', 999 => ' <tr><th>i</th><td class='print-mode'>i</td><td class='print-mode'>I</td><td class='print-mode'>8</td><td class='print-mode'>)</td><td class='print-mode'>x08</td></tr>', 1000 => ' <tr><th>j</th><td class='print-mode'>j</td><td class='print-mode'>J</td><td class='print-mode'>9</td><td class='print-mode'>*</td><td class='print-mode'>HT</td></tr>', 1001 => ' <tr><th>k</th><td class='print-mode'>k</td><td class='print-mode'>K</td><td class='print-mode'>:</td><td class='print-mode'>+</td><td class='print-mode'>LF</td></tr>', 1002 => ' <tr><th>l</th><td class='print-mode'>l</td><td class='print-mode'>L</td><td class='print-mode'>;</td><td class='print-mode'>,</td><td class='print-mode'>x0b</td></tr>', 1003 => ' <tr><th>m</th><td class='print-mode'>m</td><td class='print-mode'>M</td><td class='print-mode'>&lt;</td><td class='print-mode'>-</td><td class='print-mode'>x0c</td></tr>', 1004 => ' <tr><th>n</th><td class='print-mode'>n</td><td class='print-mode'>N</td><td class='print-mode'>=</td><td class='print-mode'>.</td><td class='print-mode'>CR</td></tr>', 1005 => ' <tr><th>o</th><td class='print-mode'>o</td><td class='print-mode'>O</td><td class='print-mode'>&gt;</td><td class='print-mode'>/</td><td class='print-mode'>x0e</td></tr>', 1006 => ' <tr><th>p</th><td class='print-mode'>p</td><td class='print-mode'>P</td><td class='print-mode'>?</td><td class='print-mode'>@</td><td class='print-mode'>x0f</td></tr>', 1007 => ' <tr><th>q</th><td class='print-mode'>q</td><td class='print-mode'>Q</td><td class='print-mode'>x1a</td><td class='print-mode'>[</td><td class='print-mode'>x10</td></tr>', 1008 => ' <tr><th>r</th><td class='print-mode'>r</td><td class='print-mode'>R</td><td class='print-mode'>ESC</td><td class='print-mode'>\</td><td class='print-mode'>x11</td></tr>', 1009 => ' <tr><th>s</th><td class='print-mode'>s</td><td class='print-mode'>S</td><td class='print-mode'>x1c</td><td class='print-mode'>]</td><td class='print-mode'>x12</td></tr>', 1010 => ' <tr><th>t</th><td class='print-mode'>t</td><td class='print-mode'>T</td><td class='print-mode'>x1d</td><td class='print-mode'>^</td><td class='print-mode'>x13</td></tr>', 1011 => ' <tr><th>u</th><td class='print-mode'>u</td><td class='print-mode'>U</td><td class='print-mode'>x1e</td><td class='print-mode'>_</td><td class='print-mode'>x14</td></tr>', 1012 => ' <tr><th>v</th><td class='print-mode'>v</td><td class='print-mode'>V</td><td class='print-mode'>x1f</td><td class='print-mode'>`</td><td class='print-mode'>x15</td></tr>', 1013 => ' <tr><th>w</th><td class='print-mode'>w</td><td class='print-mode'>W</td><td class='print-mode'>SP</td><td class='print-mode'>{</td><td class='print-mode'>x16</td></tr>', 1014 => ' <tr><th>x</th><td class='print-mode'>x</td><td class='print-mode'>X</td><td class='print-mode'>x7f</td><td class='print-mode'>|</td><td class='print-mode'>x17</td></tr>', 1015 => ' <tr><th>y</th><td class='print-mode'>y</td><td class='print-mode'>Y</td><td class='print-mode'></td><td class='print-mode'>}</td><td class='print-mode'>x18</td></tr>', 1016 => ' <tr><th>z</th><td class='print-mode'>z</td><td class='print-mode'>Z</td><td class='print-mode'></td><td class='print-mode'>~</td><td class='print-mode'>x19</td></tr> </table>', 1017 => '', 1018 => '<p>The special mode <code>z</code> will cause [[#p_-_Print_Mode_Register|p register]] to not', 1019 => 'print anything turning it into a pop operation.</p>', 1020 => '', 1021 => ''''Examples'''', 1022 => '', 1023 => 'Code:', 1024 => '<pre>tnirp l ppppp</pre>', 1025 => '', 1026 => 'Output:', 1027 => '<pre>print</pre>', 1028 => '', 1029 => '<p>All the values until [[#l_-_Literal|l]] are pushed onto the stack', 1030 => 'then [[#p_-_Print_Mode_Register|p register]] is called multiple times, each time', 1031 => 'it pops a value off the stack and prints it.</p>', 1032 => '<p>Note that since [[#p_-_Print_Mode_Register|p register]] prints off the top of the stack,', 1033 => 'the stack values need to be in reverse order to be printed.</p>', 1034 => '', 1035 => 'Code:', 1036 => '<pre>tnirp pb l s ppppp</pre>', 1037 => '', 1038 => 'Output:', 1039 => '<pre>PRINT</pre>', 1040 => '', 1041 => '<p>Similar as before, now [[#s_-_Set|s]] pops <code>pb</code>', 1042 => 'and sets the [[#p_-_Print_Mode_Register|p register]] to <code>b</code>, switching to uppercase print mode.</p>', 1043 => '', 1044 => 'Code:', 1045 => '<pre>hddb pc l s pppp</pre>', 1046 => '', 1047 => 'Output:', 1048 => '<pre>1337</pre>', 1049 => '', 1050 => '<p>Print mode <code>c</code> can be used to print numbers.</p>', 1051 => '', 1052 => 'Code:', 1053 => '<pre>tnirp pz l s ppppp</pre>', 1054 => '', 1055 => '(No Output)', 1056 => '', 1057 => '<p>Print mode <code>z</code> can be used to pop values off the stack without printing them.</p>', 1058 => '', 1059 => 'Code:', 1060 => '<pre>a pd djro pa w pb w pc ojje xjbk pa h pb l sps ao pppp spsps pppp sp</pre>', 1061 => '', 1062 => 'Output:', 1063 => '<pre>Hello World!</pre>', 1064 => '', 1065 => '<p>Does the usual trick to replace <code>l</code> (see [[#l_-_Literal|l]] examples).', 1066 => 'Then keeps switching print modes and printing values from the stack.</p>', 1067 => '', 1068 => '<h3 id='r-instruction'><span class='instruction'>r</span> - Repeat</h3>', 1069 => '', 1070 => ''''Synopsis'''', 1071 => '', 1072 => '<table class="wikitable synopsis"><tr><td><span class='operand'>count</span></td><td><code class='instruction'>r</code></td><td></td></tr></table>', 1073 => '<p>Pops <code>count</code> and the top procedure from the procedure stack and executes', 1074 => 'said procedure <code>count</code> times. A count of <code>a</code> (0) means infinite loop.</p>', 1075 => '', 1076 => ''''Example'''', 1077 => '', 1078 => 'Code:', 1079 => '<pre>tset e xpx l dr</pre>', 1080 => '', 1081 => 'Output:', 1082 => '<pre>test</pre>', 1083 => '', 1084 => '<p>After [[#l_-_Literal|l]] the stack contains <code>tsetexpx</code>.</p>', 1085 => '<p>[[#d_-_Define|d]] pops <code>xpx</code> from the value stack and pushes <code>p</code> on the procedure stack.</code>', 1086 => '<p>[[#r_-_Repeat|r]] pops <code>e</code> (4) from the value stack,', 1087 => 'the procedure from the procedure stack and repeats it 4 times, printing the 4 remaining letters on the stack.</p>', 1088 => '', 1089 => '<h3 id='s-instruction'><span class='instruction'>s</span> - Set</h3>', 1090 => '', 1091 => ''''Synopsis'''', 1092 => '', 1093 => '<table class="wikitable synopsis"><tr><td><span class='operand'>reg</span><span class='operand'>val</span></td><td><code class='instruction'>s</code></td><td></td></tr></table>', 1094 => '<p>Pops <code class="operand">reg</code> and <code class="operand">val</code> from the stack,', 1095 => 'then sets the corresponding register to <code class="operand">val</code>.</p>', 1096 => '', 1097 => ''''Example'''', 1098 => '', 1099 => 'Code:', 1100 => '<pre>m mf l s g</pre>', 1101 => '<p>Values are pushed onto the stack until [[#l_-_Literal|l]], resulting in the stack containing <code>mmf</code>.</p>', 1102 => '<p>[[#s_-_Set|s]] pops <code>mf</code> and sets the [[#m_-_Memory_Cell_Register|m register]] to <code>f</code>.</p>', 1103 => '<p>[[#g_-_Get|g]] pops <code>m</code> and pushes its value (<code>f</code>) onto the stack, resulting in a stack with <code>f</code>.</p>', 1104 => '', 1105 => '', 1106 => '<h3 id='t-instruction'><span class='instruction'>t</span> - Text Input</h3>', 1107 => '', 1108 => ''''Synopsis'''', 1109 => '', 1110 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>t</code></td><td><span class='operand'>val?</span></td></tr></table>', 1111 => '<p>Pushes a letter onto the stack based on user input.</p>', 1112 => '', 1113 => '<p>Reads one character from the input stream, converts into a', 1114 => 'letter using the reverse operation of [[#p_-_Print|p]] and sets the [[#t_-_Read_Result_Register|t register]] to the print mode that would', 1115 => 'yield that character.</p>', 1116 => '', 1117 => '<p>On failure (end of file or invalid character) it sets the', 1118 => '[[#t_-_Read_Result_Register|t register]] to <code>z</code> and doesn't push anything', 1119 => 'onto the stack.</p>', 1120 => '', 1121 => '<h3 id='t-register'><span class='instruction'>t</span> - Read Result Register</h3> <p>Holds the status of the last [[#t_-_Text_Input|t]] operation.', 1122 => 'Basically if you want to print back the same character you need to set', 1123 => 'the [[#p_-_Print_Mode_Register|p register]] to the value of the [[#t_-_Read_Result_Register|t register]].', 1124 => 'The special value of <code>z</code> indicates an error.', 1125 => 'Refer to the documentation of the [[#p_-_Print_Mode_Register|p register]] for a description of values.</p>', 1126 => '', 1127 => ''''Example'''', 1128 => '', 1129 => 'Code:', 1130 => '<pre>lt</pre>', 1131 => '', 1132 => '<p>[[#l_-_Literal|l]] exits literal mode, then [[#t_-_Text_Input|t]] reads one character', 1133 => 'from input. Follow a few examples of the end state based on the input.</p>', 1134 => '', 1135 => '<p>If the user typed <code>h</code>, the [[#t_-_Read_Result_Register|t register]] holds the value <code>a</code> and', 1136 => 'the stack the value <code>h</code>.</p>', 1137 => '', 1138 => '<p>If the user typed <code>H</code>, the stack still holds the value <code>h</code>', 1139 => 'but now the [[#t_-_Read_Result_Register|t register]] has the value <code>b</code> which corresponds to the', 1140 => 'upper case print mode.</p>', 1141 => '', 1142 => '<p>If the user typed <code>3</code>, the stack still holds the value <code>d</code>', 1143 => 'but now the [[#t_-_Read_Result_Register|t register]] has the value <code>c</code> which corresponds to the', 1144 => 'number print mode.</p>', 1145 => '', 1146 => '<p>If the input reached end of file, the [[#t_-_Read_Result_Register|t register]] will have the value <code>z</code>', 1147 => 'and the stack will be empty.</p>', 1148 => '', 1149 => '<h3 id='u-instruction'><span class='instruction'>u</span> - Undo</h3>', 1150 => '', 1151 => ''''Synopsis'''', 1152 => '', 1153 => '<table class="wikitable synopsis"><tr><td><span class='operand'>mark</span><span class='operand'>...</span><span class='operand'>mark</span></td><td><code class='instruction'>u</code></td><td></td></tr></table>', 1154 => '<p>Pops everything on the stack until <code>mark</code> is found.</p>', 1155 => '', 1156 => '<p>Starts by popping <code>mark</code>, that can be any letter.', 1157 => 'Then it keeps popping until it finds another value of <code>mark</code>', 1158 => 'or the stack is empty.</p>', 1159 => '', 1160 => ''''Example'''', 1161 => '', 1162 => 'Code:', 1163 => '<pre>foobartest l u</pre>', 1164 => '', 1165 => '<p>Before [[#u_-_Undo|u]] is executed, the stack contains <code>foobartest</code>.</p>', 1166 => '<p>[[#u_-_Undo|u]] pops a <code>t</code> then keeps popping until the following', 1167 => '<code>t</code> is popped, then stops. At the end the stack holds <code>foobar</code></p>', 1168 => '', 1169 => '<h3 id='w-instruction'><span class='instruction'>w</span> - Wrap</h3>', 1170 => '', 1171 => ''''Synopsis'''', 1172 => '', 1173 => '<table class="wikitable synopsis"><tr><td><span class='operand'>...</span><span class='operand'>count</span><span class='operand'>steps</span></td><td><code class='instruction'>w</code></td><td><span class='operand'>...</span></td></tr></table>', 1174 => '<p>Wraps the top <code>count</code> items of the stack by <code>steps</code> steps.</p>', 1175 => '', 1176 => '<p>Starts by popping <code>count</code> and <code>steps</code> from the value stack.', 1177 => 'Then it pops <code>count</code> more items, which will be the operands of the wrap operation.</p>', 1178 => '', 1179 => '<p>A wrap step consists on moving the first operand to the back of the list of operands.', 1180 => 'This is applied <code>steps</code> times.</p>', 1181 => '', 1182 => '<p>After all the steps, the operands are pushed back onto the stack in their new order.</p>', 1183 => '', 1184 => ''''Examples'''', 1185 => '', 1186 => 'Code:', 1187 => '<pre>foobar db l w</pre>', 1188 => '', 1189 => '<p>Here [[#w_-_Wrap|w]] performs <code>b</code> (1) step on', 1190 => 'the top <code>d</code> items, which are <code>bar</code>.', 1191 => 'This turns <code>bar</code> into <code>rba</code> as the <code>r</code>', 1192 => 'is moved to the back.</p>', 1193 => '', 1194 => '<p>At the end the stack contains <code>foorba</code>.</p>', 1195 => '', 1196 => 'Code:', 1197 => '<pre>foobar dc l w</pre>', 1198 => '', 1199 => '<p>The only change is the number of steps, resulting in a stack with <code>fooarb</code>.</p>', 1200 => '', 1201 => '<h3 id='x-instruction'><span class='instruction'>x</span> - Execute</h3>', 1202 => '', 1203 => ''''Synopsis'''', 1204 => '', 1205 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>x</code></td><td></td></tr></table>', 1206 => '<p>Pops and executes the top procedure.</p>', 1207 => '', 1208 => ''''Example'''', 1209 => '', 1210 => 'Code:', 1211 => '<pre>abc qppq l d x p</pre>', 1212 => '', 1213 => 'Output:', 1214 => '<pre>cba</pre>', 1215 => '', 1216 => '<p>After [[#l_-_Literal|l]] the stack contains <code>abcqppq</code>.</p>', 1217 => '<p>[[#d_-_Define|d]] pops <code>qppq</code> and pushes <code>pp</code>', 1218 => 'onto the procedure stack.</p>', 1219 => '<p>[[#x_-_Execute|x]] pops this procedure and executes it.', 1220 => 'the procedure calls [[#p_-_Print|p]] twice printing <code>cb</code>.</p>', 1221 => '<p>Finally execution continues after [[#x_-_Execute|x]], where an additional', 1222 => 'call to [[#p_-_Print|p]] prints <code>a</code>.</p>', 1223 => '', 1224 => '', 1225 => '<h3 id='y-instruction'><span class='instruction'>y</span> - Yield</h3>', 1226 => '', 1227 => ''''Synopsis'''', 1228 => '', 1229 => '<table class="wikitable synopsis"><tr><td></td><td><code class='instruction'>y</code></td><td></td></tr></table>', 1230 => '<p>Stops execution of the current procedure, leaving the stack unchanged</p>', 1231 => '', 1232 => ''''Example'''', 1233 => '', 1234 => 'Code:', 1235 => '<pre>abc qpypq l d x p</pre>', 1236 => '', 1237 => 'Output:', 1238 => '<pre>cb</pre>', 1239 => '', 1240 => '<p>This is the same as the example for [[#x_-_Execute|x]] with the exception of the presence of [[#y_-_Yield|y]] in the middle of the procedure, which causes the second [[#p_-_Print|p]] to not be executed.</p>', 1241 => '', 1242 => '<h2>Advanced Concept</h2>', 1243 => '', 1244 => '<h3 id="multi-letter-numbers">Multi-Letter Numbers</h3>', 1245 => '', 1246 => '<p>By default each letter represents a number in base 26.', 1247 => 'Sometimes values between 0 and 25 are not enough.', 1248 => 'You can enable a mode that uses multiple letters per number by setting the [[#n_-_Number_Size_Register|n register]] to', 1249 => 'a higher value, the number of letters per numer is [[#n_-_Number_of_Items|n]] + 1.</p>', 1250 => '', 1251 => '<p>This affects the condition inputs for [[#i_-_If|i]], the output of [[#n_-_Number_of_Items|n]], and', 1252 => 'both inputs and outputs of [[#a_-_Arithmetic_Operation|a]].</p>', 1253 => '', 1254 => '<p>When multi-number letters are used, the most significant letter is on the stack.', 1255 => 'For example if the stack contains <code>te</code> (<code>e</code> being at the top of the stack)', 1256 => 'and there are 2 letters per number ([[#n_-_Number_Size_Register|n register]] set to <code>b</code>),', 1257 => 'The numerical value is calculated as <code>26 * e + t</code>, with all numbers <code>26 * 4 + 19</code>, which is 123.</p>', 1258 => '', 1259 => '<h2>External Links</h2>', 1260 => '', 1261 => '* [https://dragon.best/alphastack/#playground web-based playground]', 1262 => '* [https://gitlab.com/mattia.basaglia/dragon.best/-/blob/master/media/scripts/alphastack/alphastack.py Python implementation]' ]
Unix timestamp of change (timestamp)
'1775906156'