;**********************************************************************
;   This file contains an example of how to use subroutines.          *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename:	    calltest.asm                                      *
;    Date:          January 25, 2006                                  *
;    File Version:  1                                                 *
;                                                                     *
;    Author:        CDR Charles B. Cameron                            *
;    Company:       United States Naval Academy                       *
;                                                                     * 
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required: p16f874.inc                                      *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:        None                                               *
;                                                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************


	list      p=16f874            ; list directive to define processor
	#include <p16f874.inc>        ; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _RC_OSC & _WRT_ENABLE_ON & _LVP_ON & _CPD_OFF

; Watch dog timer is disabled

;***** VARIABLE DEFINITIONS
a_init	equ	3	; Initial value for aa
b_init	equ 4	; Initial value for bb
	cblock h'20'
		aa	; Storage for aa
		bb	; Storage for bb
		cc	; Storage for cc
	endc
		
main

; remaining code goes here

	movlw	a_init	; Load aa
	movwf	aa
	movlw	b_init	; Load bb
	movwf	bb
	clrw			; Clear W and cc to see
	clrf	cc		; effect of subroutine
	
	call	AddTwoInts	; Change PC, save old PC
	movf	cc,w	; Retrieve result from cc
	
	goto	main	; Repeat indefinitely
	
AddTwoInts
	movf	aa,W	; Retrieve aa
	addwf	bb,W	; Add in bb
	movwf	cc		; Save result as cc
	clrw			; Clear W to show results more clearly
	return			; Retrieve saved PC from stack


		END                       ; directive 'end of program'


