BSM

From Esolang
Jump to navigation Jump to search

BSM is an esoteric programming language created by user:David.werecat which executes instructions based on an 8-bit state machine with a single bit modifier.

Instructions

Language Basics

The source code is read as a series of bits. The state machine starts at state 0x00. Each cycle, the instruction represented by the current state is executed (or NOP if the current state has no instruction) and the state machine moves to the next state given the current bit of code. The current bit is then moved to the next bit (or previous bit if the execution direction is reversed). When the last bit in the code is reached, execution moves back to the first bit of source code and the EndProgram instruction (instruction 0x17) is re-enabled if disabled. Execution may also be turned on and off: when execution is off the only instructions that are executed are the instructions that can turn execution back on.

There are three stacks, each which is a stack of 8-bit unsigned integers. All stacks begin with 1024 elements of value 0x00. If a stack is attempted to be read when it has no elements, a generic error is thrown by the interpreter.

The interpreter can accept multiple source code files as arguments, in which case the files are run separately and sequentially.

It should be noted that since the instruction is executed as the first part of each cycle, the first instruction executed is always 0x00.

Instruction Codes

Code Instruction
0x00 Pop stack 1 into stack 2 and increment
0x01 Pop stack 1 into stack 2 and decrement
0x02 Pop stack 2 into stack 1
0x03 Peek stack 1 into stack 2
0x04 Pop stack 2 into stack 1 and increment by the new top value of stack 2, then pop stack 2 into stack 1
0x05 Pop stack 2 into stack 1 and decrement by the new top value of stack 2, then pop stack 2 into stack 1
0x06 Pop stack 1 into stack 3
0x07 Pop stack 2 into stack 3
0x08 Pop stack 3 into stack 1
0x09 Pop stack 3 into stack 2
0x0A Read char into stack 3
0x0B Write char from stack 3
0x0C Reverse stack 3
0x0D Reverse execution direction
0x0E Turn on execution
0x0F Peek stack 1 and turn on execution if it is zero
0x10 Peek stack 2 and turn off execution if it is zero
0x11 Peek stack 2 and turn off execution if it is not zero
0x12 Set jump point to current bit
0x13 Move to jump point
0x14 Rotate stacks clockwise (top values move so 1->2 2->3 3->1)
0x15 Rotate stacks counterclockwise (top values move so 2->1 3->2 1->3)
0x16 Disable end program for this iteration (end program is re-enabled next loop of the source code)
0x17 End program

Due to the 0x03 instruction (duplication), the memory size can be expanded by any amount.

State Table

