{"id":15172814,"url":"https://github.com/antonioberna/call-assembly-from-c","last_synced_at":"2026-01-19T06:01:30.458Z","repository":{"id":241663342,"uuid":"807369370","full_name":"AntonioBerna/call-assembly-from-c","owner":"AntonioBerna","description":"Simple project that combine the power of Assembly language with the power of C language","archived":false,"fork":false,"pushed_at":"2024-06-12T02:38:27.000Z","size":11,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T03:15:32.819Z","etag":null,"topics":["aarch64","armv8-a","assembly","c","calling-conventions","intel","raspberry-pi-3","x86"],"latest_commit_sha":null,"homepage":"","language":"Assembly","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/AntonioBerna.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-05-29T01:12:39.000Z","updated_at":"2024-11-02T14:27:28.000Z","dependencies_parsed_at":"2024-06-04T00:23:37.610Z","dependency_job_id":"efe78137-c6f9-4fc9-9e2f-1da0cb8425e6","html_url":"https://github.com/AntonioBerna/call-assembly-from-c","commit_stats":{"total_commits":7,"total_committers":3,"mean_commits":"2.3333333333333335","dds":0.5714285714285714,"last_synced_commit":"df3b73c7afe2185776ed18542d7dde5c4471c79e"},"previous_names":["antonioberna/call-x86-from-c","antonioberna/call-assembly-from-c"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AntonioBerna/call-assembly-from-c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioBerna%2Fcall-assembly-from-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioBerna%2Fcall-assembly-from-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioBerna%2Fcall-assembly-from-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioBerna%2Fcall-assembly-from-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AntonioBerna","download_url":"https://codeload.github.com/AntonioBerna/call-assembly-from-c/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioBerna%2Fcall-assembly-from-c/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28562232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T03:31:16.861Z","status":"ssl_error","status_checked_at":"2026-01-19T03:31:15.069Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["aarch64","armv8-a","assembly","c","calling-conventions","intel","raspberry-pi-3","x86"],"created_at":"2024-09-27T10:20:20.263Z","updated_at":"2026-01-19T06:01:30.441Z","avatar_url":"https://github.com/AntonioBerna.png","language":"Assembly","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to call Assembly functions from C\n\n## Introduction\n\nThis is a simple project that combine the power of `Assembly` language with the power of `C` language. In this project I have create a basic calculator with the four fundamental operations, namely sum, subtract, multiplication and division. Obviously this is not a large-scale production project, but it represents a tool for educational purposes. In fact, in this project three versions of `Assembly` language were implemented and used: `AT\u0026T`, `Intel` and `ARM`.\n\n\u003e [!WARNING]\n\u003e This code has only been tested on `Manjaro Linux` (for `AT\u0026T Assembly` and `Intel Assembly`) and `Raspberry Pi 3 Model B` (for `ARM Assembly` based on `aarch64` run on `Raspbian` operating system). If you experience problems using other operating systems, such as `Windows` or `macOS`, make sure you have the appropriate skills or risk damaging your equipment.\n\n## Mini docs\n\nDownload the repository to your computer using the following command:\n\n```shell\ngit clone https://github.com/AntonioBerna/call-assembly-from-c.git\n```\n\nonce we are inside the project folder we can use one of the following programs:\n\n```shell\n./build.sh ATT\n# or\n./build.sh intel\n# or\n./build.sh arm\n# or\n./build.sh clean\n```\n\nin fact, leaving aside the last command which is used to eliminate the final executables, the first two commands represent the type of `Assembly` that is used and therefore combined with the `C` language. Obviously we are not talking about architecture, but only and exclusively about syntax preferences. In fact, the dear `AT\u0026T Assembly` has for each instruction it uses a syntax of the type:\n\n```assembly\nistrX %source, %destination\n```\n\nwhere `X` represents the number of bytes of registers that will be used as source and destination. In particular we can choose between `b` (1 byte = 8 bits), `l` (2 bytes = 16 bits), `w` (4 bytes = 32 bits) and `q` (8 bytes = 64 bits). This type of `Assembly` is a classic but can sometimes be cumbersome. In fact, for this very reason many people prefer to use or read the `Intel Assembly`:\n\n```assembly\nistr source, destination\n```\n\nAs we can see, by not having to specify the number of bytes/bits, by not having to specify the `%` symbol and by not having to specify the `$` symbol for immediate values, this syntax is simpler and more pleasant.\n\nFinally the syntax of `ARM Assembly` is very different from the previous ones and appears, in the simplest case, as follows:\n\n```assembly\nistr destination, operand1, operand2\n```\n\nin fact we note the presence of 3 parameters. However, in this type of `Assembly` we can also use 2 parameters, based on the type of instruction we want to use.\n\nOnce the command has been chosen, the executable file will be created inside the `build` directory. Therefore we can run our code using the following command:\n\n```shell\n./build/ATT-calculator\n# or\n./build/intel-calculator\n# or\n./build/arm-calculator\n```\n\ngetting the following message:\n\n```shell\nUsage: ./build/ATT-calculator [add|sub|mul|div|test] [x] [y]\n# or\nUsage: ./build/intel-calculator [add|sub|mul|div|test] [x] [y]\n# or\nUsage: ./build/arm-calculator [add|sub|mul|div|test] [x] [y]\n```\n\nThen simply follow the instructions in the message obtained to use the program correctly.\n\n\u003e [!NOTE]\n\u003e I would like to point out that there is also the `test` option which allows us to execute a function to test some very simple operations.\n\n## How to read Assembly code\n\nThe `System V Application Binary Interface (ABI)` is a set of conventions used on Unix-like operating systems, such as `Linux` and `Solaris`, to define how functions should be called and how data should be passed between functions in a compiled program. `System V ABI` calling conventions for 64 bit systems include:\n\n- Return Register: The return value of a function is stored in the `RAX` register.\n\n- Parameter passing: The first six integers or pointers are passed into registers `RDI`, `RSI`, `RDX`, `RCX`, `R8` and `R9`. The other parameters are passed onto the `stack`, in order from left to right.\n\n- Saving registers: The called function must save the `RBX`, `RSP`, `RBP`, `R12`, `R13`, `R14`, and `R15` registers if it uses them and restore them before returning control to the caller.\n\n- Stack alignment: The `stack` must always be aligned to a multiple of 16 bytes at the start of a function.\n\n- Data Structure Conventions: Data structures smaller than 16 bytes and unions are passed into registers if possible. Data structures larger than 16 bytes are passed by reference.\n\n- Management of local variables: Local variables are usually allocated on the `stack`, moving the stack pointer (`RSP`).\n\n- Handling function calls: The calling function is responsible for cleaning up the `stack` after the call, removing passed parameters.\n\nThese conventions are designed to maximize the efficiency and interoperability of programs on operating systems that adopt the `System V ABI` for 64 bit architectures. They ensure that functions can communicate consistently and that code can be effectively optimized by the compiler.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioberna%2Fcall-assembly-from-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonioberna%2Fcall-assembly-from-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioberna%2Fcall-assembly-from-c/lists"}