Subskin

From Esolang

Jump to: navigation, search

Subskin is an OISC variant with a very short (148 bytes of code) Ruby implementation written by Jannis Harder in 2005. Subskin is an abbreviation for "subtract and skip if negative", which is the only instruction.

Contents

[edit] The machine

[edit] The instruction

Each instruction has 3 words called (AP BP RP).

The instruction is

if( (memory[IP[2]]=memory[IP[0]]-memory[IP[1]]) < 0) skip();

or

if( (*RP = *AP - *BP) <0) skip();

Negative memory offsets result in undefined behavior.

[edit] Memory

The memory consists of an infinitely large array of signed bignums. If an undefined memory value is read, the program terminates.

[edit] Registers

There are 3 memory mapped registers

  • IP (Instruction Pointer) at position 0.
  • OR (Output Register) at position 1. If >= 0 it is written as character. Values >= 256 result in termination of the program. After printing the character it is set to -1.
  • IR (Input Register) at position 2. If < 0 a byte from STDIN is read and written into the register. On EOF a 256 is written into IR.

The Register actions for Input and Output are evaluated before the instruction.

[edit] The implementation

The implementation is 148 bytes of Ruby code released into the public domain.

[edit] Source code

m=readlines.map{|e|e.hex};loop{m[1]<0||$><<m[1].chr&&m[1]=-1;m[2]<0&&m[2]=
STDIN.getc||256;a,b,c=m[m[0],3];q=(m[c]=m[a]-m[b])<0?6:3;m[0]+=q}rescue 0

[edit] File format

Subskin code files (.subskin) contain one word of memory on each line in hex representation. Empty lines / lines without hex numbers are counted as zeros. The hex number has to be the first non-space character on the line, all characters after the first hex number are ignored.

[edit] Examples

cat 
3
-1
0
6
7
2
0
1
0
2
6
1
D
3
0
Hello, world! 
4
48
0
10
3
2
7
0
2
1
3
1
3
8
9
0
65
6c
6c
6f
2c
20
77
6f
72
6c
64
21
a
100
Hello, world! 2 (Improved) 
3
48
0
c
2
1
3
1
3
0
0
0
65
6c
6c
6f
2c
20
77
6f
72
6c
64
21
a
100
Hello, world! 3 (Improved again) 
See Hello world program in esoteric languages

[edit] See also

Personal tools