{"id":15060207,"url":"https://github.com/danielbrodi/lowlevelassembler","last_synced_at":"2026-01-02T20:03:54.372Z","repository":{"id":245478494,"uuid":"818222878","full_name":"danielbrodi/LowLevelAssembler","owner":"danielbrodi","description":"Program in C designed to act as an assembler, converting assembly commands into binary code with efficient preprocessing, label checking, parsing, and file management. Ensures correct conversion with strict error handling and optimal memory management practices, making it act like an ideal assembler for low-level programming tasks.","archived":false,"fork":false,"pushed_at":"2024-12-14T17:39:52.000Z","size":496,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T05:14:40.671Z","etag":null,"topics":["assembler","assembly","assembly-language","assembly-language-programming","binary","binary-code","binary-conversion","binary-converter","c","c-programming","compiler","compiler-construction","compiler-design","compilers","low-level","low-level-design","low-level-memory-manipulation","low-level-programming","memory-leak","memory-management"],"latest_commit_sha":null,"homepage":"","language":"C","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/danielbrodi.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-06-21T11:13:37.000Z","updated_at":"2025-01-06T09:56:46.000Z","dependencies_parsed_at":"2024-06-22T10:09:23.030Z","dependency_job_id":"ac106e28-bb07-477e-8fad-41d68d0b9d0c","html_url":"https://github.com/danielbrodi/LowLevelAssembler","commit_stats":null,"previous_names":["danielbrodi/lowlevelassembler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielbrodi%2FLowLevelAssembler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielbrodi%2FLowLevelAssembler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielbrodi%2FLowLevelAssembler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielbrodi%2FLowLevelAssembler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielbrodi","download_url":"https://codeload.github.com/danielbrodi/LowLevelAssembler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243685583,"owners_count":20330982,"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":["assembler","assembly","assembly-language","assembly-language-programming","binary","binary-code","binary-conversion","binary-converter","c","c-programming","compiler","compiler-construction","compiler-design","compilers","low-level","low-level-design","low-level-memory-manipulation","low-level-programming","memory-leak","memory-management"],"created_at":"2024-09-24T22:54:30.833Z","updated_at":"2026-01-02T20:03:49.352Z","avatar_url":"https://github.com/danielbrodi.png","language":"C","readme":"# Low Level Assembler [![Assembler](https://img.shields.io/badge/Assembler-v1.0-blue.svg)](#) [![](https://komarev.com/ghpvc/?username=brodiLowLevelAssembler\u0026style=pixel\u0026label=Repo%20Views\u0026color=0e75b6)](#)\n\n## Overview\n\nThe **Low Level Assembler** is a program designed to act as an assembler, converting assembly commands into their binary counterparts. \u003c/br\u003e\nThe conversion process involves multiple stages to ensure accurate and reliable assembly-to-binary transformation. \u003c/br\u003e\nThis assembler handles preprocessing, label checking, parsing, and file writing, producing multiple output files to give a detailed view of the assembly-to-binary conversion process.\n\n## Features\n\n- **Preprocessing**: Reads and expands macros.\n- **Label Checking**: Validates labels for any discrepancies.\n- **Parsing**: Analyzes and validates the syntax.\n- **File Generation**: Produces a processed file (*.am), entry labels file (*.ent), extern labels file (*.ext), and a binary code file (*.ob).\n- **Error Handling**: Strong focus on error handling to ensure accurate conversions.\n- **Memory Management**: Ensures all allocated memory is appropriately freed after use.\n\n## Table of Contents\n\n- [Overview](#overview)\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Files](#files)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\nTo use the assembler, clone the repository and compile the source code:\n\n```bash\ngit clone https://github.com/danielbrodi/LowLevelAssembler.git\ncd LowLevelAssembler\nmake\n```\n\n## Usage\n\nTo run the assembler, use the following command:\n\n```bash\n./assembler \u003cfile1\u003e \u003cfile2\u003e ... \u003cfileN\u003e\n```\nEach \u003cfile\u003e should be an assembly file you wish to process. \u003c/br\u003e\nThe program will generate corresponding output files with the following extensions:\n- *.am* for the processed file.\n- *.ent* for the entry labels file.\n- *.ext* for the extern labels file.\n- *.ob* for the binary code file.\n\n#### Run the Command\n```bash\n./assembler tests/example.asm\n```\nThis command will process **example.asm** located in the **tests** directory and generate **example.am**, **example.ent**, **example.ext**, and **example.ob** files.\n\n## Flow Example\n\n### Input File: `example.as`\nThe sample example file for running can be found in the [**tests**](./tests) directory, among other test files that you can run.\n\n```assembly\n.entry LENGTH\n.extern W\nMAIN: mov @r3, LENGTH\nLOOP: jmp L1\nprn -5\nbne W\nsub @r1, @r4\nbne L3\nL1: inc K\n.entry LOOP\njmp W\nEND: stop\nSTR: .string \"abcdef\"\nLENGTH: .data 6, -9, 15\nK: .data 22\n.extern L3\n```\n\n### Processing Steps\n\n#### Step 1: Macro Expansion\n\n```assembly\n.entry LENGTH\n.extern W\nMAIN: mov @r3, LENGTH\nLOOP: jmp L1\nprn -5\nbne W\nsub @r1, @r4\nbne L3\nL1: inc K\n.entry LOOP\njmp W\nEND: stop\nSTR: .string \"abcdef\"\nLENGTH: .data 6, -9, 15\nK: .data 22\n.extern L3\n```\n\n#### Step 2: Label Checking\n\nThe assembler checks for any discrepancies or errors in the labels, such as undefined labels or duplicate definitions. In this example, no discrepancies were found.\n\n#### Step 3: Parsing and Binary Code Generation\n\n**Binary Machine Code**\n\n| Address | Source Code               | Binary Code         |\n|---------|---------------------------|---------------------|\n| 0100    | MAIN: mov @r3, LENGTH     | 101000001100        |\n|         |                           | 000110000000        |\n|         |                           | 000111110110        |\n| 0103    | LOOP: jmp L1              | 000100101100        |\n|         |                           | 000111000110        |\n| 0105    | prn -5                    | 000110000100        |\n|         |                           | 111111101100        |\n| 0107    | bne W                     | 000101001100        |\n|         |                           | 000000000001        |\n| 0109    | sub @r1, @r4              | 101001110100        |\n|         |                           | 000010010000        |\n| 0111    | bne L3                    | 000101001100        |\n|         |                           | 000000000001        |\n| 0113    | L1: inc K                 | 000011101100        |\n|         |                           | 001000000010        |\n| 0115    | jmp W                     | 000100101100        |\n|         |                           | 000000000001        |\n| 0117    | END: stop                 | 000111100000        |\n| 0120    | STR: .string \"abcdef\"     | 000001100001        |\n|         |                           | 000001100010        |\n|         |                           | 000001100011        |\n|         |                           | 000001100100        |\n|         |                           | 000001100101        |\n|         |                           | 000001100110        |\n|         |                           | 000000000000        |\n| 0125    | LENGTH: .data 6, -9, 15   | 000000000110        |\n|         |                           | 111111110111        |\n|         |                           | 000000001111        |\n| 0128    | K: .data 22               | 000000010110        |\n\n\n#### Step 4: Writing Output Files\n\n**example.ob**\n\nBinary machine code output file containing the compiled instructions in base64 format.\n\n```\n18 11\noM\nGA\nH2\nEs\nHG\nGE\n/s\nFM\nAB\np0\nCQ\nFM\nAB\nDs\nIC\nEs\nAB\nHg\nBh\nBi\n```\n\n**example.ent**\n\nEntry labels output file listing symbols marked as entry points with their corresponding addresses.\u003cbr\u003e\nListed in decimal (base 10) format.\n\n```\nLOOP 103\nLENGTH 125\n```\n\n**example.ext**\n\nExternal labels output file listing symbols referenced but not defined within the program.\u003c/br\u003e\nListed in decimal (base 10) format.\n\n```\nW 108\nL3 112\nW 116\n```\n\n\u003e Note: If there are no external labels, the `.ext` file will not be created. \u003c/br\u003e Similarly, if there are no entry labels, the `.ent` file will not be created.\n\n## Files\n\n### Source Files\n\n- **assembler.c**: Main file containing the program's entry point and core logic.\n- **preprocessor.c**: Handles macro expansion.\n- **label_checker.c**: Validates labels.\n- **parser.c**: Parses and validates the syntax.\n- **file_writer.c**: Writes the output files.\n\n### Output Files\n\n- **.am**: Processed file after macro expansion.\n- **.ent**: File containing entry labels.\n- **.ext**: File containing external labels.\n- **.ob**: Binary code file, converted to base64.\n\n## Contributing\n\nContributions are welcome!\u003c/br\u003e\nPlease fork the repository and create a pull request with your changes. \u003c/br\u003e\n\n1. Fork the repository.\n2. Create a new branch (`git checkout -b add-feature-branch`).\n3. Commit your changes (`git commit -am 'Add new feature'`).\n4. Push to the branch (`git push origin add-feature-branch`).\n5. Create a new Pull Request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Additional Information\n\nFor more detailed information about the program's workflow, refer to the comments in the [assembler.c](assembler.c) file.\n\n### Main Method Workflow\n\n```c\n/**\n * Serves as the program's entry point. The flow of the program includes:\n *    1. Initiation of the program state. The assumption of the program is that the starting memory block is\n *       located at address '100'.\n *    2. Reading files and appending appropriate extensions(.am, .ext, .ent, .ob).\n *    3. Preprocessing: reading and expanding macros.\n *    4. Checking labels for any discrepancies.\n *    5. Parsing files to understand and validate the syntax.\n *    6. Writing all labels, both entry \u0026 external to separated files(.ext, .ent).\n *    7. Conversion from binary to base64 and save in a file (.ob).\n *       Note: If any of the stages encounters an error or fails, the program will not produce a base64 *.ob file.\n *    8. Finally, freeing the program state after processing.\n */\n```\n\n## Contact\n\nFor any questions or feedback, feel free to open an issue or contact me:\n- **Daniel Brodsky** - [Linkedin](https://www.linkedin.com/in/daniel-brod/)\n\n### Special thanks to Lior Katav for writing this software with me.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielbrodi%2Flowlevelassembler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielbrodi%2Flowlevelassembler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielbrodi%2Flowlevelassembler/lists"}