{"id":15698573,"url":"https://github.com/sof3/brainfuck-cpu","last_synced_at":"2026-01-08T01:53:38.985Z","repository":{"id":48525145,"uuid":"123293872","full_name":"SOF3/brainfuck-cpu","owner":"SOF3","description":"A Logisim schematic for a CPU that implements the Brainfuck language.","archived":false,"fork":false,"pushed_at":"2018-03-09T15:46:21.000Z","size":88,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T15:54:43.310Z","etag":null,"topics":["brainfuck","brainfuck-runtime","cpu","logisim","processor"],"latest_commit_sha":null,"homepage":"","language":"Brainfuck","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SOF3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-28T14:09:13.000Z","updated_at":"2024-04-03T21:21:47.000Z","dependencies_parsed_at":"2022-09-19T11:40:47.706Z","dependency_job_id":null,"html_url":"https://github.com/SOF3/brainfuck-cpu","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SOF3%2Fbrainfuck-cpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SOF3%2Fbrainfuck-cpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SOF3%2Fbrainfuck-cpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SOF3%2Fbrainfuck-cpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SOF3","download_url":"https://codeload.github.com/SOF3/brainfuck-cpu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246328007,"owners_count":20759692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brainfuck","brainfuck-runtime","cpu","logisim","processor"],"created_at":"2024-10-03T19:30:08.125Z","updated_at":"2026-01-08T01:53:38.943Z","avatar_url":"https://github.com/SOF3.png","language":"Brainfuck","readme":"# brainfuck-cpu\nThis repo contains a Logisim schematic file for a programmable circuit implementing a 24-bit-datapath 24-bit-mempath [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) computer.\n\nStructure:\n* main: contains everything that functions as a \"complete\" \"computer\", including:\n  * 1 24-bit ROM: contains 4-bit units of data. In each unit, bits 2:0 are encoded as BFC instructions. See the encoding specification below. Bit 3 is the special \"shutdown\" signal that hangs the clock.\n  * 1 24-bit RAM: contains 8-bit units of data, serving as the memory byte array for the Brainfuck environment.\n  * 1 main clock: the clock that regulates the synchronization of the whole system. This implementation should be synchronous\n  * 1 stdin ROM: a counter+ROM complex providing the stdin pipe for the Brainfuck environment. It reads bytes from its ROM backend, incrementing the address when the CPU signals that a byte has been read.\n  * 1 stdout RAM: a counter+RAM complex providing the stdout pipe for the Brainfuck environment. It appends bytes to its RAM backend.\n  * 1 CPU: the instruction processor\n* brainfuck/cpu:\n  * Inputs:\n    * clk (boolean): for synchronization with the main clock\n    * instr (instr\\_size): current instruction to execute\n    * instr\\_ptr (datapath\\_size): the pointer to the current instruction\n    * mem (cell\\_size): the value of the current memory cell\n    * mem\\_ptr (mempath\\_size): the pointer to the current memory cell\n    * stdin (cell\\_size): the stdin value to read, if needed\n  * Outputs:\n    * instr\\_ptr (datapath\\_size): the pointer to the next instruction\n    * mem\\_ptr (mempath\\_size): the pointer to the next memory cell\n    * writing\\_mem (boolean): a boolean indicating whether the current memory cell should be updated to set\\_mem (according to the Brainfuck language, an instruction that updates a memory cell would not update the memory pointer, so it is not necessary to distinguish it as the cell _before_ or the cell _after_ the instruction)\n    * set\\_mem (cell\\_size): the value to be set into memory if writing\\_mem is 1\n    * stdout\\_ready (boolean): a boolean indicating whether the \"stdout\" output should be appended to the stdout pipe\n    * stdout (cell\\_size): the value to be appended to the stdout pipe if stdout\\_ready is 1\n    * stdin\\_read (boolean): a boolean indicating whether a new cell should be pulled from the stdin pipe, i.e. the current one has been consumed\n  * Internal registers:\n    * a 6-bit counter used for finding the matching `]` when `[` is executed with memory 0 (i.e. a while loop has broken)\n    * a Register24Stack64 subcircuit for storing pointers to previous `[` instructions.\n* Register24Stack64:\n  * Uses a 6-bit-mempath 24-bit-cell RAM\n  * Implements a first-in-last-out \"stack\" data structure for 24-bit data cells\n  * Has 3 valid input combinations:\n    * `~push \u0026 ~pop`: PEEK action, not modifying the RAM. Outputs the tail entry (last-inserted entry) in the stack.\n    * `push \u0026 ~pop`: PUSH action, appending insert\\_data to the stack. Output is undefined.\n    * `~push \u0026 pop`: POP action, removing the last-inserted entry from the stack. Output is undefined.\n  * Needs formal proof to determine if brainfuck/cpu might experience bugs due to a PUSH/POP action not being able to output the tail value in the same tick. If issues exist, may need doueble-ticking.\n\n### BFC 3-bit encoding\nBFC means \"Brainfuck compiled\". It is a simple mapping of Brainfuck instructions into 3-bit units.\nThe following bitsets correspond to symbolic instructions in the Brainfuck language:\n\n| Bitset (2:0) | Symbol | Synopsis |\n| :----: | :----: | :----: |\n| `000` | `\u003e` | Increments the memory pointer |\n| `001` | `\u003c` | Decrements the memory pointer |\n| `010` | `+` | Increments the memory value |\n| `011` | `-` | Decrements the memory value |\n| `100` | `.` | Sends the current memory value to stdout |\n| `101` | `,` | Consumes the current stdin value and stores it in the current memory value |\n| `110` | `[` | If current memory value is 0, skips to the matching `]` behind, which is not necessarily the immediately following one |\n| `111` | `]` | If current memory value is not 0, jumps back to the matching `[` before |\n\n### Memory allocation\n* boolean: 1 bit\n* instr\\_size: 3 bits\n* datapath\\_size: 24 bits\n* mempath\\_size: 24 bits\n* cell\\_size: 8 bits\n\n### Synchronization\nThe whole circuit is currently synchronous with the same main clock. However, constraints in stdin and Register24Stack64 may require double-ticking. Formal proof is required to confirm.\n\n### RESET\nThis implementation defines that all memory cells start at 0.\n\n### The `bfc` utility\nbfc.cpp is a standalone C++ file that can be compiled to build Brainfuck programs.\n\nAccepting the argument FILE\\_BASENAME, bfc will parse the {FILE\\_BASENAME}.bf file\n\nThen it will emit the following files:\n* {FILE\\_BASENAME}.min.bf: The syntactically minified Brainfuck program code, i.e. only instruction bytes are left.\n* {FILE\\_BASENAME}.bfc: The Brainfuck code is compiled into binary form, equivalent what is loaded inside the instruction ROM. The higher 4 bits (7:4) are unused. Bit 3 is the shutdown bit. The lower 3 bits (2:0) are BFC-encoded instructions.\n* {FILE\\_BASENAME}.bfc.txt: The BFC file converted into plaintext, compatible with Logisim ROM imports.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsof3%2Fbrainfuck-cpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsof3%2Fbrainfuck-cpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsof3%2Fbrainfuck-cpu/lists"}