11.07.2015 Views

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ICCV8 <strong>for</strong> AVR – C Compiler <strong>for</strong> Atmel AVRPreserved RegistersAn assembly function must save <strong>and</strong> restore <strong>the</strong> following registers. These registersare called preserved registers, since <strong>the</strong>ir contents are unchanged by a function call.Local variables are assigned to <strong>the</strong>se registers by <strong>the</strong> <strong>compiler</strong>. R28/R29 or Y (this is <strong>the</strong> frame pointer) R10/R11/R12/R13/R14/R15/R20/R21/R22/R23You can ask <strong>the</strong> <strong>compiler</strong> not to use <strong>the</strong> registers R20, R21, R22, <strong>and</strong> R23, ; <strong>the</strong>n youdo not need to save <strong>and</strong> restore <strong>the</strong>se four registers. See Global RegistersVolatile RegistersThe o<strong>the</strong>r registers: R0/R1/R2/R3/R4/R5/R6/R7/R8/R9/R24/R25/R26/R27/R30/R31 SREGcan be used in a function without being saved or restored. These registers are calledvolatile registers, since <strong>the</strong>ir contents may be changed by a function call.Interrupt H<strong>and</strong>lersSince an interrupt h<strong>and</strong>ler operates asynchronously to <strong>the</strong> normal program operation,<strong>the</strong> interrupt h<strong>and</strong>ler or <strong>the</strong> functions it calls must not modify any machine registers.There<strong>for</strong>e, an interrupt h<strong>and</strong>ler must save <strong>and</strong> restore all registers that it uses. This isdone automatically if you use <strong>the</strong> <strong>compiler</strong> capability to declare a C function as aninterrupt h<strong>and</strong>ler. If you write a h<strong>and</strong>ler in assembly <strong>and</strong> if it calls normal C functions,<strong>the</strong>n <strong>the</strong> assembly h<strong>and</strong>ler must save <strong>and</strong> restore <strong>the</strong> volatile registers, since normalC functions do not preserve <strong>the</strong>m.The exception is when you ask <strong>the</strong> <strong>compiler</strong> not to use <strong>the</strong> registers R20, R21, R22,<strong>and</strong> R23 ; <strong>the</strong>n <strong>the</strong> interrupt h<strong>and</strong>lers may use <strong>the</strong>se four registers directly.StructurePassing by ValueIf passed by value, a structure is always passed through <strong>the</strong> stack, <strong>and</strong> not inregisters. Passing a structure by reference (i.e., passing <strong>the</strong> address of a structure) is<strong>the</strong> same as passing <strong>the</strong> address of any data item; that is, a pointer to <strong>the</strong> structure(which is 2 bytes) is passed.143

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!