tyw的笔记 https://bbs.21ic.com/?7589 [收藏] [复制] [RSS]

日志

HT给的例程,少了TD0~TD4清0,害人不浅

已有 1225 次阅读2015-12-25 11:03 |系统分类:兴趣爱好| 二进制

;********************************
;* 四字节二进制转BCD码                        *
;* 入口:DATA3 DATA2 DATA1 DATA0     *
;* 出口:TD4 TD3 TD2 TD1 TD0             *
;********************************
BTOD_32:        MOV     A,20H
                MOV     COUNT0,A
BTOD1:         
;/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
;************************
;* TD0~TD4清0是必需的! *               ;TMD,HT例程中少这一步,害人不浅
;************************
                CLR     TD0                          ;运算前暂存器先清"0"
                CLR     TD1
                CLR     TD2
                CLR     TD3
                CLR     TD4
;/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/             
                CLR     [0AH].0
                RLC     DATA0
                RLC     DATA1
                RLC     DATA2
                RLC     DATA3
                MOV     A,TD0
                ADC     A,TD0
                MOV     TD0,A
                DAA     TD0
                MOV     A,TD1
                ADC     A,TD1
                MOV     TD1,A
                DAA     TD1
                MOV     A,TD2
                ADC     A,TD2
                MOV     TD2,A
                DAA     TD2
                MOV     A,TD3
                ADC     A,TD3
                MOV     TD3,A
                DAA     TD3
                MOV     A,TD4
                ADC     A,TD4
                MOV     TD4,A
                DAA     TD4
                SDZ     COUNT0
                JMP     BTOD1
                RET
               
               
这是HT给的例程,少了TD0~TD4清0,下面程序中把TD0读到A再迭加,前提是运算前TD0~TD4都清0了,
若不为0就会运算错误.给折腾了好几天,tmd害人不浅

;32bit bin to bcd
bintobcd_32 proc                                             ;data0data1data2data3 BIN 32 bit--->to0to1to2to3to4BCD 
        init
        mov     a, 20h
        mov     count0, a
loop1232:
        clr     [0ah].0
        rlc     data0
        rlc     data1
        rlc     data2
        rlc     data3
        mov     a, to0
        adc     a, to0
        mov     to0, a
        daa     to0
        mov     a, to1
        adc     a, to1
        mov     to1, a
        daa     to1
        mov     a, to2
        adc     a, to2
        mov     to2, a
        daa     to2
        mov     a, to3
        adc     a, to3
        mov     to3, a
        daa     to3
        mov     a, to4
        adc     a, to4
        mov     to4, a
        daa     to4
        sdz     count0
        jmp     loop1232
        ret
bintobcd_32 endp

endif          
               

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)