{"id":23265751,"url":"https://github.com/andreip/hack-compiler-os-cpu","last_synced_at":"2025-04-06T07:34:05.488Z","repository":{"id":140786552,"uuid":"147163384","full_name":"andreip/hack-compiler-os-cpu","owner":"andreip","description":"A simple computer: compiler, os and cpu design.","archived":false,"fork":false,"pushed_at":"2018-10-04T03:58:36.000Z","size":3135,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T12:57:02.307Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.andreipetre.ro/posts/2018-09-27-built-own-computer","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-09-03T06:50:38.000Z","updated_at":"2020-12-24T09:43:06.000Z","dependencies_parsed_at":"2024-06-14T07:00:10.512Z","dependency_job_id":null,"html_url":"https://github.com/andreip/hack-compiler-os-cpu","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreip%2Fhack-compiler-os-cpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreip%2Fhack-compiler-os-cpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreip%2Fhack-compiler-os-cpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreip%2Fhack-compiler-os-cpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreip","download_url":"https://codeload.github.com/andreip/hack-compiler-os-cpu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247450842,"owners_count":20940938,"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":[],"created_at":"2024-12-19T15:32:21.393Z","updated_at":"2025-04-06T07:34:05.470Z","avatar_url":"https://github.com/andreip.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"#### About ####\n\nThis is part of a course. See my blog post for more info\nhttp://www.andreipetre.ro/posts/2018-09-27-built-own-computer\n\n#### Folder structure ####\n\n* `jack-chess/` folder contains a chess game written in Jack, a new programming\nlanguage\n* `compiler/` folder contains a compiler, a virtual machine and an assembler that\ncan compile Jack programs down to binary code\n* `cpu_hdl/` folder uses a has hardware description language to model a CPU and\nits logical gates, MUXes, DEMUXes, ALU, Registers ; simpler than verilog \u0026 vhdl\n* `OS/` is a simple operating system written in Jack for math primitives, heap\nmemory allocation and deallocation, drawing pixels on the screen, drawing text\non the screen with a custom font, reading input from user keyboard and others\n* `tools/` is a set of [java binaries and shell utilities taken from here](https://www.nand2tetris.org/software)\nused to emulate the hack platform and cpu\n\n#### Compile and run the chess game ####\n\nI'll walk you through compiling [a chess game](https://github.com/andreip/jack-chess)\nand running it on a hack platform emulator.\nYou'll need:\n* CMake and a C++ in order to compile the compiler\n* Java available on your system to run the VM Emulator\n* python to generate some files in jack-chess\n\n```bash\n# Compile the compiler/ folder\n$ mkdir build; cd build\n$ cmake ../compiler\n$ make\n$ ls\n# You should see 3 binaries in the current folder\n# AsmHack, VMTranslator and JackCompiler\n\n# Now pull in the chess game submodule\n$ git submodule update --init --recursive\n# Generate some missing sprites/ and DrawSprites.jack files\n$ python ../jack-chess/generate_jack_drawing.py\n# Compiles each .jack file to a .vm intermediary language file in same dir\n$ ./JackCompiler ../jack-chess/\n# Generates a ../jack-chess/jack-chess.asm file\n$ ./VMTranslator ../jack-chess/\n\n# Run the virtual machine emulator\n$ ../tools/VMEmulator.sh\n\n#\n# Then:\n# - click File -\u003e Load Program in the VM Emulator\n# - navigate to the 'jack-chess/', select it and hit Load Program\n#   (Make sure you select the actual folder and hit Load Program without\n#    going inside it; and don't select an individual .vm file, you actually\n#    want all .vm files to be loaded in memory)\n# - change \"Program flow\" to \"No animation\" in the select widget at the top\n# - hit the \"\u003e\u003e\" button to start and it should work\n#\n\n# Compiling further from asm down to binary code won't\n# work because the asm file is too large (~130K lines of code)\n# to fit in memory and be addressable by a 16bit computer. At most\n# it can compile something up to ~32K lines asm, since that's the max\n# address a goto instruction can jump to with 16-bit instructions\n# (15bits actually used for address).\n# So this won't work, you can try and see it fail :)\n$ ./AsmHack ../jack-chess/jack-chess.asm\n\n# But hey, don't get sad, you can assemble a smaller file.\n# Will create a Fill.hack file in same directory with original .asm\n$ ./AsmHack ../cpu_hdl/04/Fill.asm\n# Its contents aren't that interesting.\n```\n\nYou can compile the operating system files the same way, but you'll run into\nthe same limitation that the assembly file is again too big.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreip%2Fhack-compiler-os-cpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreip%2Fhack-compiler-os-cpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreip%2Fhack-compiler-os-cpu/lists"}