>> Part of the point of inline assembly is that it allows you to specify
>> input and output registers; the compiler will take care of loading and
>> storing the appropriate values if necessary. In many cases it isn't
>> because they'll already be in registers due to the surrounding code and
>> the compiler just passes the appropriate register to your assembly code.
>> If not, the compiler handles the loads and stores for you.
>
> No, much of the point of inline assembly is that you are 100% in control
> at that point. The code must also be reasonably transparent, and easy to
> see what's happening. That's not the case with the (presumably gcc)
> example shown. The AT&T syntax doesn't help, having to quote things in
> strings makes it worse, and having to use this weird interface to
> specify where values are coming from, and where they're going to, makes
> it impossible.
The purpose of in-line assembly is to allow you to specify something
that you can't (as efficiently) in C code itself. By its nature, it is
"non-portable". Some implementations of in-line assembly just provide
for the literal insertion of assembly code into the code stream (this is
fairly simple for the compiler), with maybe some smarts in the optimizer
to figure out what has happened to its register store. This type of
in-line assembly can actually cause "pessimisms" as its presence can
greatly interfere with the compilers ability to optimize the code.
Another method of implementing in-line assembly inserts more abstract
operations, which do not necessarily specify exact registers to be used,
but register classes and transfer flow from one instruction to another
(normally you CAN specify an exact register if needed). This form is
more common on RISC-like machines with a rich set of registers and many
operations can work on a variety of registers. In this case, the
optimizer works with the in-line assembly and does what optimizers are
good at, register scheduling. Yes, the programmer has given up some
control over the exact code sequence being executed (but often still has
ways to keep that control if they wanted to), but has gained in the
ability for the compiler to optimize the code better.
In this case, if the value happened to already have been in a suitable
register, than the code could just use that register instead of
reloading the value from memory. If it was in a register not suitable
for the instruction, a quicker move operation from the register instead
of out to memory can be used.