{"id":21314637,"url":"https://github.com/dor-sketch/assembler","last_synced_at":"2025-03-15T21:22:42.504Z","repository":{"id":197891591,"uuid":"697534424","full_name":"Dor-sketch/Assembler","owner":"Dor-sketch","description":"Thorough study of compiler architectures and translating assembly code.","archived":false,"fork":false,"pushed_at":"2024-02-01T21:32:25.000Z","size":2565,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T10:23:02.865Z","etag":null,"topics":["code-generation","file-output","openuniversity","preprocessing","symbol-table-generation","syntax-analysis"],"latest_commit_sha":null,"homepage":"","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/Dor-sketch.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}},"created_at":"2023-09-27T23:50:44.000Z","updated_at":"2024-05-30T09:28:20.000Z","dependencies_parsed_at":"2023-11-11T00:04:06.732Z","dependency_job_id":"a953874d-7f89-4a62-9635-d6441ca1e6c6","html_url":"https://github.com/Dor-sketch/Assembler","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.21052631578947367","last_synced_commit":"d996f5d5543c0038a746db2369023354b13387bb"},"previous_names":["dor-sketch/openu_course20465_project","dor-sketch/assembler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dor-sketch%2FAssembler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dor-sketch%2FAssembler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dor-sketch%2FAssembler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dor-sketch%2FAssembler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dor-sketch","download_url":"https://codeload.github.com/Dor-sketch/Assembler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243791136,"owners_count":20348423,"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":["code-generation","file-output","openuniversity","preprocessing","symbol-table-generation","syntax-analysis"],"created_at":"2024-11-21T18:14:25.443Z","updated_at":"2025-03-15T21:22:42.478Z","avatar_url":"https://github.com/Dor-sketch.png","language":"C","readme":"# 🛠 Assembler for Custom Assembly Language\n\nThis project involved the development of an assembler for a specialized assembly language. Its primary aim was to convert human-readable assembly instructions into binary machine code, bridging the gap between high-level programming concepts and low-level execution on computers.\n\nImplemented in `ANSI C`, this project demonstrates a strong understanding of foundational programming principles. It was part of the `20465 System Programming Laboratory` course at _The Open University of Israel_ studied during the 2021-2022 academic year,  and achieved a grade of `98`.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./images/image-1.png\" width=\"400\"\u003e\n\u003c/p\u003e\n\n---\n\n**Table of Contents**\n\n\u003c!-- @import \"[TOC]\" {cmd=\"toc\" depthFrom=2 depthTo=2 orderedList=false} --\u003e\n\n\u003c!-- code_chunk_output --\u003e\n\n- [🚀 Features](#-features)\n- [🤖 Usage](#-usage)\n- [✅ Examples](#-examples)\n- [🧩 Modules](#-modules)\n- [👥 Contributing](#-contributing)\n- [📜 License](#-license)\n\n\u003c!-- /code_chunk_output --\u003e\n\n---\n\n## 🚀 Features\n\n- **Preprocessing** 🧹: The assembler supports preprocessing tasks, including macro expansion and line numbering.\n\n- **Syntax Checking** ✅: The assembler ensures syntax accuracy, checking for valid opcodes and operands.\n\n- **Symbol Table** 📚: The assembler generates a symbol table, computing label memory addresses.\n\n- **Machine Code Generation** 💻: The assembler produces the machine code and data images.\n\n- **Output Files** 📁: The assembler prints output files such as the machine code file, external data words file, and entry type symbols file.\n\n- **Error Handling** 🚨: The assembler handles various syntax and semantic errors, providing descriptive error messages, including line numbers and error types with clickable links to the relevant code.\n\n- **Dynamic Memory Allocation** 🧠: The assembler uses dynamic memory allocation to manage memory efficiently.\n- **Modular Design** 🧩: The assembler is designed with a modular architecture, with each module responsible for a specific task.\n\n- **Coding Standards** 📏: The assembler adheres to the project's coding standards, including naming conventions, indentation, and documentation.\n\n- **Testing** 🧪: The assembler is thoroughly tested, with a test suite that covers all possible scenarios, including `valgrind` memory leak checks with no errors.\n\n---\n\n## 🤖 Usage\n\n### New GUI\n\n| ![Alt text](./images/image.png) | ![Alt text](./images/image-2.png) |\n| :-----------------------------: | :-------------------------------: |\n\nThe assembler now includes a new GUI, allowing users to assemble assembly code with a few clicks. The GUI is built with `Gtk+`. It's written in `c++` but integrates with the assembler's `c` codebase using `extern \"C\"`. This allows the assembler `main` function to get services from the GUI, such as the input file path and output directory path without having to change the assembler's codebase.\n\n**Note:** The GUI is currently only tested on `Ubuntu 22.04` and `MacOS Sonoma` and consider a work in progress. For stable usage, please use the command line interface or prevoius version of the Assembler.\n\n---\n\nBefore runing the assembler, make sure you have `gcc` and `Gtk+` installed on your machine.\n\nYou can install `Gtk+` on `MacOS` using `brew`:\n\n```bash\nbrew install gtk+3\n```\n\n---\n\n### Command Line\n\nUse the assembler by providing an input file with assembly code. The output includes several files: a machine code file, an external data words file, and an entry type symbols file.\n\n```bash\nmake\n./assembler {input - without .as extension. e.g. input_example}\n```\n\n---\n\n## ✅ Examples\n\n### Successful Assembly Output\n\nThe screenshots below demonstrate the successful output files generated by the assembler from the [input_example.as](./images/input_example.as) file:\n\n- Assembly Code Snippet (`ps.am`):\n\n    ```assembly\n    ; Assembly code that defines data, strings, and contains various instructions\n    ; including 'add', 'prn', 'lea', 'inc', 'mov', 'sub', 'bne', 'cmp', 'dec', and 'stop'.\n    .entry LIST\n    .extern  W\n    MAIN:  add r3,LIST\n    LOOP:  prn #48\n      macro m1 ; macro definition\n      inc r6\n      mov r3, W\n      endm\n      lea STR, r6\n      m1 ; macro call\n      sub r1, r4\n      bne END\n      cmp vall, #-6\n      bne END[r15]\n      dec K\n    .entry MAIN\n      sub LOOP[r10],r14\n    END:  stop\n    STR:  .string \"abcd\"\n    LIST:  .data 6,-9\n      .data -100\n    .entry K\n    K:  .data 31\n    .extern va\n    ```\n\n    _note: the macro will be expanded in the preprocessor stage:_\n\n    ```assembly\n    .entry LIST\n    .extern  W\n    MAIN:  add r3,LIST\n    LOOP:  prn #48\n      lea STR, r6\n      inc r6\n      mov r3, W\n      sub r1, r4\n      bne END\n      cmp vall, #-6\n      bne END[r15\n      dec K\n    .entry MAIN\n      sub LOOP[r10],r14\n    END:  stop\n    STR:  .string \"abcd\"\n    LIST:  .data 6,-9\n      .data -100\n    .entry K\n    K:  .data 31\n    .extern vall\n    ```\n\n- Entry Symbol Table (`input_example.ent`):\n\n    ```plaintext\n      ; List of entry symbols and their addresses\n      K,0144,0005\n      LIST,0144,0002\n      MAIN,0096,0004\n    ```\n\n- External Symbol References (`input_example.ext`):\n\n    ```plaintext\n      ; External symbols and their references in the code\n      vall BASE 0125\n      vall OFFSET 0126\n      W BASE 0115\n      W OFFSET 0116\n    ```\n\n- Machine Code Output (`input_example.ob`):\n\n    ```plaintext\n    ; Binary representation of the assembly code\n    41 9\n    0100 A4-B0-C0-D0-E4\n    ... (additional lines of machine code)\n    0149 A4-B0-C0-D1-Ef\n    ```\n\n---\n\n### Error Handling\n\nBelow is a screenshot showing how the assembler handles various syntax and semantic errors from [errors_example.as](errors_example.as). Each error message is designed to be descriptive, guiding the user to identify and rectify the issues within the assembly code.\n\n![image](https://github.com/Dor-sketch/openu_course20465_project/assets/138825033/d3178433-7907-40ff-b8d5-f2f500b07d0c)\n\nThe error messages include issues like undefined operations, missing operands, invalid target registers, and failures to find symbols for direct addressing mode, showcasing the assembler's comprehensive error-checking capabilities.\n\n---\n\n## 🧩 Modules\n\nThe assembler includes several modules:\n\n- `📝 pre.c`: Manages preprocessing tasks, including macro expansion and line numbering.\n- `🔎 syntax.c`: Ensures syntax accuracy, checking for valid opcodes and operands.\n- `🚦 first_pass.c`: Conducts the first assembly pass, generating a symbol table and computing label memory addresses.\n- `🚀 second_pass.c`: Performs the second pass, producing the machine code and data images.\n- `🖨️ print_output.c`: Prints output files such as the machine code file, external data words file, and entry type symbols file.\n- `🏁 main.c`: Coordinates the other modules to produce the final output.\n\n## 👥 Contributing\n\nContributors are welcome! Fork the repository and submit a pull request with your changes. Please ensure your contributions are well-tested and adhere to the project's coding standards.\n\n## 📜 License\n\nThis project is licensed under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdor-sketch%2Fassembler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdor-sketch%2Fassembler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdor-sketch%2Fassembler/lists"}