這是用PIC組合語言寫出來的16進位轉換十進位程式碼,
可以分別將百位數、十位數及個位數字取出來,適用於8位元的單晶片

輸入:w暫存器
輸出:w暫存器

程式碼內容:
 
;******取出百位數字******
 
GETHNDS                       
               movwf      t1
               clrf     w2
gethnds_loop         
               movlw      .100
               incf          w2,f
               subwf       t1,f
               btfsc           STATUS,C
               goto           gethnds_loop
               decf            w2,w
               return
                              
;******取出十位數字******
 
GETTENS                            
               movwf      t1
               clrf     w2
gettens_loop          
               movlw      .10
               incf          w2,f
               subwf       t1,f
               btfsc        STATUS,C
               goto        gettens_loop
               decf         w2,w
               goto         GETONES
 
;******取出個位數字******
              
GETONES                           
               movwf      w2
               movlw      .10
deltens_loop          
               subwf       w2,f
               btfsc        STATUS,C
               goto        deltens_loop
               addwf      w2,w                    
               return

文章標籤
全站熱搜
創作者介紹
創作者 chipfish 的頭像
chipfish

魚的方舟 *單晶片嵌入式系統工作室 ( Microcontroller, Embedded system )

chipfish 發表在 痞客邦 留言(0) 人氣(6,031)