Myke's Home Page
|
"StakCall" ExperimentA Stack using the FSR can be used to pass data to and from subroutines in the PICmicro as is shown in this application.
The source code listed below can be accessed from the CD-ROM by clicking Here.
title "StakCall - Passing Subroutine Parms via Stack"
;
; This Program shows how to set up a psuedo-Stack and use it to pass
; Parameters between the Mainline and Routines.
;
; 99.11.13 - Updated for Second Edition
;
; Myke Predko
; 96.05.10
;
LIST P=16F84, F=INHX8M, R=DEC
INCLUDE "p16f84.inc"
; Registers
i equ 12 ; Registers to Operate on
j equ 13
Stack equ 14 ; Start of the virtual Stack
__CONFIG _CP_OFF & _WDT_OFF & _RC_OSC
PAGE
; Mainline of StakCall
org 0
movlw 4 ; Initialized the Variables
movwf i
movlw Stack ; Set up the Stack
movwf FSR
; j = Increment( i )
; Get the value of i + 1 and put it in "j"
incf FSR, f ; Make Space for the Sum
movf i, w ; Get First Value to Add and store on
movwf INDF ; the Stack
incf FSR, f
call Increment ; Increment the Value
decf FSR, f ; Get and Store the Sum
movf INDF, w
movwf j
Finished ; Finished, Just Loop Around Forever
goto $
; Increment Subroutine
Increment ; Add the Two Values on the Stack
decf FSR, f ; Get the First Value and Increment it
incf INDF, w
decf FSR, f ; Store the result
movwf INDF
incf FSR, f ; Reset the Stack Pointer
return
end
|