Page 351 - Programming Microcontrollers in C
P. 351

336    Chapter 6  Large Microcontrollers

                          and stack; program, multiple 65 K banks for code and one 65 K bank
                          for data and stack; data, one 65 K bank for code and multiple 65K
                          banks for data and stack; and finally far, multiple 65 K banks for code,
                          data, and stack. With each of these memory models, it is necessary to
                          keep track and often change the contents of the extension registers. As
                          a result, with these models, it is necessary to alter slightly the stacking
                          sequence. Such a sequence is shown in Figure 6-5. The function call
                          that will cause the stack to be arranged as is shown in the figure below
                          has four arguments. From left to right these arguments are xlen,
                          *xdata, ylen, and *ydata. The lengths are simple character
                          values, and the pointers in this case must be 20-bit values. If a function
                          call to this routine is compiled with the small memory model, or any
                          other model with the exception of the compact model, the stacking
                          will include the extension registers as shown below.





                                        Stack Contents



                                                         SP after XK is saved
                          X after tsx        XK          SP after pushm x, d
                                              X
                                              D          SP after function call
                            SP at rts
                                            CCR
                                             PC          SP before function call
                                           *xdatak
                                            *xdata
                                             ylen
                                           *ydatak
                                            *ydata





                              Figure 6-5: Stacking Sequence That Passes Extension Registers
                              The B register, which is the righthand side of the D register, will
                          contain the left-most parameter when the function is called. There­
                          fore, the parameter xlen will be found in the least significant bits of
                          the location labeled D in the above stack outline. The routine shown
                          below will make use of both the X and the Y registers. The compiler
                          allows for all registers with the exception of the X register to be
   346   347   348   349   350   351   352   353   354   355   356