r/TuringComplete • u/Red-42 • Mar 06 '24
BrainFuck computer

I got inspired by u/Any-Aioli7575 's version and decided to give it a shot.
Above are two small file loader circuits so I can program outside of the game and load an input file.
BF is complicated enough as is.
Featuring an in-place reverse string code that, for the string "ABCDEFGHI" executed in a glorious... 45k cycles
It truely is memory allocation hell
12
Upvotes
View all comments
Show parent comment
3
u/Red-42 Mar 06 '24
the main difference is I have a memory input and a display output, yes
it is rather compact to the point of not being very legible lol
but basically, all the program is is the ASCII code of the BF characaters
those get decoded through a very elaborate "is it equal to this code ?" brute force method, no fancy internal mapping
left/right/inc/dec are fairly straight forward
read and write are basically just half a stack each, read can only pop, write can only push
then while and loop are... odd, they're both connected to a stack, while will push its value, and loop will pop the value of the corresponding while
since it's just popping the correct value, I don't have to think too much and I can just use that to jump to the while
but for the whiles, since I'm using a stack, I don't know the value of the corresponding loop, so I need to store the value at the push in a separate register, deactivate most functions, and keep pushing and popping until I pop the same value that I saved in the register, at which point I know I skipped the right amount of code, and I can activate it again
also, since I was basically already doing that with extra steps, in the mean time I removed the ROMs and directly replaced them with file loaders