Simple/Decimal Computer Examples

Here are a couple of introductory Simple/Decimal Computer examples
  1. Read in two input values, and display their sum on the output. Program starting address is 20.
    040 - 041 - 440 - 241 - 542 - 142 - 900

  2. Count from 1-3 displaying each value on the output. Program starting address in 40.
    400 - 510 - 110 - 200 - 510 - 110 - 200 - 510 - 110 - 900

  3. Count from 1-? displaying each value on the output (infinite loop). Program starting address is 30.
    400 - 510 - 110 - 200 - 631

  4. Count from -x to 0, displaying each value on the output (loop with test). -x is stored in cell 19; program starting address is 20.
    419 - 200 - 518 - 118 - 721 - 900

  5. Add together n input values and display their sum on the output. n is prestored in location 5 and the program starting address is 20.
    405 - 300 - 505 - 729 - 090 - 491 - 290 - 591 - 620 - 191 - 900

    In programs like this it is recommended that one first initialize the memory cell that is to serve as the running total (i.e. cell 91) to zero. The code to do this is: 400 - 300 - 591

Here is the sum n values program, properly annotated:

Cell 5: loop counter: initialized from input
Cell 10: sum: initialized to zero
Cell 11: current value read in from input
Cell 20: Starting address of the program

Cell Code Comment
20 005 Read in counter: number of values to sum
21 400 Cells 21-23: zero out sum (cell 10)
22 300
23 510
24 405 Cells 24-26: Decrement counter (cell 5)
25 300
26 505
27 740 Test if done: counter is negative
28 630 Goto iteration of loop: add in another value
30 011 Read in value to sum (cell 11)
31 410 Put sum into ACC
32 211 Add new value to Sum
33 510 Store off new value of sum (cell 10)
34 624 Go test loop counter
40 110 Output sum (cell 10)
41 900 TTFT