?? ancillary.asm
字號(hào):
IFNDEF ANCILLARY1
#DEFINE ANCILLARY1
;*******************************
;下溢標(biāo)志置1
SETFUN BSF FPFLAGS,FUN ;下溢標(biāo)志置1
BTFSS FPFLAGS,SAT ;檢測(cè)是否允許飽和
RETLW 0xFF ;帶錯(cuò)誤標(biāo)志返回
MOVLW 0x01 ;浮點(diǎn)數(shù)所能表示的最小值
MOVWF EXP1 ;0x 01 00 00
CLRF ARGBL1
CLRF ARGBH1
RLF SIGN,F
RRF ARGBH1,F ;得到合適的符號(hào)位
RETLW 0xFF
;********************************************************
;本程序?qū)崿F(xiàn)設(shè)置IOV位
SETIOV BSF FPFLAGS,IOV ;IOV位置1
BTFSS FPFLAGS,SAT ;檢測(cè)飽和允許位
RETLW 0xFF ;
CLRF ARGBH1 ;結(jié)果取飽和值
BTFSS SIGN,MSB ;
MOVLW 0xFF
MOVWF ARGBH1 ;SIGN = 0, 0x 7F FF
MOVWF ARGBL1 ;SIGN = 1, 0x 80 00
RLF SIGN,F
RRF ARGBH1,F
RETLW 0xFF ;返回錯(cuò)誤標(biāo)志
;***************************************************
;本程序?qū)崿F(xiàn)設(shè)置FOV位
SETFOV BSF FPFLAGS,FOV ;上溢標(biāo)志置1
BTFSS FPFLAGS,SAT ;檢測(cè)飽和允許位
RETLW 0xFF
MOVLW 0xFF
MOVWF EXP1 ;飽和數(shù)
MOVWF ARGBH1 ; 0x 7F FF FF
MOVWF ARGBL1
RLF SIGN,F
RRF ARGBH1,F
RETLW 0xFF
;*****************************************************
;本程序?qū)崿F(xiàn)將結(jié)果請(qǐng)0
RES024 CLRF ARGBH1 ;結(jié)果為0
CLRF ARGBL1
CLRF EXP1
RETLW 0
;*****************************************************
;本程序?qū)崿F(xiàn)設(shè)置定義域錯(cuò)誤標(biāo)志
DOMERR24 BSF FPFLAGS,DOM ;定義域錯(cuò)誤
RETLW 0xFF
;*****************************************************
;本程序?qū)崿F(xiàn)設(shè)置FDZ位
SETFDZ BSF FPFLAGS,FDZ
RETLW 0xFF
;*****************************************************
;本程序?qū)崿F(xiàn)去掉最高位隱含的1
FIXSIGN24 BTFSS SIGN,MSB
BCF ARGBH1,MSB
RETLW 0
;********************************************************
;多項(xiàng)式計(jì)算宏定義
POL macro COF,N,ROUND
;多項(xiàng)式計(jì)算。階次N, 自變量AARG,系數(shù)COF,
;假定當(dāng)N>1時(shí),AARG已經(jīng)復(fù)制到DARG中.
;結(jié)果在AARG中
; ROUND = 0 no rounding is enabled; can be previously enabled
; ROUND = 1 rounding is enabled
; ROUND = 2 rounding is enabled then disabled before last add
; ROUND = 3 rounding is assumed disabled then enabled before last add
; ROUND = 4 rounding is assumed enabled and then disabled before last
; add if DARGB3,RND is clear
; ROUND = 5 rounding is assumed disabled and then enabled before last
; add if DARGB3,RND is set
local i,j
variable i = N, j = 0
if ROUND == 1 || ROUND == 2
BSF FPFLAGS,RND
endif
MOVLW COF#v(i)
MOVWF BEXP
while j <= 2
MOVLW COF#v(i)#v(j)
MOVWF BARGB#v(j)
variable j = j + 1
endw
CALL FPM32
variable i = i - 1
MOVLW COF#v(i)
MOVWF BEXP
variable j = 0
while j <= 2
MOVLW COF#v(i)#v(j)
MOVWF BARGB#v(j)
variable j = j + 1
endw
CALL FPA32
variable i = i - 1
while i >= 0
MOVF DEXP,W
MOVWF BEXP
MOVF DARGB0,W
MOVWF BARGB0
MOVF DARGB1,W
MOVWF BARGB1
MOVF DARGB2,W
MOVWF BARGB2
CALL FPM32
MOVLW COF#v(i)
MOVWF BEXP
variable j = 0
while j <= 2
MOVLW COF#v(i)#v(j)
MOVWF BARGB#v(j)
variable j = j + 1
endw
if i == 0
if ROUND == 2
BCF FPFLAGS,RND
endif
if ROUND == 3
BSF FPFLAGS,RND
endif
if ROUND == 4
BTFSS DARGB3,RND
BCF FPFLAGS,RND
endif
if ROUND == 5
BTFSC DARGB3,RND
BSF FPFLAGS,RND
endif
endif
CALL FPA32
variable i = i - 1
endw
endm
;**********************************************************************
POLL1 macro COF,N,ROUND
; 32 bit evaluation of polynomial of degree N, PN(AARG), with coefficients COF,
; with leading coefficient of one, and where AARG is assumed have been be saved
; in DARG when N>1. The result is in AARG.
; ROUND = 0 no rounding is enabled; can be previously enabled
; ROUND = 1 rounding is enabled
; ROUND = 2 rounding is enabled then disabled before last add
; ROUND = 3 rounding is assumed disabled then enabled before last add
; ROUND = 4 rounding is assumed enabled and then disabled before last
; add if DARGB3,RND is clear
; ROUND = 5 rounding is assumed disabled and then enabled before last
; add if DARGB3,RND is set
local i,j
variable i = N, j = 0
variable i = i - 1
if ROUND == 1 || ROUND == 2
BSF FPFLAGS,RND
endif
MOVLW COF#v(i)
MOVWF BEXP
variable j = 0
while j <= 2
MOVLW COF#v(i)#v(j)
MOVWF BARGB#v(j)
variable j = j + 1
endw
CALL FPA32
variable i = i - 1
while i >= 0
MOVF DEXP,W
MOVWF BEXP
MOVF DARGB0,W
MOVWF BARGB0
MOVF DARGB1,W
MOVWF BARGB1
MOVF DARGB2,W
MOVWF BARGB2
CALL FPM32
MOVLW COF#v(i)
MOVWF BEXP
variable j = 0
while j <= 2
MOVLW COF#v(i)#v(j)
MOVWF BARGB#v(j)
variable j = j + 1
endw
if i == 0
if ROUND == 2
BCF FPFLAGS,RND
endif
if ROUND == 3
BSF FPFLAGS,RND
endif
if ROUND == 4
BTFSS DARGB3,RND
BCF FPFLAGS,RND
endif
if ROUND == 5
BTFSC DARGB3,RND
BSF FPFLAGS,RND
endif
endif
CALL FPA32
variable i = i - 1
endw
endm
ENDIF
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -