UM8

From Esolang
Jump to navigation Jump to search
This article is not detailed enough and needs to be expanded. Please help us by adding some more information.

UM8 a virtual machine created by User:Palaiologos for the Esolang Reverse Engineering Contest. The contest has finished in July 2020.

It contains 13 instructions ranging from 0x0 to 0xd. The original interpreter will take ASCII hexadecimal input from stdin (in uppercase). If it encounters something else than [0-9A-D] it will stop taking input and proceed to execution.

The machine contains 3 registers: A, B and C. The instruction sets permits self-modification of the program buffer, implying the program buffer can also be used as a tape for data storage or just modifying code in general.

Instruction set (credit: Gibson)

The instruction reference is written as some pseudo-code.

  • a, b, c are the registers
  • pc is the program counter
  • [expr] points at (expr) in the program buffer
  • ; are comments/notes from me
0 -> exit()
1 -> if (b) a = c
2 -> swap a, c
3 -> a = ~(b&c) ; NAND gate
4 -> putchar(b)
5 -> b = getchar()
6 -> swap a, b
7 -> a = [pc+c+1]
8 -> [pc+a+1] = b
9 -> a = [++pc]
A -> pc = b, [pc] = c
B -> a = !a ; logic NOT
C -> a >>= 1
D -> a <<= 1

NOTE Due to the way the interpreter is implemented, A jumps to b+1 and not b. However, [b] will still be set to c.

Example Programs

Cat

154906A

Here is a commented disassembly to understand it better:

1  | if (b) a = c      ; "dummy" instruction
5  | b = getchar()     ; get character from stdin
4  | putchar(b)        ; prints it
90 | a = 0
6  | a, b = b, a       ; sets b to 0
A  | pc = b, [pc] = c  ; jumps to 1, modifying the "dummy" instruction.

Hello World

9169BDD6496D2163D2163D2163D216364962163DD2163DD64962163D
D2163DD64962163DDDD216364952163D2163DD6498DD6495D2163DDD
216364962163DDDD21636497DD2163D2163D64962163DD2163DD6496
D2163D2163DD6498D2163D21636495D64

Explainations here.

Cat halting on EOF

942986A649629D516A

Truth machine

56649C891232616369129AD1690A

Implementations

The original implementations from User:Palaiologos are available here.

User:Matthilde's reverse-engineering writeup and C99 implementation is available in this git repo.