3 ms·
> > In GCC, inline assembly has insane syntax. Probably on purpose, to discourage writing it. > Certain folks will mention it is because the compiler needs reg
by cesarb 2y ago
> > In GCC, inline assembly has insane syntax. Probably on purpose, to discourage writing it.
> Certain folks will mention it is because the compiler needs register usage info, yet PC compilers could and can, infer the usage as well, when parsing those asm blocks,
The compiler can only infer the register usage info for known instructions, but the whole point of inline assembly in GCC is to use instructions the compiler doesn't know about (and many of these have implicit register uses which can't be inferred from just looking at the assembly syntax, you really need to know what the instruction does). And in some cases, the register usage can't be inferred even for known instructions; for instance, the registers used by a "call xyz" instruction depend on how the "xyz" subroutine was implemented (it probably has a nonstandard calling convention, otherwise there would be no reason for using inline assembly to call it).
The "weird syntax" actually matches closely how known instructions are described within GCC itself, which makes sense since GCC inline assembly is all about teaching it about new (or non-standard) machine instructions (or pseudo-instructions), without having to modify and recompile the compiler.
- pjmlp 2y agoYeah, which kind of proves the point of the design of UNIX compilers, versus other platforms. I know GCC since 1995, and am I quite aware why such bad developer experience should be preferable kind of argumentation.