⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fpd32.asm

📁 PIC单片机的汇编源码合集,应用比较广泛,设计程序时可做子程序来用
💻 ASM
字号:
;***********************32位浮点数除法*************************
          
               IFNDEF           FPD321
                #DEFINE         FPD321

FPD32           MOVF            BEXP,W                  ; test for divide by zero
                BTFSC           STATUS,Z
                GOTO            SETFDZ32

                MOVF            AEXP,W
                BTFSC           STATUS,Z
                GOTO            RES032

D32BNE0         MOVF            AARGB0,W
                XORWF           BARGB0,W
                MOVWF           SIGN                    ; save sign in SIGN
                BSF             AARGB0,MSB              ; make argument MSB's explicit
                BSF             BARGB0,MSB

TALIGN32        CLRF            TEMP                    ; clear align increment
                MOVF            AARGB0,W
                MOVWF           AARGB3			; test for alignment
                MOVF            AARGB1,W
                MOVWF           AARGB4
                MOVF            AARGB2,W
                MOVWF           AARGB5

                MOVF            BARGB2,W
                SUBWF           AARGB5,F
                MOVF            BARGB1,W
                BTFSS           STATUS,C
                INCFSZ          BARGB1,W

TS1ALIGN32      SUBWF           AARGB4,F
                MOVF            BARGB0,W
                BTFSS           STATUS,C
                INCFSZ          BARGB0,W

TS2ALIGN32      SUBWF           AARGB3,F

                CLRF            AARGB3
                CLRF            AARGB4
                CLRF            AARGB5

                BTFSS           STATUS,C
                GOTO            DALIGN32OK

                BCF             STATUS,C                      ; align if necessary
                RRF             AARGB0,F
                RRF             AARGB1,F
                RRF             AARGB2,F
                RRF             AARGB3,F
                MOVLW           0x01
                MOVWF           TEMP                    ; save align increment          

DALIGN32OK      MOVF            BEXP,W                  ; compare AEXP and BEXP
                SUBWF           EXP,F
                BTFSS           STATUS,C
                GOTO            ALTB32
        
AGEB32          MOVLW           .127-1
                ADDWF           TEMP,W
                ADDWF           EXP,F
                BTFSC           STATUS,C
                GOTO            SETFOV32
                GOTO            DARGOK32                ; set overflow flag

ALTB32          MOVLW           .127-1
                ADDWF           TEMP,W
                ADDWF           EXP,F
                BTFSS           STATUS,C
                GOTO            SETFUN32                ; set underflow flag

DARGOK32        MOVLW           D'24'			; initialize counter
                MOVWF           BARGB3

DLOOP32         RLF             AARGB5,F                ; left shift
                RLF             AARGB4,F
                RLF             AARGB3,F
                RLF             AARGB2,F
                RLF             AARGB1,F
                RLF             AARGB0,F
                RLF             TEMP,F

                MOVF            BARGB2,W                ; subtract
                SUBWF           AARGB2,F
                MOVF            BARGB1,W
                BTFSS           STATUS,C
                INCFSZ          BARGB1,W
DS132           SUBWF           AARGB1,F

                MOVF            BARGB0,W
                BTFSS           STATUS,C
                INCFSZ          BARGB0,W
DS232           SUBWF           AARGB0,F

                RLF             BARGB0,W
                IORWF           TEMP,F
                
                BTFSS           TEMP,LSB                ; test for restore
                GOTO            DREST32

                BSF             AARGB5,LSB
                GOTO            DOK32

DREST32         MOVF            BARGB2,W                ; restore if necessary
                ADDWF           AARGB2,F
                MOVF            BARGB1,W
                BTFSC           STATUS,C
                INCFSZ          BARGB1,W
DAREST32        ADDWF           AARGB1,F

                MOVF            BARGB0,W
                BTFSC           STATUS,C
                INCF            BARGB0,W
                ADDWF           AARGB0,F

                BCF             AARGB5,LSB

DOK32           DECFSZ          BARGB3,F
                GOTO            DLOOP32

DROUND32        BTFSC           FPFLAGS,RND
                BTFSS           AARGB5,LSB
                GOTO            DIV32OK
                BCF             STATUS,C
                RLF             AARGB2,F               ; compute next significant bit
                RLF             AARGB1,F               ; for rounding
                RLF             AARGB0,F
                RLF             TEMP,F

                MOVF            BARGB2,W               ; subtract
                SUBWF           AARGB2,F
                MOVF            BARGB1,W
                BTFSS           STATUS,C
                INCFSZ          BARGB1,W
		SUBWF           AARGB1,F

                MOVF            BARGB0,W
                BTFSS           STATUS,C
                INCFSZ          BARGB0,W
		SUBWF           AARGB0,F

                RLF             BARGB0,W
                IORWF           TEMP,W
                ANDLW           0x01            

                ADDWF           AARGB5,F
                BTFSC           STATUS,C
                INCF            AARGB4,F
                BTFSC           STATUS,Z
                INCF            AARGB3,F

                BTFSS           STATUS,Z                      ; test if rounding caused carryout
                GOTO            DIV32OK
                RRF             AARGB3,F
                RRF             AARGB4,F
                RRF             AARGB5,F
                INCF            EXP,F
                BTFSC           STATUS,Z                      ; test for overflow
                GOTO            SETFOV32


DIV32OK         BTFSS           SIGN,MSB
                BCF             AARGB3,MSB		; clear explicit MSB if positive

                MOVF            AARGB3,W
                MOVWF           AARGB0                  ; move result to AARG
                MOVF            AARGB4,W
                MOVWF           AARGB1
                MOVF            AARGB5,W
                MOVWF           AARGB2

                RETLW           0


SETFDZ32        BSF             FPFLAGS,FDZ             ; set divide by zero flag
                RETLW           0xFF
               ENDIF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -