Try it online!Try it online! Check Debug to see the generated SBIN code.†
How it worksSesos assembly
add 26 jmp jmp, fwd 1, add 1, fwd 1, add 1, rwd 2, sub 1, jnz fwd 2, add 64 jmp, rwd 2, add 1, fwd 2, sub 1, jnz rwd 1, sub 1 jnz rwd 1 jmp jmp, put, rwd 1, jnz fwd 27 jmp, put, rwd 1, jnz add 10, put, get, rwd 1 jmp, fwd 1, add 1, rwd 1, sub 1, jnz rwd 1 ; jnz (implicit)
How it works
We start by initializing the tape to ABCDEFGHIJKLMNOPQRSTUVWXYZ. This is as follows.
Write 26 to a cell, leaving the tape in the following state.
v 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 0
As long as the cell under the data head is non-zero, we do the following.
Copy the number to the two cells to the left and add 64 to the leftmost copy.
v 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 26 0 0
Move the leftmost copy to the original location, then subtract 1 from the rightmost copy.
v 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 90 0
The process stops after 26 iterations, since the rightmost copy is 0 by then. We move a cell to the right, so the final state of the tape after the initialization is the following.
v 0 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0
Now we're ready to generate the output, by repeating the following process until the cell under the data head is zero.
First, we print the character under the data head and move to the right, repeating this step until a cell with value 0 is found. After printing ABCDEFGHIJKLMNOPQRSTUVWXYZ, the tape looks as follows.
v 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0
Now we move the data head 27 units to the left (back to the leading 0) and repeat the print-move combination until a cell with value 0 is found. This prints nothing and leaves the tape as follows.
v 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0
Now, we write 10 to the current cell, print the corresponding character (linefeed) and zero the cell with a call to get on empty input, leaving the tape unchanged.
Afterwards, we move the content of the cell to the right to the current cell, then move the data head to units to the right.
v 65 0 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0
The next iteration is slightly different. The first printing step prints BCDEFGHIJKLMNOPQRSTUVWXYZ, leaving the tape as follows.
v 65 0 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0
Now we move the data head 27 units to the left.
v 65 0 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0
The subsequent printing loop prints A and leaves the tape as follows.
v 65 0 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0
Once again, we print a linefeed, move the content of the cell to the right to the current cell, then move the data head to units to the right.
v 65 66 0 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0
After 24 more iterations, the final step of moving the data head to the right leaves the tape in the following state.
v 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0 0
The cell under the data head is now 0 and the program terminates.
† TIO uses a newer version of Sesos, which is backwards-compatible for SASM, but generates shorter SBIN code.