BrainF**k Interpreter for CASIO fx-92+ Spéciale College

It’s too late for today, so the program is untested. I’ll probably test it on my calc the other day when I got more time to waste.

In short, this calculator is extremely limited. Hats off to the contributors at https://algos-casiofx92.com/; you guys are genius.

Note: Access X&Y registers with “Aller a x:y”

The program space is rather limited. Instead of doing I/O the way I’m doing it (by using two registers as the “streams”), you can modify the program to redirect the I/O functions to “Demander valeur” and “Afficher result”. In that case the maximum BF program length is 16*5=80 steps.

 

Maximum Length: 16*3 Steps
X:PC	: Program Counter
Y:XS	: Execution State
A:AC	: Accumulator 
B:IS	: Input Stream
C:OS	: Output Stream
D:SC	: Scratch Pad
E:P1	: Program Space 1
F:P2	: Program Space 2
M:P3	: Program Space 3
; Opcode Encoding:
; 0: NOP   1: >     2: <     3: +     4: -
; 5: .     6: ,     7: [     8: ]
; Limitations:
;   1. Any datum > 9 will corrupt nearby values in the scratch pad
; Fetch Instruction
Ent(PC/16)+1->AC
Si AC=1 Alors
	Ent(10*(P1*10^(PC-AC*16)-Ent(P1)*10^(PC-AC*16))->AC
Sinon
	Si AC=2 Alors
		Ent(10*(P2*10^(PC-AC*16)-Ent(P2)*10^(PC-AC*16))->AC
	Sinon
		Ent(10*(P3*10^(PC-AC*16)-Ent(P3)*10^(PC-AC*16))->AC
	Fin
Fin
; A State Machine for [ ] Instructions
Si XS=1 Alors
	PC+1->PC
Sinon
	Si XS=2 Alors
		PC+1->PC
		Si AC=8 Alors
			XS=1
		Fin
		AC=0
	Sinon
		PC-1->PC
		Si AC=7 Alors
			XS=1
		Fin
		AC=0
	Fin
Fin
; Execute the Instruction
; This part is rather ugly. The culprit it the 3-level return limitation of the calculator.
 
Si AC<=4 Alors
	Si AC<=2 Alors
		Si AC=1 Alors
			SC*10->SC				; >
		Sinon
			Si AC=2 Alors
				SC/10->SC			; <
			Fin
		Fin
	Sinon
		Si AC=3 Alors
			SC+1->SC				; +
		Sinon
			SC+1->SC				; -
		Fin
	Fin	
Sinon
	Si AC<=6 Alors
		Si AC=5 Alors								; .
			Ent(10*((SC/10)-Ent((SC/10))))->AC
			OS*10+AC->OS
		Sinon										; ,
			Ent(10*((IS/10)-Ent((IS/10))))->AC
			((Ent(SC/10))*10+(SC-Ent(SC)))+AC->SC
		Fin
	Sinon
		Si AC=7 Alors								; [
			Si Ent(10*((SC/10)-Ent((SC/10))))==0
				2->XS
			Fin
		Sinon										; ]
			Si Ent(10*((SC/10)-Ent((SC/10))))!=0
				3->XS
			Fin
		Fin
	Fin
Fin

Leave a Reply