A special keyword may be associated with a function declaring it as _naked. The _naked function modifier attribute prevents the compiler from generating prologue and epilogue code for that function. This means that the user is entirely responsible for such things as saving any registers that may need to be preserved, selecting the proper register bank, generating the return instruction at the end, etc. Practically, this means that the contents of the function must be written in inline assembler. This is particularly useful for interrupt functions, which can have a large (and often unnecessary) prologue/epilogue. For example, compare the code generated by these two functions:
volatile data unsigned char counter;For an 8051 target, the generated simpleInterrupt looks like:
Note, this is an outdated example, recent versions of SDCC generatewhereas nakedInterrupt looks like:
_nakedInterrupt:The related directive #pragma exclude allows a more fine grained control over pushing & popping the registers. While there is nothing preventing you from writing C code inside a _naked function, there are many ways to shoot yourself in the foot doing this, and it is recommended that you stick to inline assembler.
Next: 3.12.3 Use of Labels Up: 3.12 Inline Assembler Code Previous: 3.12.1 A Step by Contents Index 2008-02-29 |