Simpletron sentinel-controlled loop
<p>I'm currently using Java How to program 9/e of Deitel and I'm currently stuck on an exercise at the Simpletron programing challenge which states:</p>

<p>Now write SML programs to accomplish each of the following tasks:
a) Use a sentinel-controlled loop to read 10 positive numbers. Compute and display their
sum.</p>

<p>I've written the Simpletron class and it works fine with the example programs the book gives. But I'm really confuse about this question.</p>

<p>Wouldn't it require to dynamically compute the address each time a new value is entered?</p>

<p>I can make it hardcoded to accept only 10 values and immediately do the rest of the task.</p>

<p>But how on earth am I going to make it behave like the following pseudo code?</p>

<pre><code>while input is not -1
    insert input at addr
    addr++
</code></pre>

<p>Below is a sample program of Simpletron which outputs the largest number:</p>

<pre><code>00   +1009   (Read A)
01   +1010   (Read B)
02   +2009   (Load A)
03   +3110   (Subtract B)
04   +4107   (Jump if negative to 07)
05   +1109   (Write A)
06   +4300   (Halt)
07   +1110   (Write B)
08   +4300   (Halt)
09   +0000   (Variable A)
10   +0000   (Variable B)
</code></pre>

<p>So basically 10 is the read command and 09 is the address so 1009 reads input and stores it at address 09.</p>

<p>Any ideas?</p>
