The right shows how we can find the nth

The user will need to input a
number which will be stored in three different locations, one that will be used
for calculations, one for reference so that it cannot be modified and the last
one for is used for the counter. First we will need calculate the square of the
number that has been inserted by the user by adding it to itself. We use a loop
for this so that the action continues to take place until the counter reaches
zero where this action will then terminate. Next, we will need to add the input number to
the square number that has just been calculated and hence this new value is
stored in the memory location one. We do this due to the fact that brackets
will need to be expanded before we look at the rest of the equation which is a
rule of BODMAS. Lastly, division has to be carried out in one of the memory
location in this case its location 2. In order for division to take place we
will subtract two from location one until it reaches zero. This process will
continue to keep, adding, subtracting and dividing until the loop has finally
reached a zero where the program will terminate so that the counter can load
and show the output in the computer. The flowchart on the right shows how
we can find the nth triangle number. After the program is compiled, you
should see from mailbox 0 to 99 the instructions 901, 323, 526 and so on. 
The program counter will start at 0. Furthermore, DAT reserves mailbox 88 for c
(the user input), mailbox 87 for b (the value of the current triangular
number), mailbox 86 for a (the number of triangular numbers that have
been calculated), mailbox 89 for zero and mailbox 90 for one. Once we click on
‘Run’ and ‘Step’ the program will start taking actions. Firstly, program will
accept the input ‘a’ from the user and initialise the values of ‘b’ and ‘c’ to
‘zero’. The algorithm will then be able to calculate triangular number until
the calculated triangular number is greater than or equal to the input value.
The output will be ‘c’ when the triangular number is equal to the input or else
it would show an output of zero. Next, the ‘LOOP’ will start where the input
‘a’ is subtracted from ‘b’. If the result is negative, then the LMC will stay
in the loop. In order to calculate the next triangular number, ‘c’ is increased
by one, and this new value of ‘c’ will be then added to b.  It is also important to know that the BR LOOP
indicates the end of the loop body; this is where the BRANCH command causes the
execution of the LMC to “jump” back to the start of the loop. Once
the LOOP has ended, the value of ‘b’ should be greater than or equal to the
input ‘a’. We use the SUB (subtract) instruction is to check if ‘b’ and ‘a’ are
equal and if they are equal, subtracting ‘b’ from ‘a’ will equal 000.  Branch if zero (BRZ) will allow the LMC to
skip past the code section that handles when these two values are not
equal.  The LMC will then execute the
code segment that outputs ‘c’ to the Out-Box where the input ‘a’ is the Nth
triangular number. However, if they are not equal, then the result on the
Accumulator will not be 000, and thus BRZ will do nothing.  The code after the BRZ instruction is
executed; outputting zero to the Out-Box.