'''Malbolge''' on avoimen lähdekoodin periaatteella toimiva esoteerinen ohjelmointikieli. Sen kehitti Ben Olmstead vuonna 1998.
Malbolge on saanut nimensä Helvetin kerroksen mukaan.

Malbolgen lähtökohtana on että se on mahdollisimman vaikeasti ohjelmoitava. Kuitenkin, muutamilla tempuilla sen saa ymmärrettäväksi.

==Malbolge-ohjelmointi==

Malbolge on niin vaikeasti ymmärrettävä, että sen suunnittelusta kului kaksi vuotta ennen kuin ensimmäinen järkevä Malbolge-ohjelma tehtiin. Tosin tällöinkään ohjelmaa ei koodannut ihminen, vaan se generoitiin Andrew Cooken ohjelmoimalla sädehakualgoritmilla (beam search).

Vuonna 2000 Anthony Youhas [http://www.antwon.com/index.php?p=234 esitti blogissaan] päihittäneensä Malbolgen vaikeudet ja osaavansa käyttää sitä. Hän osoitti tämän tekemillään kolmella ohjelmalla. Hän ei kuitenkaan paljastanut ohjelmointimetodiaan.

==Malbolgen toiminta==

Malbolge on konekieli joka toimii kolmikantaisessa (ternary) järjestelmässä, ei binäärissä. 

Malbolgessa on kolme rekisteriä, '''''a''''', '''''c''''' ja '''''d''''', jotka ovat kuin muuttujia muissa kielissä. Kun ohjelma alkaa, kaikkien kolmen arvo on 0.
*'''c''':llä on erityinen merkitys: Se osoittaa nykyiseen osoitteeseen.

===Osoitinnotaatio===

''d''-rekisterissä voi olla muistiosoite; tällöin ''[d]'' on kyseisen osoitteen sisältämä arvo. ''[c]'' toimii vastaavasti.

===Muisti===

Malbolgen virtuaalikoneessa on 59049 muistisanaa, joista kussakin voi olla 10 merkkiä pitkä kolmikantainen luku. Jokaisella muistipaikalla on osoite väliltä 0 - 59048, ja ne voivat kukin sisältää luvun väliltä 0 - 59048 (desimaalinen). Jos sanan arvo saavuttaa 59049:n, se korvataan 0:lla.

Ennen kuin Malbolge-ohjelman suoritus aloitetaan, ohjelma ladataan tulkin muistin alkuun. Välilyöntimerkit unohdetaan, ja jotta ohjelmoinnista tulisi vaikeampaa, koko muun ohjelman tulee koostua alla mainituista merkeistä. Loppuosa muistista täytetään "crazy operation"ia käyttäen kaavalla ''[m]&nbsp;=&nbsp;crz&nbsp;[m&nbsp;-&nbsp;2],&nbsp;[m&nbsp;-&nbsp;1]''.

==Käskyt==

'''Malbolge''' is a Dante's ''Inferno'', the Malebolge.

The peculiarity of Malbolge is that it was designed to be the most difficult and esoteric programming language.  However, several of the tricks used to make understanding it difficult can be simplified away.

==Programming in Malbolge==
Malbolge was so difficult to understand when it arrived that it took two years for the first Malbolge program to appear.  The program was not even written by a human being: it was generated by a Lisp.

On August 24, 2000, Anthony You announced on his blog that he "beat Malbolge with a stick and mastered its secrets", providing evidence in the form of three Malbolge programs that print various phrases. He did not, however, reveal his techniques.[http://www.antwon.com/index.php?p=234]

Later, Lou Scheffer posted a cryptanalysis of Malbolge and provided a program to copy its input to its output.  

Olmstead believed Malbolge to be a linear bounded automaton. There is a more interesting discussion about whether one can implement sensible loops in Malbolge &mdash; it was many years before introducing the first non-terminating one. A correct 99 Bottles of Beer program, which deals with non-trivial loops and conditions, was not announced for eight years; first correct one was by Hisashi Iizawa in 2007.

== Hello, world in Malbolge ==
This Malbolge program displays "Hello, world."
<code>
  (=<`:9876Z4321UT.-Q+*)M'&%$H"!~}|Bzy?=|{z]KwZY44Eq0/{mlk**
  hKs_dG5[m_BA{?-Y;;Vb'rR5431M}/.zHGwEDCBA@98\6543W10/.R,+O< </code>

== Simplified workings of Malbolge ==
Malbolge is ternary interpreter. To aid in the writing of Malbolge programs that run properly, the way the standard interpreter works will be described below. 

==== Notes ====
* The standard interpreter and the official specification do not match perfectly.
* This is a simplified explanation of the interpreter source code: it obviates useless encryption and subtraction steps and introduces an assembly language.
<!-- * Before correcting it, make sure it's actually technically incorrect and not just unfamiliar. -->

=== Registers ===
Malbolge has three registers, '''''a''''', '''''c''''', and '''''d''''', which are like points to the current instruction.

=== Pointer notation ===
'''''d''''' can hold a memory address; '''''[d]''''' is the value stored at that address. '''''[c]''''' is similar.

=== Memory ===
The virtual machine has 59049 (3<sup>10</sup>) memory locations that can each hold a ten-digit ternary number. Each memory location has an address from 0 to 59048 and can hold a value from 0 to 59048. Incrementing past this limit wraps back to zero.

Before a Malbolge program starts, the first part of memory is filled with the program. All whitespace in the program is ignored and, to make programming more difficult, everything else in the program must start out as one of the instructions below.

The rest of memory is filled by using the ''crazy'' operation (see below) on the previous two addresses ('''[m]&nbsp;=&nbsp;crz&nbsp;[m&nbsp;-&nbsp;2],&nbsp;[m&nbsp;-&nbsp;1]''').  Memory filled this way will repeat every twelve addresses (the individual ternary digits will repeat every three or four addresses, so a group of ternary digits is guaranteed to repeat every twelve).

=== Instructions ===
Malbolge has eight instructions. Malbolge figures out which instruction to execute by taking the value at '''''[c]''''', adding the value of '''''c''''' to it, and taking the remainder when this is divided by 94. The final result tells the interpreter what to do:

{| align="center" border="1" cellpadding="2" class="wikitable"
|+ Instructions
|- align="center"
! Value of <br />([c]&nbsp;+&nbsp;c)&nbsp;%&nbsp;94 !! Instruction represented !! Explanation
|- align="center"
! 4
| ''jmp&nbsp;[d]&nbsp;+&nbsp;1'' || align="left" | The value at '''''[d]''''', plus one, is where Malbolge will jump to and start executing instructions.
|- align="center"
! 5
| ''out&nbsp;a'' || align="left" | Prints the value of '''''a''''', as an ASCII character, to the screen.
|- align="center"
! 23
| ''in&nbsp;a'' || align="left" | Inputs a character, as an ASCII code, into '''''a'''''. Newlines or line feeds are both code ''10''.  An end-of-file condition is code ''59048''.
|- align="center"
! 39
| ''rotr&nbsp;[d]''<br />''mov&nbsp;a,&nbsp;[d]'' || align="left" | Rotates the value at '''''[d]''''' by one ternary digit (000211111'''''2''''' becomes '''''2'''''000211111). Stores the result both at '''''[d]''''' and in '''''a'''''.
|- align="center"
! 40
| ''mov&nbsp;d,&nbsp;[d]'' || align="left" | Copies the value at '''''[d]''''' to '''''d'''''.
|- align="center"
! 62
| ''crz&nbsp;[d],&nbsp;a''<br />''mov&nbsp;a,&nbsp;[d]'' || align="left" | Does the ''crazy'' operation (see below) with the value at '''''[d]''''' and the value of '''''a'''''. Stores the result both at '''''[d]''''' and in '''''a'''''.
|- align="center"
! 68
| ''nop'' || align="left" | Does nothing.
|- align="center"
! 81
| ''end'' || align="left" | Ends the Malbolge program.
|- align="center"
| colspan="3" | ''Any other value does the same as '''68''': nothing. These other values are not allowed in a program while it is being loaded, but are allowed afterwards.''
|}