.nolist ; avr_registers.inc - my CPU register usage and naming for AVR ; author Neil Franklin, last modification 2008.11.16 ; register usage and calling convention ; callee-push/pop minimises code but allways runtime overhead ; caller-push/pop minimises runtime overhead but repeated code ; large register sets like AVR allow splitting registers into 2 groups ; some used for callee, caller pushes, only if it needs these ; some used for caller, callee pushes, only if it needs these ; with an good splitting policy only push/pop in multilevel calls ; instruction set specialty registers, 16bit ; registers for 16bit X Y and Z addressing ; on all 16bit pairs use *H:*L naming .def ZL = R30 ; often special use, often changes, ideal for temp .def ZH = R31 ; callee may use any time, caller push if still in use .def YL = R28 ; only non-Z with +q addresseing, potential frame pointer .def YH = R29 ; must stay robust, callee push if used as third .def XL = R26 ; often 2 pointers are quickly needed, not Y for this .def XH = R27 ; callee may use any time, caller push if still in use ; other registers for 16bit arithmetic (adiw, sbiw) ; on all 16bit pairs use *H:*L naming, D = Double .def DL = R24 ; never changed unneccessary, can have lasting stuff .def DH = R25 ; must survive entire caller, callee push if used ; registers for 16bit multiplication result ; on all 16bit pairs use *H:*L naming, M = Multiplication .def ML = R0 ; change at any multiplication, not lasting stuff, use as temp .def MH = R1 ; callee may use any time, caller push if still in use ; instruction set normal registers, 8bit ; registers with immediate instructions (ldi, subi, sbci, cpi, andi, ori) ; are rest of R16..R31, gives R16..R23 ; immediate temporaries (and parameters) for general computation, T = Temp .def T0 = R16 ; often changed, callee fast usage, caller push if still in use .def T1 = R17 .def T2 = R18 ; immediate saved (and (loop) counters), S = Save .def S0 = R19 ; must survive entire caller, incl calls, callee push if used .def S1 = R20 ; are used longer, may be renamed to make code more readable .def S2 = R21 ; immediate for interupts service routines, I = Interrupt .def I0 = R22 ; not used in normal code, only for interrupt, ISR without push .def I1 = R23 ; therefore also survive between multiple interrupts ; instruction set reduced functionality registers, 8bit ; registers without immediate instructions ; are rest of R0..R15, gives R2..R15 ; use all as fast direct access (register not memory) variables, V = Variable .def V0 = R2 ; must survive entire program, callee push if used .def V1 = R3 .def V2 = R4 .def V3 = R5 .def V4 = R6 .def V5 = R7 .def V6 = R8 .def V7 = R9 .def V8 = R10 .def V9 = R11 .def V10 = R12 .def V11 = R13 .def V12 = R14 .def V13 = R15 .list