Malbolge

Some general information about Malbolge can be found at Esolang. I'd be glad if you take note of my work with Malbolge:

Generate a simple text printing program

With this program you can generate Malbolge programs that simply print a text. The text your generated Malbolge program should print can be entered as a command line argument or via STDIN. Not supported characters are simply ignored, but at least all ASCII characters except the plus (+) are supported. The maximum size of the input string due to the limitated size of Malbolge programs depends on its content but about more than 2,000 characters will be critical.

How it works

The basic idea is equal to Andrew Cooke's idea who wrote the first "Hello World!" Malbolge program ever: Automated searching for a Malbolge program that prints the string we want. But with my preliminary considerations I was able to reduce the runtime of the searching algorithm dramatically.

Reflections: The out command needs the character in register A. If there is no user input you have only two commands for writing a value into register A.
I wanted to make the program very simple so it won't use a memory cell for input twice. So I tried to use only rotation, crazy, out, and nop.
A shift operation does completely overwrite A ignoring its value. That's the reason why a shift operation doesn't make sense behind a crazy operation if A has not been printed yet.
I've tested the behaviour of the rotation and crazy commands automatically with input in the range from 33 to 126. This are possible initial values. For other input values I would have to manipulate the data pointer D in my program which would be more complicated. The result of the test was that all ASCII characters can be build with at most 2 crazy operations after one rotation. All but '+' do need at most one crazy operation.
Because the data pointer and the code pointer are both moved by 1 after each command I tried to shift the shift command itself into the A register. But manipulating the executed command to a non-ASCII character crashes the interpreter.
So I decided to use a single jump as first byte of the program, followed by nops until the destination address. Then the data pointer is always 98 steps behind the program counter. That menas that all data from position 98 on will be encrypted after its execution and will be changed when read. But this is no problem, I just have to care about it.

The algorithm: To print a single character I have a search window starting with size 1. I will do a rotate before or at the last position of the search window and - if the rotation was done before the last position - a crazy operation at the last position. Trying out every position for a rotation and incrementing the search window size I will find the positions of the rotate and (maybe) the crazy operation to get a correct value in A (because the data at [D] will change at each code position). All other positions of the code are set to be nops. After that, A can be printed out and the next character can be searched. For '+' some special handling is neccessary because it needs 1 rotation and 2 crazy operations. Maybe I will work on it in the future.

Example

The following program was generated automatically and prints "Hello World!\n":

bCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^
]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@9>=<;:9876543210/.'K+*)i'&}C{"!~w=<zyxw
vutsrqponmlkjihafe^$ba`_^]?zZYXWV8TSRKoONMFKJIHG@d'CBA@?>=<;4X87w5.R2
10p.-,+*)(!E%$#"!~}|{zyxwvutsrqponmlkjihgfedcbD!_^]\[ZYXWVUTSRQPO1lY 

This example is bigger than Andrew Cooke's first "Hello World" program and also bigger than the example at Wikipedia, but it has been generated really fast and automatically.