This program computes y = 2x
[0] LOD #1 ; ACC=1 [2] STO Y ; Y=1 [4] CPZ X ; X=0 ? [6] JMZ #10 ; NO, proceed [8] HLT ; YES, stop [10] LOD Y ; ACC=Y [12] MUL #2 ; ACC=Y*2 [14] STO Y ; p = Y*2 [16] LOD X ; ACC=X [18] SUB #1 ; ACC=X-1 [20] STO X ; X = X-1 [22] JMP #4 ; jump to instruction in cell [4] [X] 4 ; storage for x [Y] 0 ; storage for y |
For a comparison, the same task in JavaScript for computing y = 2x for x = 4 could look as follows:
var X = 4; var Y = 1; while (X != 0) { Y = Y * 2; X = X - 1; } |