; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; ADD/SUBTRACT n1, n2 ; Add two 16-bit numbers to produce a 16-bit result, permitting overflow. ; Add the two's complement of one 16-bit number to another 16-bit number ; to perform subtraction, permitting underflow. ; Addition: n1 = n1 + n2 ; Subtraction: n1 = n1 - n2 ; Device data and reset vector P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 n1H Res d'1' ; MSB of n1. n1L Res d'1' ; LSB of n1. n2H Res d'1' ; MSB of n2. n2L Res d'1' ; LSB of n2. org 0 start MOVLW d'0' ; Outputs for LEDs to TRIS 6h MOVLW d'0' ; display 16-bit result. TRIS 7h MOVLW 0x00C8 ; Problem: C836h-2575h MOVWF n1H MOVLW 0x36 MOVWF n1L MOVLW 0x25 MOVWF n2H MOVLW 0x75 MOVWF n2L CALL Sub16 ; n1 = n1 - n2 MOVF n1L,w ; Show result in binary on MOVWF 6h MOVF n1H,w ; LEDs connected to ports. MOVWF 7h GOTO $ ; Endless loop Sub16 COMF n2H ; Take two's complement COMF n2L ; of n2. If zero, n2L BTFSC status,z ; overflowed, so carry INCF n2H ; into n2H. Add16 MOVF n2L,w ; Add the LSBs. If carry, ADDWF n1L BTFSC status,c ; increment MSB of sum. INCF n1H MOVF n2H,w ; Add the MSBs ADDWF n1H RETLW 0h end