• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統 > 設計應用 > PIC單片機無符號BCD加法子程序

    PIC單片機無符號BCD加法子程序

    作者: 時間:2011-03-08 來源:網絡 收藏

    !--StartFragment-->;******************* 無符號 BCD 加法 ***************
    ;
    ; This routine performs a 2 Digit Unsigned BCD Addition
    ; It is assumed that the two BCD numbers to be added are in
    ; locations Num_1 Num_2. The result is the sum of Num_1+Num_2
    ; and is stored in location Num_2 and the overflow carry is returned
    ; in location Num_1
    ;
    ; Performance :
    ; Program Memory : 25
    ; Clock Cycles : 17 ( worst case )
    ;
    ;*******************************************************************;
    ;
    Num_1 equ 8 ; 加數寄存器,加法和的高位寄存器。
    result equ 8
    ;
    Num_2 equ 9 ; 加數寄存器,加法和的低位寄存器。
    O_flow equ 9
    ; 其它的寄存器自己定義
    ;
    BCDAdd
    movf Num_1,W
    clrf Num_1 ;clear num_1
    addwf Num_2,1 ; do binary addition
    btfsc STATUS,C ; 256 then skip
    goto inc_n1n2 ;else inc all
    movlw 66 ;add 66
    addwf Num_2,1 ;/
    btfss STATUS,DC ;half carry?
    goto sub_06 ;no then subtract
    btfss STATUS,C ;full carry?
    goto sub_60 ;yes then subtract
    inc_n1
    incf Num_1,1 ;inc it
    retlw 0 ;clr w
    sub_06
    btfss STATUS,C ;full carry
    goto sub_66 ;yes subtract 66
    movlw 6 ;else subtract 6
    goto sub_com ;do common
    sub_66
    movlw 66
    sub_com
    subwf Num_2,1
    retlw 0
    sub_60
    movlw 60
    goto sub_com
    inc_n1n2
    movlw 66
    addwf Num_2,1
    goto inc_n1
    ;
    ;********************************************************************
    ; 測試程序(注意它怎樣使用該子程序)
    ;*********************************************************************
    main
    movlw 99
    movwf Num_1 ; Set Num_1 = 99 ( max BCD digit )
    movlw 99
    movwf Num_2 ; Set Num_2 = 99
    ;
    call BCDAdd ; After addition, Num_2 = 98
    ; ; and Num_1 = 01 ( 99+99 = 198 -> max number )
    ;
    self goto self ;如不是測試程序,這句無用
    ;
    ;
    org 1FF
    goto main
    ;
    END




    評論


    相關推薦

    技術專區

    關閉
    主站蜘蛛池模板: 尼木县| 沙坪坝区| 泸水县| 鞍山市| 方正县| 新疆| 广东省| 横峰县| 陕西省| 麻城市| 五家渠市| 宽甸| 民乐县| 滦南县| 且末县| 碌曲县| 梁平县| 海林市| 皮山县| 内黄县| 同仁县| 桂林市| 苏尼特左旗| 乐陵市| 黄平县| 伽师县| 鄂托克前旗| 荣昌县| 金溪县| 淅川县| 静安区| 连南| 邓州市| 敖汉旗| 琼中| 平原县| 桑日县| 库尔勒市| 敦化市| 宝丰县| 东安县|