Reverse String in Unicat

Published on 28 August 2023 (Updated: 28 August 2023)

Welcome to the Reverse String in Unicat page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

# Find end of input by finding null-termination
0o00 πŸ˜ΊπŸ˜ΌπŸ˜ΉπŸ˜ΊπŸ™€πŸ™€ Memory 10 (0o12) through N+11 = input (N characters), newline, null
0o01 πŸ˜»πŸ˜ΉπŸ˜ΈπŸ™€πŸ™€πŸ˜ΉπŸ˜ΊπŸ™€πŸ™€ Memory 0 = 0o12 (10 = '\n')
0o02 πŸ˜»πŸ˜ΉπŸ˜ΉπŸ™€πŸ™€πŸ˜ΉπŸ˜ΊπŸ™€πŸ™€ Memory 1 = 0o12 (10, input pointer)
0o03 πŸ˜»πŸ˜ΉπŸ˜ΊπŸ™€πŸ™€πŸ˜ΉπŸ™€πŸ™€ Memory 2 = 1
0o04 πŸ˜»πŸ˜ΉπŸ˜»πŸ™€πŸ™€πŸ˜ΈπŸ™€πŸ™€ Memory 3 = 0
0o05 πŸ˜ΏπŸ™€πŸ˜ΈπŸ˜»πŸ™€πŸ™€πŸ˜ΉπŸ™€πŸ™€ Memory 3 += Memory 1 (input pointer)
0o06 πŸ˜ΌπŸ˜ΎπŸ˜»πŸ™€πŸ™€ Memory 3 = pointer(Memory 3) (contents of input pointer)
0o07 πŸ˜½πŸ˜ΏπŸ˜»πŸ™€πŸ™€πŸ˜ΉπŸ˜ΈπŸ™€πŸ™€ If Memory 3 > 0, jump to 0o11 (0o10 + 1)
0o10 πŸ˜»πŸ˜ΉπŸ˜ΉπŸ™€πŸ˜ΏπŸ˜ΉπŸ˜ΊπŸ™€πŸ™€ Jump to 0o13 (0o12 + 1)
0o11 πŸ˜ΏπŸ™€πŸ˜ΈπŸ˜ΉπŸ™€πŸ™€πŸ˜ΊπŸ™€πŸ™€ Memory 1 += Memory 2 (1) (increment input pointer)
0o12 πŸ˜»πŸ˜ΉπŸ˜ΉπŸ™€πŸ˜ΏπŸ˜»πŸ™€πŸ™€ Jump to 0o04 (0o03 + 1)

# Null-terminate before input
0o13 πŸ˜»πŸ˜ΉπŸ˜ΉπŸ˜ΉπŸ™€πŸ™€πŸ˜ΈπŸ˜ΈπŸ™€πŸ™€ Memory 9 (0o11) = 0

# Strip trailing newline (if present)
0o14 πŸ˜»πŸ˜ΉπŸ˜»πŸ™€πŸ™€πŸ˜ΉπŸ™€πŸ˜Ώ Memory 3 = -1
0o15 πŸ˜ΏπŸ™€πŸ˜ΈπŸ˜»πŸ™€πŸ™€πŸ˜ΉπŸ™€πŸ™€ Memory 3 += Memory 1 (input pointer - 1, previous character)
0o16 πŸ˜ΌπŸ˜ΎπŸ˜»πŸ™€πŸ™€ Memory 3 = pointer(Memory 3) (previous character)
0o17 πŸ˜ΏπŸ™€πŸ˜ΊπŸ˜»πŸ™€πŸ™€πŸ˜ΈπŸ™€πŸ™€ Memory 3 -= Memory 0 (contents of input pointer - '\n')
0o20 πŸ˜½πŸ˜ΏπŸ˜»πŸ™€πŸ™€πŸ˜ΊπŸ˜ΌπŸ™€πŸ™€ If Memory 3 > 0, jump to 0o25 (0o24 + 1) (if contents of input pointer > '\n')
0o21 πŸ˜»πŸ˜ΉπŸ˜ΌπŸ™€πŸ™€πŸ˜ΉπŸ™€πŸ˜Ώ Memory 4 = -1
0o22 πŸ˜ΏπŸ™€πŸ™€πŸ˜»πŸ™€πŸ™€πŸ˜ΌπŸ™€πŸ™€ Memory 3 *= Memory 4
0o23 πŸ˜½πŸ˜ΏπŸ˜»πŸ™€πŸ™€πŸ˜ΊπŸ˜ΌπŸ™€πŸ™€ If Memory 3 > 0, jump to 0o25 (0o24 + 1) (if '\n' > contents of input pointer)
0o24 πŸ˜ΏπŸ™€πŸ˜ΊπŸ˜ΉπŸ™€πŸ™€πŸ˜ΊπŸ™€πŸ™€ Memory 1 -= Memory 2 (1) (decrement input pointer)

# Output reversed string starting before newline (if present) until beginning
# null-termination is found, then output a newline
0o25 πŸ˜ΏπŸ™€πŸ˜ΊπŸ˜ΉπŸ™€πŸ™€πŸ˜ΊπŸ™€πŸ™€ Memory 1 -= Memory 2 (1) (decrement input pointer)
0o26 πŸ˜»πŸ˜ΉπŸ˜»πŸ™€πŸ™€πŸ˜ΈπŸ™€πŸ™€ Memory 3 = 0
0o27 πŸ˜ΏπŸ™€πŸ˜ΈπŸ˜»πŸ™€πŸ™€πŸ˜ΉπŸ™€πŸ™€ Memory 3 += Memory 1 (input pointer)
0o30 πŸ˜ΌπŸ˜ΎπŸ˜»πŸ™€πŸ™€ Memory 3 = pointer(Memory 3) (contents of input pointer)
0o31 πŸ˜½πŸ˜ΏπŸ˜»πŸ™€πŸ™€πŸ˜»πŸ˜»πŸ™€πŸ™€ If Memory 3 > 0, jump to 0o34 (0o33 + 1)
0o32 πŸ˜½πŸ˜ΌπŸ˜ΈπŸ™€πŸ™€ Output Memory 0 ('\n')
0o33 πŸ™€πŸ™€ Exit
0o34 πŸ˜½πŸ˜ΌπŸ˜»πŸ™€πŸ™€ Output Memory 3 (contents of input pointer)
0o35 πŸ˜»πŸ˜ΉπŸ˜ΉπŸ™€πŸ˜ΏπŸ˜ΊπŸ˜ΌπŸ™€πŸ™€ Jump to 0o25 (0o24 + 1)

Reverse String in Unicat was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.