新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PIC單片機(jī)無符號(hào) BCD 減法

PIC單片機(jī)無符號(hào) BCD 減法

作者: 時(shí)間:2011-03-08 來源:網(wǎng)絡(luò) 收藏
;*******************無符號(hào) BCD 減法***************;; This routine performs a 2 Digit Unsigned BCD Subtraction.; It is assumed that the two BCD numbers to be subtracted are in; locations Num_1 & Num_2. The result is the difference of Num_1 & Num_2; ( Num_2 - Num_1) and is stored in location Num_2 and the overflow carry; is returned in location Num_1.;; Performance :; Program Memory : 31; Clock Cycles : 21 ( worst case );;*******************************************************************;Num_1 equ 8 ; Overflow flow carry overwrites Num_1result equ 8;Num_2 equ 9 ; Num_2 - Num_1 overwrites Num_2O_flow equ 9;;其它寄存器自己定義;BCDSubmovf Num_1,wsubwf Num_2clrf Num_1rlf Num_1btfss STATUS,DCgoto adjst1btfss Num_2,3 ; Adjust LSD of Resultgoto Over_1btfsc Num_2,2goto adjst1 ; Adjust LSD of Resultbtfss Num_2,1goto Over_1 ; No : Go for MSDadjst1movlw 6subwf Num_2Over_1btfss Num_1,0 ; CY = 0 ?goto adjst2 ; Yes, adjust MSD of resultclrf Num_1btfss Num_2,7 ; No, test for MSD >9RETLW 0btfsc Num_2,6goto adjst2btfss Num_2,5RETLW 0adjst2movlw 60 ; add 6 to MSDsubwf Num_2clrf Num_1btfss STATUS,CARRY ; test if underflowRETLW 0movlw 1movwf Num_1OverRETLW 0;;********************************************************************; 測(cè)試程序(注意用法,Num_2-Num_1=Num_2);*********************************************************************mainmovlw 23movwf Num_1 ; Set Num_1 = 23movlw 99movwf Num_2 ; Set Num_2 = 99call BCDSub ; After subtraction, Num_2 = 76 ( 99-23 ); ; and Num_1 = 0 ( indicates positive result );self goto self ; 如不是測(cè)試程序,本句無用;org 1FFgoto main;END

評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