esolang

LMCode

The Little Man Computer's commands as single characters. One accumulator, a tape, and jumps to labels.

Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 42

The idea

LMCode takes its commands from the Little Man Computer, a teaching model of a computer with an INBOX, an OUTBOX and an accumulator. Each command is one character, and the memory is a tape of cells with a pointer, as in brainfuck.

Read the story

There are no loops in brackets. A jump goes to its label wherever the label is, forward or back. ? always jumps to !, { jumps to } when the accumulator is 0 or more, and ( jumps to ) when it is exactly 0. The same { makes an if in one program and a loop in another.

The machine

CharDoes
,Read a number into the accumulator
.Print the accumulator
~Store the accumulator in the current cell
^Load the current cell into the accumulator
> <Move the pointer right or left
+ -Add or subtract the current cell
?Jump to !
{Jump to } if the accumulator is 0 or more
(Jump to ) if the accumulator is 0

Input and output are decimal numbers. Each printed number gets a line of its own, and a jump goes to the first label of its kind in the program.

Example

The doubling stores the number in cell 0 and adds the cell to the accumulator.

The doubling stores the number in cell 0 and adds the cell to the accumulator.

The largest of two numbers, with the setup the specification asks for in front. It subtracts the second from the first, and when the result is 0 or more it jumps past the part that loads the second.

Expected: 7
Expected: 7

The Fibonacci program wants a count in cell 0, 1 in cell 1 and 1 in cell 2 but the specification gives no code that puts them there, so ,~>,~>,~<< reads them in first. Each round prints two numbers and takes 1 from the count, and the { at the end jumps back to the } at the start until the count is below 0. A count of 2 gives three rounds.

Expected: 1 2 3 5 8 13

Patterns it teaches

  • Counter machines: numbers in cells, changed by adding and subtracting, with a test for 0 and below.

Further

Cell-based

Write your own in Run Convert a program from LMCode

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: lmcode.

Command line

shib run lmcode -e ',~+.' --input '21'
shib manual lmcode

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/lmcode.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org