BinaryBits
BinaryBits (or BB) is a language where everything is in binary. BB was created by User:Evylah for no particular reason.
- This is still a work in progress. It may be changed in the future.
Overview
Instructions, data, and everything else are all in binary. BB is designed for an 8-bit computer.
Data structure
Data is stored in a heap. There are 256 8-bit cells. In this page a memory cell will be referred to as M#, where # is a number.
Instructions can either write or read to a memory address.
Address M0 and M1 will be used for ALU operations. M2 is -1 (0b11111111), M3 is 0, and M4 is 1.
Instructions
Instructions are all written as one 20 bit binary string. Each instruction is read like this:
op A B 0110 10011010 11010010
… Just without the spaces. A and B are parameters. Any unused parameters for A or B can be filled with anything you want.
Flags
Flags are represented with one 8-bit binary string.
00000000 U+0-EC
Bit | Flag | Character (readable form) |
---|---|---|
128
|
nothing | N/A |
64
|
nothing | N/A |
32
|
Unconditional (always true) | U
|
16
|
is Positive | +
|
8
|
is Zero | 0
|
4
|
is Negative | -
|
2
|
is Even | E
|
1
|
carry | C
|
These flags apply to the result of the last ALU operation (anything math or logic related).
- Bits
128
and64
don't do anything and can be filled with whatever you want. - Carry gets flagged when the operation results over 255.
- Negative numbers are check if the 128 bit is a 1 (128 is -128 in 2's complement, and if the -128 bit is a 1 the entire number is negative.)
Instruction set
For parameters, they will be listed as M, #, or something else.
M is a memory cell, # is an immediate number.
Conditional branching
op | name | parameter A | parameter B | function/use |
---|---|---|---|---|
0000
|
JMP
|
flags | # | Jump to instruction #B if any of the condition flags A are true. Jumping to instruction FF will halt the program, and the program counter will halt when it reaches FF. |
Memory
op | name | parameter A | parameter B | function/use |
---|---|---|---|---|
0001
|
LOAD
|
M | # | Load MA with #B |
0010
|
UIP
|
M | - | Ask user for a byte and load it into MA |
0011
|
COPY
|
M | M | Copy MA to MB |
1001
|
OUT
|
M | - | Output the value of MA |
ALU
op | name | parameter A | parameter B | function/use |
---|---|---|---|---|
0100
|
ADD
|
M | - | M0 + M1, store in MA |
0101
|
INV
|
M | - | Invert all bits of M0, store in MA |
0110
|
INC
|
M | - | MA = M0 + 1 |
0111
|
DEC
|
M | - | MA = M0 - 1 |
1000
|
DEC
|
M | - | MA = M0 - 1 |
Implementation
If you are building this as an actual computer (good luck), outputting can be done with binary or hexadecimal. If you are programming an implementation with Python or something, use ASCII output.
Code examples
Readable form isn't the actual code. All numbers are written in hexadecimal (for easy converting to binary). Line numbers are added for clarity.
//
denotes a comment.
All unused parameters in binary will be filled with 0.
A + B problem
Readable form
0 | UIP M0 1 | UIP M1 2 | ADD M3 // Add M0 and M1, store in M3 3 | OUT M3 // Output M3
Binary
00100000000000000000 00100000000100000000 01000000001100000000 10010000001100000000
Cat program
Terminates on 0.
Readable form
0 | LOD M1 0 // this gets added with the input to check for 0 1 | UIP M0 2 | ADD M0 // M0 = input, raise 0 flag if input is 0 3 | OUT M0 4 | JMP 0 FF // halt if 0 5 | JMP U 1 // Jump back to user input
Binary
00010000000100000000 00100000000000000000 01000000000000000000 10010000000000000000 00000000100011111111 00000010000000000001
Truth-machine
Readable form
0 | UIP M0 // Input 1 | LOD 0 M1 // Load 0 to M1 to check 2 | ADD M0 // Check for 0 3 | JMP 0 6 // Jump to line 6 (output 0) 4 | OUT M4 // output 1 (M4 is always 1) 5 | JMP U 4 // jump to line 4 and repeat forever 6 | OUT M3 // output 0 (M3 is always 0) 7 | JMP U FF // end
Binary
00100000000000000000 00010000000000000001 10000000000000000000 00000000100000000110 10010000010000000000 00000010000000000100 10010000001100000000 00000000100011111111