Home Swift UNIX C Assembly Go Web MCU Research Non-Tech

How to generate assembly code using Clang

2022-08-13 | Assembly | #Words: 160 | 中文原版

Sometimes for learning or debuging, I need to view the assembly code of the program. This is very convenient in many GUI IDEs. For example, in Xcode, just click “Product”-“Perform Action”-“Assemble File Name”, as follows:

Assembly code generated by Xcode

How to implement it in the terminal?

First create a C file test.c. The content is as follows:

#include <stdio.h>

int main() {
    printf("hello world!\n");
    return 0;
}

Then use the following command:

$ cc -S test.c

it will generate a file named as test.s, which contains assembly language, as follows:

Contents of the assembly code file generated using the above command

I hope these will help someone in need~