Logica
Logica is an esolang for a 2-bit CPU created by User:H. H. P. M. P. Cole. There is no input/output. It is not Turing-Complete, but it can be, provided infinite storage and infinite-length instructions (this only allows for 16 instructions). Given the constraints, the version of Logica shown here only allows for 2256 possible programs. The CPU has four 2-bit registers.
| Designed by | User:H. H. P. M. P. Cole |
|---|---|
| Appeared in | 2025 |
| Computational class | Linear bounded automata |
| Reference implementation | Python |
| Influenced by | 2 Bits, 1 Byte, and the 74181 ALU |
A typical instruction (all the variables are bits):
a₁a₂ b₁b₂ c₁c₂ d₁d₂d₃d₄ e₁e₂ f₁f₂f₃f₄
The breakdown of the instruction
The four-bit string d₁d₂d₃d₄ specifies the logical operation to be followed. The truth table for the logical operation is as follows:
| Input 1 | Input 2 | Output |
|---|---|---|
| 0 | 0 | d₁
|
| 0 | 1 | d₂
|
| 1 | 0 | d₃
|
| 1 | 1 | d₄
|
There are 2⁴ = 16 such logical operations. The operation is simply called "operation d₁d₂d₃d₄".
The two-bit string a₁a₂ denotes the command to be used.
a₁a₂
|
Command to be followed |
|---|---|
| 00 | Jump unconditionally to instruction number f₁f₂f₃f₄.
|
| 01 | Load the result of operation d₁d₂d₃d₄ with inputs b₁b₂ and c₁c₂ into register e₁e₂.
|
| 10 | Load the result of operation d₁d₂d₃d₄ with inputs being the numbers in registers b₁b₂ and c₁c₂, into register e₁e₂.
|
| 11 | End the program. |
Python 3 interpreter
The example program given is an infinite loop.
print('Logica Interpreter')
print('by Cole')
print('======================================')
print('Link: https://esolangs.org/wiki/Logica')
print('======================================')
instructionlist = ['1001111000110000',
'0000000000000000',
'1100000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000',
'0000000000000000']
def logicalinstruction(b,c,d):
e = ''
for i in range(0,2):
if b[i] == '0' and c[i] == '0':
e = e + d[0]
if b[i] == '0' and c[i] == '1':
e = e + d[1]
if b[i] == '1' and c[i] == '0':
e = e + d[2]
if b[i] == '1' and c[i] == '1':
e = e + d[3]
return e
def binary(a):
if a == '00':
return 0
if a == '01':
return 1
if a == '10':
return 2
if a == '11':
return 3
print('Instruction R0 R1 R2 R3')
print('======================================')
r = ['00','00','00','00']
print(' ',r[0],r[1],r[2],r[3])
i = 0
while instructionlist[i][0:2] != '11':
a = instructionlist[i][0:2]
b = instructionlist[i][2:4]
c = instructionlist[i][4:6]
d = instructionlist[i][6:10]
e = instructionlist[i][10:12]
f = instructionlist[i][12:16]
if a == '00':
print(instructionlist[i],r[0],r[1],r[2],r[3])
i = 4*binary(instructionlist[i][12:14])+binary(instructionlist[i][14:16])
if a == '01':
r[binary(e)] = logicalinstruction(b,c,d)
print(instructionlist[i],r[0],r[1],r[2],r[3])
i = i + 1
if a == '10':
r[binary(e)] = logicalinstruction(r[binary(b)],r[binary(c)],d)
print(instructionlist[i],r[0],r[1],r[2],r[3])
i = i + 1
if instructionlist[i][0:2] == '11':
print(instructionlist[i],r[0],r[1],r[2],r[3])
