DEV Community

Jami
Jami

Posted on

Esoteric Coding Languages: Malbolge

Esoteric programming languages

are often created to add a little bit of spice to the coding world. They're mysterious and often unsolvable for the average coder due to their unnecessary difficulty. Luckily, the world loves mystery. **BranFlakes **and **Befunge **seemed to be as bad as esoteric languages could get until Malbolge was introduced.

Malbolge was made to be almost impossible to use due to it's self altering and base-three arithmetic code. It builds on the difficulties of earlier esoteric languages like BranFlakes and Befunge by playing on older versions of computer science and encryption.

Malbolge was made in 1998, named after the 8th circle in Dante's Inferno, and created by Ben Olmstead. The first written program however, was made through a Beam Search algorithm (a quick problem solving search algorithm using breadth first search to build it's search tree) designed by Andrew Cooke (through a Lisp implementation).

Two assembly languages currently exist to write Malbolge code. The first is LaL which was implemented by Japanese researchers and the second is HeLL due to a precise specification of LaL not being available as of 2013 (now available). Both of these languages utilize *mnemonics *(a strategy of accessing information in long term memory) and labels so that ternary memory address access is not necessary to run it's program. It's use is not necessary, it is more to say that it was done rather than for useful applications.

Malbolge was generated by a Beam Search Algorithm: A heuristic search algorithm that only searches the most definitive nodes at a time. Because Beam Search expands limited nodes it is most beneficial for large searches. It utilizes _best-search-first modification _which alters log probability to return decent results. Beam search is often used in machine translation systems due to it's accuracy and ability to search larger databases.

Malbolge has 3 accessible memory locations (registers) 'A' (accumulator), 'C' (code pointer), 'D' (data pointer). After every instruction if the memory that 'C' points to is within the range of 33-126 then the following translation table is used:

When the interpreter executes a program it first checks to see if the proposed code is an ASCII character. If it is, it subtracts 33 from it and adds 'C' and then modifies its character index by 94. If the original code is not an ASCII character the program automatically terminates.


The word Cat in Malbolge

This strange language has eight instructions and it's code functions based on trits of each machine word. The variable 'J' sets the pointer to the value already being pointed to. The variable 'I' sets the pointer to the value that will be pointed to. The star character rotates the trinary value of the cell that 'D' points to, to the right of 1. The variable 'P' performs a tritwise operation on the cell 'D' points to with contents of 'A'. The variable '<' reads the ASCII value from the stdin and converts it to Trinary and then stores it in A. The forward slash character converts the value in A to ASCII and then writes it in stdout . 'V' indicates the machines termination and lastly 'O' increments 'C' and 'D'.

A-Trits:

Di-Trits:

Trinary -> ASCII -> Decimal -> Hex-Table:

There are two techniques for writing Malbolge. The first is to print the text and terminate the code. The second technique is used for conditionals, loops, and inputs. In the second technique the developer designs the program as if every cell of memory can be initialized with arbitrary values, then generates the initialization code that writes the corresponding values into memory.

Malbolge utilizes '.code' and '.data' to determine where memory cells are used. Values within both of these must be assigned to a label and as the code self modifies, it's Movd/nop becomes a Movd instruction (an instruction which copies scalar quantities), which then becomes a Nop after modifying and encrypting again. Nop is short for no-operation meaning it does nothing and does not access any memory.

Malbolge is a wild and strange coding language that is not used very often. It's implementation is mostly for shock value and to show just how complicated machines can become. While it's not necessary to learn, it can be a great way of understanding how complex languages can get and how computers are able to interpret that complexity.

Sources:
https://en.wikipedia.org/wiki/Malbolge
https://en.wikipedia.org/wiki/Beam_search
https://dev.to/viz-x/malbolge-the-programming-language-designed-to-be-impossible-1bl7
https://www.geeksforgeeks.org/machine-learning/introduction-to-beam-search-algorithm/
https://direct.mit.edu/tacl/article/doi/10.1162/tacl_a_00346/96473/Best-First-Beam-Search
https://wiki.c2.com/?ProgrammingLanguageNamingPatterns
http://www.lscheffer.com/malbolge_spec.html
https://lutter.cc/malbolge/tutorial/cat.html
https://ctl.stanford.edu/memory-strategy-mnemonics
https://en.wikipedia.org/wiki/NOP_(code)
https://www.cs.auckland.ac.nz/references/macvax/op-codes/Instructions/mov.html

Top comments (0)