LMCode

From Esolang
Jump to navigation Jump to search

LMCode — esoteric programming language. Based on the Little man computer command system.

LMCode operates on an array of memory cells, also referred to as the tape, each initially set to zero. There is a pointer, initially pointing to the first memory cell. The commands are:

Command Description
, Download a value from INBOX into the accumulator
. Upload a value from the accumulator into OUTBOX
~ Download a value from the accumulator into the current memory cell
^ Upload a value from the current memory cell into the accumulator
> Move the pointer to the right
< Move the pointer to the left
+ Add a value from the current cell to the accumulator
- Sub a value in the current cell from the accumulator
? Jump to the label !
! The label of the command ?
{ Jump to the label }

This does only work if acc>=0

} The label of the command {
( Jump to the label )

This does only work if acc=0

) The label of the command (


Examples

Double a value

,~+.

So the way this works is:

Download a value from INBOX into the accumulator

Download a value from the accumulator into cell 0

Add a value from the cell 0 to the accumulator (double a value)

Upload doubled value from the accumulator into OUTBOX

The largest element in the list

To run the program, you must first upload initial values to cells 0 and 1, then go back to cell 0.

,~>,~<

Then run

^>-{^?}<^!.

The way this works is:

Upload the first value from cell 0 into the accumulator

Move the pointer to cell 1

Sub the second value from the accumulator

If acc>=0, jump to label }

Upload the second value from the cell 1 into the accumulator

Jump to label !

Move the pointer to cell 0

Upload the first value from cell 0 into the accumulator

Upload a value from the accumulator into OUTBOX

Fibonacci

}>>^>+.~<+.~<<^>-<~{

To run the program, you must first upload count of the cycles (into cell 0), decremet of the count - the natural number 1 (into cell 1), first Fibonacci number - the natural number 1 (into cell 2).


See also

CARDboard Illustrative Aid to Computation

OISC

FALSE

Brainfuck

External resources

Article about LMCode, posted on habr.com

Interpreter of LMCode on github.com