新聞中心

        EEPW首頁 > 嵌入式系統(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;;********************************************************************; 測試程序(注意用法,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 ; 如不是測試程序,本句無用;org 1FFgoto main;END

        評論


        相關(guān)推薦

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

        關(guān)閉
        主站蜘蛛池模板: 长顺县| 专栏| 庄河市| 屏东市| 岳池县| 青阳县| 泗水县| 寻甸| 枣阳市| 余姚市| 滕州市| 息烽县| 岗巴县| 花莲县| 江川县| 攀枝花市| 五原县| 青阳县| 古交市| 凉城县| 银川市| 三台县| 尼木县| 南京市| 阳泉市| 江安县| 响水县| 雅江县| 平山县| 邵东县| 于田县| 绍兴县| 德阳市| 迁西县| 鄢陵县| 阜平县| 哈尔滨市| 高唐县| 南召县| 新闻| 宁蒗|