04 How is a Malbolge program structured?

Malbolge Specification (lscheffer.com)

A Malbolge program is executed in a memory of 3^10 cells. Each memory cell contains a value between 0 and 59048.

Three registers are needed for the execution:

C is the instruction pointer pointing to the current instruction to be executed. The register is automatically incremented after each instruction.
D is the data pointer pointing to the current value to be processed. The register is automatically incremented after each command.
A is the register used for data input and output.

Program execution

Loading the program

When loading the program, spaces, tabs and line breaks are ignored. When writing to the memory cells, it is checked whether it is a valid command. If not, the execution is aborted.

If the memory area is exceeded during writing, the program execution is aborted.

After reading the program, the remaining memory area is filled with the Crazy function.

Initializing the registers

Registers C, D and A are set to 0.

Execute the program

  • Reading the memory cell C
  • Checking for validity
  • Execute the command
  • Encrypt the memory cell C
  • Increment C and D

Commands

CommandExplanation
i4jump [D]Copies the value at C to [D].
<5out APrints the value of A, as an ASCII character, to the screen.
/23in AInputs a character, as an ASCII code, into A.
*40rot [D]
mov A, [D]
Rotates the value at [D] by one ternary digit . Stores the result both at [D] and in A.
j68mov D, [D]Copies the value at [D] to D.
p39D = crazy A, [D]
mov A, [D]
Does the crazy operation with the value at [D] and the value of A. Stores the result both at [D] and in A.
o62nopDoes nothing
v81haltEnds the Malbolge program