State Next State On 0 Next State On 1
0x00 0x2B 0xF7
0x01 0x77 0x1D
0x02 0x5F 0x78
0x03 0x4E 0xEA
0x04 0x9A 0xAE
0x05 0x01 0x60
0x06 0x75 0x46
0x07 0x1A 0x1A
0x08 0x73 0x68
0x09 0x76 0x50
0x0A 0x63 0x44
0x0B 0xC1 0x82
0x0C 0x5E 0x47
0x0D 0xAA 0xC9
0x0E 0xA6 0x07
0x0F 0x15 0x27
0x10 0x79 0x81
0x11 0x38 0xB1
0x12 0x5D 0xA2
0x13 0x19 0xA5
0x14 0xBC 0x55
0x15 0x3F 0xE5
0x16 0x7A 0x56
0x17 0x8D 0x93
0x18 0xFB 0x7F
0x19 0xF9 0xAC
0x1A 0x3B 0x16
0x1B 0x91 0x2A
0x1C 0xA8 0x57
0x1D 0x68 0x51
0x1E 0x04 0x9A
0x1F 0x03 0xBD
0x20 0x36 0xB2
0x21 0x3E 0x5E
0x22 0x35 0x6E
0x23 0x52 0x37
0x24 0x92 0x34
0x25 0xC7 0x69
0x26 0x87 0x52
0x27 0x05 0x08
0x28 0x96 0x04
0x29 0x6A 0xD9
0x2A 0xD8 0x77
0x2B 0x8F 0x0B
0x2C 0x95 0xB5
0x2D 0x5B 0x1E
0x2E 0x66 0x7D
0x2F 0x69 0x1C
0x30 0xE2 0x64
0x31 0xCD 0x9D
0x32 0x98 0xF4
0x33 0x6E 0x75
0x34 0x64 0xD4
0x35 0x99 0xD6
0x36 0xAC 0xCE
0x37 0x18 0x4F
0x38 0x5C 0x4E
0x39 0x0D 0x28
0x3A 0xEB 0x09
0x3B 0xDD 0x7A
0x3C 0x86 0x40
0x3D 0xE4 0x99
0x3E 0x0C 0xC5
0x3F 0xC5 0x5F
0x40 0xAE 0x9C
0x41 0xAF 0x94
0x42 0xAB 0x36
0x43 0x6C 0x8B
0x44 0x7C 0xBA
0x45 0xD4 0xF3
0x46 0x3D 0x10
0x47 0x72 0xF6
0x48 0xF3 0x66
0x49 0xF5 0xB7
0x4A 0xCE 0x4A
0x4B 0x07 0x25
0x4C 0x46 0x4C
0x4D 0x37 0xB8
0x4E 0x4B 0xDD
0x4F 0x6B 0x14
0x50 0x6D 0x03
0x51 0x34 0x63
0x52 0x82 0xC1
0x53 0xCA 0xCC
0x54 0xA0 0xF2
0x55 0xEF 0xAD
0x56 0x6F 0xAA
0x57 0xED 0x54
0x58 0xA5 0x7E
0x59 0x2D 0xD7
0x5A 0xAD 0x29
0x5B 0x25 0x2D
0x5C 0x50 0x3B
0x5D 0xD3 0x12
0x5E 0xC0 0x15
0x5F 0x2A 0xCB
0x60 0x74 0x43
0x61 0x1E 0xF0
0x62 0x2E 0x2E
0x63 0xFE 0x1B
0x64 0x9B 0xE2
0x65 0x53 0x9E
0x66 0x21 0x0C
0x67 0x06 0x22
0x68 0x60 0x45
0x69 0x61 0x70
0x6A 0xA7 0x42
0x6B 0xBF 0xCF
0x6C 0xFF 0x92
0x6D 0x65 0x90
0x6E 0x31 0xDB
0x6F 0xB5 0xB6
0x70 0xEC 0xC2
0x71 0xE0 0x76
0x72 0x00 0x2B
0x73 0x1D 0xCD
0x74 0x43 0x0F
0x75 0xDE 0xC3
0x76 0xB7 0xD5
0x77 0x10 0x6C
0x78 0x12 0x88
0x79 0x33 0xFF
0x7A 0xDB 0x97
0x7B 0xD2 0x87
0x7C 0x7D 0x21
0x7D 0xA3 0xD8
0x7E 0xF4 0x59
0x7F 0x85 0xE6
0x80 0x8B 0x24
0x81 0x8C 0x79
0x82 0x4D 0x4D
0x83 0xCB 0x3E
0x84 0xE9 0xE4
0x85 0x20 0x20
0x86 0x8A 0xEB
0x87 0xEE 0xEE
0x88 0x0B 0x8F
0x89 0xC3 0xAB
0x8A 0x2F 0x3A
0x8B 0x93 0x39
0x8C 0x27 0x80
0x8D 0x4C 0x06
0x8E 0xF2 0x11
0x8F 0x7B 0xD2
0x90 0xBE 0xEC
0x91 0xBA 0xA6
0x92 0x08 0x30
0x93 0x81 0x31
0x94 0xCF 0xBC
0x95 0x22 0x8C
0x96 0x97 0x8D
0x97 0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