访问电脑版页面

导航:老古开发网手机版其他

32位除以16(DSP56F805汇编)

导读:
关键字:

;==================================================
;32位除以16位结果为16位,结果放在Y0中,清0,累加器A
;入口参数:被除数在A,Y0中,除数在X0中
;出口:结果在A,Y0中
;说明:32位除以16位的运算中,结果为16位或32位
;=================================================

div_32by16:                                      
                cmp     #$0000,x0
                beq     error_diver
                cmp     #1,x0
                beq     diver_return
                bra     right_diver
error_diver:   
                move    #$ffffffff,a
                move    #$ffff,y0
diver_return:               
                rts               
right_diver:               
                move    a0,a1
                move    y0,a0
                brset   #$8000,a1,diver_ok
                brset   #$8000,x0,diver_ok
                bra     run_diver               
diver_ok:
                asr     a
                bfclr   #$8000,a1
                asr     x0
                bfclr   #$8000,x0                         
run_diver:               
                move    a1,y1
                cmp     x0,y1
                bcc     overflow_deal
                                                             ;正整数除法,余数必须右移
                move    #$3ffe,y1                            ;本来在这里可以用4000乘的
                mpysu   x0,y1,b                              ;但用4002可以提高运算精度
                asr     b                                    ;
                bfclr   #$8000,b1
                move    b0,y0                                ;
                move    b1,y1                                ;
                clr     b                                    ;
                tfr     a,b                                  ;
                asr     b
                bfclr   #$8000,b1                            ;
                bfclr   #$0001,sr                            ;
                sbc     y,b                                  ;比较并转移
                bcs     continue_diver                         
 over_flow:         
                asr      a
                bfclr    #$8000,a1                           ;
                asl      a                                   ;
                bfclr    #$0001,sr
                rep      #16                                 ;
                div      x0,a
                clr      a1
                asl      a
                move     a0,y0
                add      x0,a
                asr      a
                move     a1,x:temp
                clr      a
                rts
continue_diver:                
                asl     a                                    ;             
                bfclr   #$0001,sr                            ;
                rep     #16                                  ;
                div     x0,a                                 ;
                move    a0,y0                                ;
                add     x0,a
                asr     a
                move    a1,x:temp
                clr     a                                    ;
                rts
overflow_deal:          
                move   a0,y0
                move   a1,a0
                move   #$0000,a1
                asl    a
                bfclr  #$0001,sr
                rep    #16
                div    x0,a
                lea    (sp)+
                move   a0,x:(sp)
                add    x0,a
                asr    a
                move   a1,a0
                move   #$0000,a1
                jsr    right_diver
                pop    a0
                rts  

来源:   作者:  2006/9/25 16:50:53
栏目: [ ]

相关阅读

安森美推出新的高功率图腾柱PFC控制器,满足具挑战的能效标准

动态功耗低至60μA/MHz!助力设备超长续航,首选国民技术低功耗MCU!