Page 172 - Programming Microcontrollers in C
P. 172

Microcontroller Memory    157

                          operations. The program can arbitrarily change the stack pointer value
                          so that room for automatic variables can be easily provided or elimi­
                          nated. In the small microcontrollers, automatic variables are stored
                          in RAM and their scope is not limited to the block in which they are
                          defined. Their access is limited to their block, however. Consider the
                          following code segment:
                   main()
                   {
                       int i;
                       .
                       .
                       .
                   }


                   void able(void)
                   {
                       int i;
                       .
                       .
                       .
                   }
                              The two occurrences of the variable i in this case will cause no
                          trouble because each i will be given a unique location in RAM and
                          the scoping arrangement will insure that any reference to iin main()
                          will not be confused with the i in able() and vice versa.
                              An important implication of this change in storage: recursion is
                          no longer available! Only one memory location is available for each
                          variable in the program. When a stack is used to store automatic
                          variables, a function can call itself and a new block is created each
                          time the function is entered. Thus, each time a function calls itself, a
                          new stack frame that contains space for all automatic storage in the
                          function is created. The function can call itself repeatedly as long as
                          there is space on the stack to create new stack frames for the succes­
                          sive calls. Without stack space for variable storage, recursion is
                          impossible.
                              A second limitation that occurs is in the available arguments for
                          function calls. The compiler C6805 for the M68HC05 family de­
                          fines an int as an 8-bit number and a long as a 16-bit number.
   167   168   169   170   171   172   173   174   175   176   177