新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > PIC單片機無符號 BCD 減法

        PIC單片機無符號 BCD 減法

        作者: 時間:2011-03-08 來源:網(wǎng)絡 收藏
        ;*******************無符號 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

        評論


        相關推薦

        技術專區(qū)

        關閉
        主站蜘蛛池模板: 黔西| 丽水市| 体育| 讷河市| 陇西县| 安义县| 凯里市| 岫岩| 大化| 汽车| 伊吾县| 乃东县| 息烽县| 筠连县| 南漳县| 德兴市| 武清区| 巩留县| 古丈县| 甘泉县| 荣成市| 乌拉特前旗| 绥化市| 车致| 田林县| 互助| 榕江县| 清河县| 漯河市| 汉中市| 偏关县| 顺昌县| 白水县| 库伦旗| 泰顺县| 连江县| 郯城县| 定陶县| 蓬莱市| 孟津县| 宁海县|