{"id":15060397,"url":"https://github.com/joakimwinum/bytecorecompiler","last_synced_at":"2025-04-10T05:50:56.908Z","repository":{"id":234787653,"uuid":"789512473","full_name":"joakimwinum/bytecorecompiler","owner":"joakimwinum","description":"ByteCoreCompiler: A compiler that transforms ByteCore assembly code into executable memory bytes, seamlessly bridging the gap between high-level assembly instructions and the ByteCore Emulator's low-level functionality.","archived":false,"fork":false,"pushed_at":"2025-02-05T19:53:51.000Z","size":84,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T07:04:18.262Z","etag":null,"topics":["8-bit-computing","assembly-language","code-compilation","compiler","computer-architecture","low-level-programming","python","software-development"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/bytecorecompiler/","language":"Python","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/joakimwinum.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-20T18:59:31.000Z","updated_at":"2025-02-05T19:53:02.000Z","dependencies_parsed_at":"2024-07-20T17:49:01.556Z","dependency_job_id":"7dfb59cf-1293-44af-83cd-f64e7ed017f7","html_url":"https://github.com/joakimwinum/bytecorecompiler","commit_stats":null,"previous_names":["joakimwinum/bytecorecompiler"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimwinum%2Fbytecorecompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimwinum%2Fbytecorecompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimwinum%2Fbytecorecompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joakimwinum%2Fbytecorecompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joakimwinum","download_url":"https://codeload.github.com/joakimwinum/bytecorecompiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247892133,"owners_count":21013649,"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":["8-bit-computing","assembly-language","code-compilation","compiler","computer-architecture","low-level-programming","python","software-development"],"created_at":"2024-09-24T22:58:17.742Z","updated_at":"2025-04-10T05:50:56.878Z","avatar_url":"https://github.com/joakimwinum.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ByteCoreCompiler\n\nThe ByteCoreCompiler transforms ByteCore assembly code into a 64KB memory byte array, compatible with the [ByteCore Emulator](https://github.com/joakimwinum/bytecore). It includes features to identify syntax errors and guide developers through debugging their code.\n\n## Overview\n\nThe compiler process involves several steps to convert text-based assembly code into executable memory bytes:\n\n1. **Lexical Analysis**: Converts raw text into tokens.\n2. **Syntax Analysis**: Checks token structure and builds a syntax tree.\n3. **Semantic Analysis**: Further inspects the syntax tree for logical consistency.\n\nSuccessful compilation results in a memory byte array ready for emulation; errors during any stage will generate exceptions to highlight issues.\n\n## ByteCore Assembly Language\n\nThe ByteCore assembly language represents instructions in a format that the ByteCore Emulator can execute directly, consisting of:\n\n- **MSB (Most Significant Byte)**\n- **LSB (Least Significant Byte)**\n- **DATA**: Can be either a valid hexadecimal number or an opcode.\n\n### Rules\n\nThe compiler adheres to specific rules to ensure the correct interpretation of ByteCore assembly:\n\n- Strips leading, trailing, and extra spaces.\n- Treats line breaks (`\\n`, `\\r`, `\\r\\n`) as new lines.\n- Ignores text after a semicolon (`;`), which denotes a comment.\n- Requires lines to have exactly 0 or 3 tokens, not counting comments.\n- Expects the first two tokens of a line to represent numbers in hexadecimal format (0-255).\n- Requires the third token to be either a valid opcode or a valid data value. Data values must be hexadecimal numbers ranging from 0 to 255 (00 to FF).\n- Prohibits assigning data to a memory address that has already been set.\n- Every opcode, except for `HALT`, expects an extended memory address to follow. For more details on how extended memory addresses are used within the ByteCore CPU's big-endian memory architecture, see the [Addressing Modes](https://github.com/joakimwinum/bytecore?tab=readme-ov-file#addressing-modes) section.\n\n### Instructions\n\nRefer to the [ByteCore Emulator README](https://github.com/joakimwinum/bytecore?tab=readme-ov-file#instructions) for a detailed list of supported instructions.\n\n## Installation and Setup\n\n### Prerequisites\n\nEnsure Python 3.11 or newer is installed. Clone the repository and navigate to the root directory. Consider setting up a Python virtual environment to manage dependencies.\n\n### Dependencies\n\nInstall required dependencies with:\n\n```bash\npip3 install -r requirements.txt\n```\n\n### Codespaces\n\nAlternatively, use Codespaces for a pre-configured environment by clicking [here](https://github.com/codespaces/new?hide_repo_select=true\u0026ref=main\u0026repo=joakimwinum/bytecorecompiler).\n\n## Usage\n\nTo compile ByteCore assembly code into memory bytes and execute it, follow these steps:\n\n### Example 1: Simple Program\n\n```python\nfrom bytecorecompiler.compiler import Compiler\nfrom bytecore.emulator import ByteCore\n\nbytecore_assembly = \"\"\"\n00 00 LOAD\n00 01 00\n00 02 0A\n00 03 ADD\n00 04 00\n00 05 0B\n00 06 STORE\n00 07 FF\n00 08 FF\n00 09 HALT\n00 0A 14; 20\n00 0B 1E; 30\n\"\"\"\n\nmemory_bytes = Compiler(bytecore_assembly).get_memory_bytes()\nbyte_core = ByteCore(memory_bytes)\nbyte_core.cycle_until_halt()\ndump = byte_core.dump()\n\ndump.memory[-1]  # equals 50\n```\n\n### Example 2: Advanced Program\n\nThis example uses all defined opcodes to demonstrate the compiler's capabilities with a more complex program structure.\n\n```python\nfrom bytecorecompiler.compiler import Compiler\nfrom bytecore.emulator import ByteCore\n\nbytecore_assembly = \"\"\"\n00 00 JMP\n00 01 FE\n00 02 00\n\n01 00 37; 55\n01 01 14; 20\n01 02 02;  2\n01 03 01;  1\n\nFE 00 LOAD\nFE 01 01\nFE 02 00\nFE 03 ADD\nFE 04 01\nFE 05 02\nFE 06 STORE\nFE 07 01\nFE 08 00\nFE 09 LOAD\nFE 0A 01\nFE 0B 01\nFE 0C SUB\nFE 0D 01\nFE 0E 03\nFE 0F STORE\nFE 10 01\nFE 11 01\nFE 12 LOAD\nFE 13 01\nFE 14 01\nFE 15 JZ\nFE 16 FF\nFE 17 00\nFE 18 JMP\nFE 19 FE\nFE 1A 00\n\nFF 00 LOAD\nFF 01 01\nFF 02 00\nFF 03 STORE\nFF 04 FF\nFF 05 FF\nFF 06 HALT\n\"\"\"\n\nmemory_bytes = Compiler(bytecore_assembly).get_memory_bytes()\nbyte_core = ByteCore(memory_bytes)\nbyte_core.cycle_until_halt()\ndump = byte_core.dump()\n\ndump.memory[-1]  # equals 95\n```\n\n## License\n\nThis project is licensed under the terms of the MIT License. See the [LICENSE](https://github.com/joakimwinum/bytecorecompiler/blob/main/LICENSE) file for the full text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoakimwinum%2Fbytecorecompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoakimwinum%2Fbytecorecompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoakimwinum%2Fbytecorecompiler/lists"}