;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PIC16F84A. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F84A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
NUM1 EQU 0X5A
NUM2 EQU 0X39
cblock 0x10
REG1
REG2
endc
ORG 0X00
Begin
banksel TRISA ;first make PORTA an input and PORTB an output
movlw 0x1F ;all PORTA pins to input mode
movwf TRISA
clrf TRISB ;all PORT pins to output mode
; now check PORTA to see if we want to add or subtract. Assume switch is on RA0
banksel PORTA ;port I/O is in bank zero
btfss PORTA,0 ;skip next instruction if RA0 = 1 (subtract requested)
goto AddMode
; if the previous line didn't take us to AddMode, subtract was requested
movlw NUM2 ;put NUM2 in the working register
sublw NUM1 ;subtract it from NUM1 with the result in the W register
movwf REG1 ;save the result in REG1
movf STATUS,W ;copy the status register contents to W
movwf REG2 ;and then to REG2
goto Finished
AddMode
movlw NUM1 ;put NUM1 in the working register
addlw NUM2 ;add NUM2 with the result in the W register
movwf REG1 ;save the result in REG1
movf STATUS,W ;copy the status register contents to W
movwf REG2 ;and then to REG2
Finished
end