{"id":30752663,"url":"https://github.com/github0null/sdcc-binutils-mcs51","last_synced_at":"2025-09-04T08:36:17.531Z","repository":{"id":311744845,"uuid":"1044696440","full_name":"github0null/sdcc-binutils-mcs51","owner":"github0null","description":"use sdcc+as+ld to build your mcs51 project","archived":false,"fork":false,"pushed_at":"2025-08-26T09:55:54.000Z","size":92,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-26T11:22:14.393Z","etag":null,"topics":["8051","8052","as","binutils","ld","mcs51","sdcc"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/github0null.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,"zenodo":null}},"created_at":"2025-08-26T04:42:59.000Z","updated_at":"2025-08-26T09:54:30.000Z","dependencies_parsed_at":"2025-08-26T11:22:19.534Z","dependency_job_id":"50f12095-768f-4fa3-a86e-b47e35480170","html_url":"https://github.com/github0null/sdcc-binutils-mcs51","commit_stats":null,"previous_names":["github0null/sdcc-binutils-mcs51"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/github0null/sdcc-binutils-mcs51","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0null%2Fsdcc-binutils-mcs51","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0null%2Fsdcc-binutils-mcs51/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0null%2Fsdcc-binutils-mcs51/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0null%2Fsdcc-binutils-mcs51/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github0null","download_url":"https://codeload.github.com/github0null/sdcc-binutils-mcs51/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0null%2Fsdcc-binutils-mcs51/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273576007,"owners_count":25130402,"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","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["8051","8052","as","binutils","ld","mcs51","sdcc"],"created_at":"2025-09-04T08:36:12.144Z","updated_at":"2025-09-04T08:36:17.499Z","avatar_url":"https://github.com/github0null.png","language":"Shell","readme":"\n[中文](./README_zh.md)\n\n# Summary\n\nThis is the [sdcc](https://sdcc.sourceforge.net/) + [binutils](https://www.gnu.org/software/binutils/) compiler suite prepared for mcs51. \n\nIt uses sdcc as the front end to generate assembly and then uses gnu as+ld to complete the compilation and linking.\n\nThe source code of this repository is referenced from: https://github.com/volumit/sdcc_aurix_scr_42 \n\n**What's the difference ?**\n\nThe linker of sdcc does not support the dead code elimination function (i.e., deleting unused functions in the program), so when compiling a large number of c files with sdcc, the generated hex will be very large in size.\n\nThis solution can solve this problem. \n\nbinutils as supports syntax like `.section.text._func`, so a section can be generated for each function. Thus, the ld can use the `--gc-sections` feature to remove unused sections.\n\nThis toolchain is in the experimental stage, it has already passed the test suite.\n\n![](./docs/test-result.jpg)\n\n# Notice\n\nSome functions may be somewhat different from sdcc.\n\n  - **Not support overlay**：All local variables are saved to the stack, so the `--stack-auto --nooverlay` parameter must be enabled,otherwise, the compilation will fail.\n  - **Not support medium, huge model**：Only the 'small' and 'large' models are supported\n  - **Not support address \u003e 64K**：References to addresses greater than '0xFFFF' are not supported, and thus SFR32 is not supported either\n  - **Not support xstack**: The stack can only be located in 'iram'\n  - **Absolute address position**：'__at(xxx)' cannot be used for absolute address localization of 'data idata xdata code', ** except for the SFR register **, because ld uses linker script for address allocation. To use this function, refer to the \"Usage\" section below, or directly define the absolute position of the symbol using '-Wl,--defsym='\n  - **Stack**：Since the overlay feature is not supported, all local variables and function parameters are stored in the stack. This poses a challenge for mcs51 because even with the large model, the maximum remaining size of the stack is' 256-32 = 224 bytes'. Therefore, for function calls, Don't use too many function parameters and nested calls, as this will accelerate stack overflow.\n\n# Build It\n\nRun `apt install build-essential` to install gcc at first.\n\nThen, run:\n\n```shell\ngit clone https://github.com/github0null/sdcc-binutils-mcs51.git\ncd sdcc-binutils-mcs51\ngit submodule update --init --recursive\ncd build\n./do_all\n```\n\nAfter compilation is completed, the generated binary is located in: `build/_install`\n\n## Build It For win32\n\nPlease install `x86_64-w64-mingw32-gcc` and `libz-mingw-w64-dev` first.\n\ncd to build-win32 and run:\n\n```shell\n./binutils_configure\n./binutils_make\n./sdcc_configure\n./sdcc_make\n```\n\n# Usage\n\nPlease refer to the Makefile in the `examples` directory\n\n```makefile\nmain.hex: main.o delay.o foo.o\n  @echo \"link $@\"\n  $(CC) -mmcs51 --model-small --stack-auto --nooverlay --out-fmt-ihx -Wl,--print-memory-usage -o $@ $^\n\n%.o: %.c | Makefile\n  @echo \"CC $\u003c\"\n  @$(CC) -c -mmcs51 --model-small --stack-auto --nooverlay -o $@ $\u003c\n```\n\n## Absolute address reference\n\nIf you want to use an absolute address reference for 'data idata xdata code', please implement it by referring to the following snippet:\n\n```c\nextern __xdata unsigned char REG_1_RES; // 0xCA00\nextern __xdata unsigned char REG_2;\t// 0xCA01\nvoid dummy()\n{\n  __asm\n    .globl _REG_1_RES, _REG_2\n    .section .xdata, \"aw\"\n    .equ _REG_1_RES, 0xCA00\n    .equ _REG_2, 0xCA01\n  __endasm;\n}\n```\n\nAnother more convenient method is to directly pass the compilation parameters `-Wl,--defsym=_REG_1_RES=0xCA00 -Wl,--defsym=_REG_2=0xCA01` to directly define the absolute position of the symbol.\n\nAnd then define a declaration in you code:\n\n```c\nextern __xdata unsigned char REG_1_RES;\nextern __xdata unsigned char REG_2;\n```\n\n\u003e Note: SDCC will add a '_' prefix for the symbol\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub0null%2Fsdcc-binutils-mcs51","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub0null%2Fsdcc-binutils-mcs51","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub0null%2Fsdcc-binutils-mcs51/lists"}