esolang

FakeASM

It reads like assembly for a 65c816, but there is no processor under it, only an interpreter that runs the source one line at a time.

CosmoConsole, 2012 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 6 known programs · Test method

Run it

Expected: Hello, world!

The idea

CosmoConsole made FakeASM in 2012 to look like the assembly languages of real processors such as the 65c816. The interpreter was written in VB.net, and its program counter is the line number. FakeASM2 followed in 2014 with a few more instructions, among them QUI, which prints the program's own source, and RSC, which reads one character. The specification says the source of the first interpreter is thought to be lost, and FakeASM2 was rebuilt from it by decompiling.

Read the story

There is no real machine, so the instructions do what a console program needs. ECHO prints a line, WDX prints the X register in decimal, and AGAIN starts the program over.

The machine

A, B and C hold 16 bits, and X, Y and Z hold 8. The flag register P has c for carry, z for zero or equal, n for negative, and x for how RXY indexes. RAM and ROM hold 65,536 bytes each, and the stack lives in RAM.

InstructionDoes
LAC 5 LXC 99Load a number into a register
LDA.w 100h STA.w 100hLoad or store a register in RAM; .w is two bytes, little-endian
TAX TBACopy one register into another
INC X DEC BAdd or take 1
ACC 7 ACR 100h SCC 2Add or subtract with carry, a number or a byte of RAM
CMC 69h CXC 1Compare A or another register with a number; z when equal, c when greater
JMP L: JEQ L: JCC L:Jump to a label, always or on a flag
JSR L: RETCall and return
PHA PLBPush and pull
ECHO "text" PRINT "text"Print text with or without a line break
WDX WRA WHA WBAPrint a register in decimal, hex or binary
RSC WCA.wRead a character into A; print A as a character
AGAIN STPStart over; stop

A line that ends in a colon is a label, and a jump names it with the colon, as in JMP Loop:. A line that starts with ; is a comment, and !PI=3 declares a constant used as !PI. Numbers are decimal, 1Fh in hex or 101b in binary.

The specification's table says JEQ jumps when z is 0 and JNE when it is 1, and its line for INC says decrease. The programs in the specification need the opposite of both, and this implementation follows the programs.

This implementation is a subset. Sound, the cursor, the keyboard, random numbers, the shared data file and the interpreter commands that read or write files stop the run with a reason. Colours and delays do nothing.

Example

A Hello World program.

A Hello World program.

A loop. CXC 5 sets z once X is 5, and until then JNE jumps back.

Expected: 1 2 3 4 5

The cat from FakeASM2. RSC gives 0 at the end of the input, which sets z and ends the loop.

Expected: Grüße

A subroutine. JSR pushes the line to come back to, SHL doubles A, and the result is printed in decimal and in hex.

Expected: 42 2A

The 99 bottles of beer and its Deadfish interpreter run as written. Its Fibonacci routine, called with X set to 10, leaves 55 in A. ACR adds a single byte of RAM, so from the 16th number on the routine goes wrong and gives 731 where 987 belongs.

Further

Also in Turing tarpits

Write your own in Run Convert a program from FakeASM

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run fakeasm -e 'QUI'
shib manual fakeasm

Source

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

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

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