Myke's Home Page

Book CD-ROM Home

File Copying/Harddrive Setup

Development Tools

Experiments

Projects

Useful Code Snippets and Macros

Introduction to Electronics

Introduction to Programming

Datasheets

PCBs

Links

McGraw-Hill Professional Publishing

"CallBUp" Experiment

The PICmicro's program counter stack is two entries deep for the low end, eight entries deep for the mid-range, sixteen deep for the PIC17CXX and thirty one entries deep for the PIC18CXX. If too many calls are made in an application, the program counter stack is overwritten and the actual return address is lost. What happens when the stack is overwritten is demonstrated in this experiment.

A good rule of thumb for the PICmicro's program counter stack is to always leave two stack entries in the worst case condition. The worst case condition can be considered to be the situation where the mainline is at its deepest point in execution plus the interrupt handler active in the deepest point in its execution. For the mid-range this means that the stack should never be more than six entries deep, the PIC17C4X never more than fourteen and the PIC18CXX should never be more than twenty-nine.

The source code listed below can be accessed from the CD-ROM by clicking Here.

 title  "CallBUp - Blowing up the PC Stack."
;
;  This Program calls a bunch of routines to show how the Stack can
;   be exceeded and an incorrect address returned
;
;  99.11.13 - Updated for Second Edition
;
;  Myke Predko
;  96.05.13
;
  LIST P=16F84, R=DEC
  INCLUDE "p16f84.inc"

;  Registers

 __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC

  PAGE
;  Mainline of CallBUp

  org 0

  call  Prog1                   ;  Now, Just Call Subroutines

Finished                        ;  Finished, Just Loop Around Forever
  goto  $

;  Subroutines
;  The Subroutines consist of:
;  Prog_at_Label
;    calling Prog_at_label_plus_one
;    return

Prog1

  call  Prog2

  return

Prog2

  call  Prog3

  return

Prog3

  call  Prog4

  return

Prog4

  call  Prog5

  return

Prog5

  call  Prog6

  return

Prog6

  call  Prog7

  return

Prog7

  call  Prog8

  return

Prog8

  call  Prog9

  return

Prog9

  call  Prog10

  return

Prog10

  return                        ;  At End of "Call" Chain, Start Returning

  end
              

Click Here to look at the fourteenth experiment - Table0