<code>BUTTONS</code> is a tiny computer that you can program entirely with a 2 button mouse by clicking on buttons.
<code>BUTTONS</code> is a tiny computer that you can program entirely with a 2 button mouse by clicking on buttons.
@ -57,7 +57,7 @@
plates <code>done plates</code>.</p>
plates <code>done plates</code>.</p>
<p>You would probably take the first plate off the top of the stack of
<p>You would probably take the first plate off the top of the stack of
plates, write the number <code>1</code> on it, and then set it to the
<code>new plates</code>, write the number <code>1</code> on it, and then set it to the
side in the <code>done plates</code> stack. You can't put it back on the
side in the <code>done plates</code> stack. You can't put it back on the
<code>new plates</code> stack of plates because then you wouldn't make
<code>new plates</code> stack of plates because then you wouldn't make
your way through the plates. You take one off the <code>top</code> of
your way through the plates. You take one off the <code>top</code> of
@ -67,7 +67,7 @@
going through all 10 plates.</p>
going through all 10 plates.</p>
<p>You then look over at your stack of numbered <code>done plates</code>
<p>You then look over at your stack of numbered <code>done plates</code>
and you're happy, but the plate on <code>top</code> is numbered 20.
and you're happy, but the plate on <code>top</code> is numbered 10.
You've stacked them in reverse, and you probably need to re-stack them in
You've stacked them in reverse, and you probably need to re-stack them in
order. How would you do that? Well, you simply take one off the top of
order. How would you do that? Well, you simply take one off the top of
the <code>done stack</code> and put it onto another stack (let's call
the <code>done stack</code> and put it onto another stack (let's call
@ -159,13 +159,13 @@
When you see the <code>0:</code> at the front of the line that's the line number. It's not code, just me being lazy and not wanting to implement line numbers in fancy CSS.
When you see the <code>0:</code> at the front of the line that's the line number. It's not code, just me being lazy and not wanting to implement line numbers in fancy CSS.
</blockquote>
</blockquote>
<h2>TICKS</h2>
<h2>CLICKS</h2>
<p>Before we get into loops I have to warn you that <code>BUTTONS</code>
<p>Before we get into loops I have to warn you that <code>BUTTONS</code>
is not a very powerful computer. It can only perform <code>128</code>
is not a very powerful computer. It can only perform <code>128</code>
operations before it runs out of energy called <code>TICKS</code>. If
operations before it runs out of energy called <code>CLICKS</code>. If
your computer runs this many ticks then <code>BUTTONS</code> will stop
your program runs for 128 many clicks then <code>BUTTONS</code> will stop
running and give up.</p>
running and give up because it is tired.</p>
<h2>Looping with JUMP</h2>
<h2>Looping with JUMP</h2>
@ -216,7 +216,7 @@
<p>You run it, thinking it will stop at zero, and instead
<p>You run it, thinking it will stop at zero, and instead
<code>BUTTONS</code> does exactly what you told it to do and keeps going
<code>BUTTONS</code> does exactly what you told it to do and keeps going
until it runs out of <code>TICKS</code>, leaving .... <code>-32</code> on
until it runs out of <code>CLICKS</code>, leaving .... <code>-32</code> on
the top? What?!</p>
the top? What?!</p>
<p>The reason is you have no way to tell <code>BUTTONS</code> when to stop. You can tell it to do the math and where to <code>JUMP</code> but you have no way to tell buttons "when you reach 0 on the <code>STACK</code> you should stop." You do this with the <code>JZ</code> operation which means "<code>JUMP if Zero</code>". It simply looks at the top of the <code>STACK</code> and if that's 0 then it does a <code>JUMP</code> to where you want. This is doing a test of the top of stack, and a jump. Now we can rewrite our program like this:</p>
<p>The reason is you have no way to tell <code>BUTTONS</code> when to stop. You can tell it to do the math and where to <code>JUMP</code> but you have no way to tell buttons "when you reach 0 on the <code>STACK</code> you should stop." You do this with the <code>JZ</code> operation which means "<code>JUMP if Zero</code>". It simply looks at the top of the <code>STACK</code> and if that's 0 then it does a <code>JUMP</code> to where you want. This is doing a test of the top of stack, and a jump. Now we can rewrite our program like this:</p>