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.
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
|i||4||jump [D]||Copies the value at C to [D].|
|<||5||out A||Prints the value of A, as an ASCII character, to the screen.|
|/||23||in A||Inputs a character, as an ASCII code, into A.|
mov A, [D]
|Rotates the value at [D] by one ternary digit . Stores the result both at [D] and in A.|
|j||68||mov D, [D]||Copies the value at [D] to D.|
|p||39||D = 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.|
|v||81||halt||Ends the Malbolge program|