|
|
In earlier versions of C the asm facility was primitive. You included a line that looked like a call on the function asm , which took one argument, a string:
asm("assembly instruction here");Unfortunately this technique has shortcomings when the assembly instruction needs to reference C language operands. You have to guess the register or stack location into which the compiler would put the operand and encode that location into the instruction. If the compiler's allocation scheme changed, or, more likely, if the C code surrounding the asm changed, the correct location for the operand in the asm would also change. You would have to be aware that the C code would affect the asm and change it accordingly.
The new facility presented here is upwardly compatible with old code, since it retains the old capability. In addition, it allows you to define asm macros that describe how machine instructions should be generated when their operands take particular forms that the compiler recognizes, such as register or stack variables.
The optimizer (cc -O) may work incorrectly on C programs that use the asm facility, particularly when the asm macros contain instructions or labels that are unlike those that the C compiler generates. Furthermore, you may need to rewrite asm code in the future to maximize its benefits as new optimization technology is introduced into the compilation system.