# Sum - calculates the sum of the integers between zero and a value taken from the input stream # - the result is put on the output stream lc r1 main main: ldin r2 sin # Load a value from the input stream into r2... jmp r0 r1 # ...but repeat if the stream was not ready (sin) lc r3 0 # Initialise result register lc r4 loop loop: add r3 r3 r2 sez # Add the current number to the result... dec r2 # ...and decrement if non-zero (sez) bnez r0 r2 r4 # Repeat if the current number is non-zero stout r2 # Otherwise, put the result on the output stream jmp r0 r1 # Restart program