W
(8 bit) or _rO
(16 bit) or _r0-_r1
(32 bit). The result replaces the first operand on the stack, but may have a different size.
In fact, the code generated by cpik might differ from this scheme, depending on various optimizations performed by the compiler.
Due to hardware limitation, the total amount of local non static data declared in a function can't exceed 127 bytes. Data local to a function are formal parameters, local variables, and temporaries. Excepted for very complex expressions, temporaries never exceed a few bytes, so, as a rule of thumb, about 100 bytes are always available.
In the following example, 2 bytes are used for parameters u and v, and a third one is used for storing a temporary.
int h(int u, int v) { return (u+v)/3 ; }
Here is the result of the compilation:
C18_h movff INDF0,PREINC0 ; push u onto the stack movlw -2 movf PLUSW0,W,0 ; move v to W addwf INDF0,F,0 ; replace the stacked copy of u by u+v movlw 3 ICALL div8 ; divide top of stack data by 3 movff POSTDEC0,_r0 ; pop result to _r0L return 0
Notice that the space used to store the local variables is not necessarily the sum of space needed for each variable. For example, in the following code, j and z are stored at the same address, so only 2 bytes are used on the stack to store k, j and z.
int func2(int k) { if( k > 27) { int j = 3 ; k += j ; } else { int z = 23 ; k += z ; } return k ; }
Alain Gibaud 2015-07-09