How do I compile the asm generated by GCC?

前端 未结 7 2005
南方客
南方客 2020-12-04 06:18

I\'m playing around with some asm code, and something is bothering me.

I compile this:

#include 

int main(int argc, char** argv){
  p         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 06:57

    gcc can use an assembly file as input, and invoke the assembler as needed. There is a subtlety, though:

    • If the file name ends with ".s" (lowercase 's'), then gcc calls the assembler.
    • If the file name ends with ".S" (uppercase 'S'), then gcc applies the C preprocessor on the source file (i.e. it recognizes directives such as #if and replaces macros), and then calls the assembler on the result.

    So, on a general basis, you want to do things like this:

    gcc -S file.c -o file.s
    gcc -c file.s
    

提交回复
热议问题