Ask coding questions

← Back to all posts
Asm
Highwayman (1455)

So recently I was looking at a post in learn about bash scripting and I found
an interesting tidbit: you can compile c/c++ to assembly and compile that assembly to machine code.
Now the reason this matters to me is that it seems as if we could just straight up compile asm to machine code with that same gcc compiler. Would that work?

Comments
hotnewtop
CoolqB (164)

Yes, it's possible to get GCC/G++ to output the intermediate assembly code (simply pass the -S flag to the compiler). You can additionally pass the -masm=intel flag to output assembly syntax (my preference) rather than AT&T.

To compile to machine code you can either try to get another compiler (such as MASM) to compile your assembly, or use gcc to compile it. For instance gcc test.s will output a.exe.

theangryepicbanana (1692)

Yea you can compile assembly using the gcc. Not sure what version but it is there