Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC: Inline assembly - good for?

So I just found out GCC could do inline assembly and I was wondering two things:

  1. What's the benefit of being able to inline assembly?

  2. Is it possible to use GCC as an assembly compiler/assembler to learn assembly?

I've found a couple articles but they are all oldish, 2000 and 2001, not really sure of their relevance.

Thanks

like image 228
Nope Avatar asked Nov 26 '22 23:11

Nope


1 Answers

The benefit of inline assembly is to have the assembly code, inlined (wait wait, don't kill me). By doing this, you don't have to worry about calling conventions, and you have much more control of the final object file (meaning you can decide where each variable goes- to which register or if it's memory stored), because that code won't be optimized (assuming you use the volatile keyword).

Regarding your second question, yes, it's possible. What you can do is write simple C programs, and then translate them to assembly, using

gcc -S source.c

With this, and the architecture manuals (MIPS, Intel, etc) as well as the GCC manual, you can go a long way.

There's some material online.

http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/

The downside of inline assembly, is that usually your code will not be portable between different compilers.

Hope it helps.

like image 98
Tom Avatar answered Jan 12 '23 01:01

Tom