?? cnv04.s43
字號:
;==============================================================================
; MSP430 Floating Point Package Version 4.0 IAR
;
; Conversion Subroutines
; Texas Instruments Deutschland IAR Version
; Date: January, 6 1997 March, 14 2000
; Author: Lutz Bierl TID 4711
; Version: 4.02 4.03
; 3.0 First version
; 4.0 Comment enhancements and corrections
;
;============================================================================
;
; This Conversion Package supports the following Integer Conversions:
;
; CNV_BIN40 40 Bit binary to floating point (24/40 mantissa)
; CNV_BIN32U 32 Bit unsigned binary to floating point (24/40 mantissa)
; CNV_BIN32 32 Bit signed binary to floating point (24/40 mantissa)
; CNV_BIN16U 16 Bit unsigned binary to floating point (24/40 mantissa)
; CNV_BIN16 16 Bit signed binary to floating point (24/40 mantissa)
; CNV_BIN 40 Bit binary buffer to floating point (24/40 mantissa)
; CNV_FP_BIN Floating point to binary 40 bits (24/40 mantissa)
; CNV_BCD_FP 12 digit signed BCD to floating point (24/40 mantissa)
; CNV_FP_BCD FP number to signed 12 digit BCD number (24/40 mantissa)
;
; Errors are written to the Status Register SR: N = 0: no error
; N = 1: error occured
;
; The conversion subroutines may be used for mantissas with 24 bits and
; with 40 bits: the value of DOUBLE decides which length is used:
; DOUBLE = 0: 24 bit mantissa (4 bytes per floating point number)
; DOUBLE = 1: 40 bit mantissa (6 bytes per floating point number)
;
; MSB=.31 .23 LSB=.0 .FLOAT format
; +-------------------------------------------+
; | e.7 ... e.0 | sign | m.22 ........... m.0 | DOUBLE = 0
; +--------------------.----------------------+
; Exponent E DP Mantissa M
;
; MSB=.47 .39 LSB=.0 .DOUBLE format
; +-----------------------------------------------------+
; | e.7 ... e.0 | sign | m.38 ..................... m.0 | DOUBLE = 1
; +--------------------.--------------------------------+
; Exponent E DP Mantissa M
;
; Explanation of the FPP: see Metering Application Report
;============================================================================
;
; For all Conversion Subroutines:
;
; - Two (three) free words have to be allocated on the stack
; - Arguments are not changed (except if on TOS)
; - All pointers point to the MSB part of the numbers
; - After the completion both pointers (and the SP) point to the result
; on top of the stack (TOS)
;
; Call Example (written for both formats):
;
; CALL #FLT_SAV ; Save registers
; SUB #(ML/8)+1,SP ; Allocate stack for result
; MOV #bcdb,RPARG ; Load address of BCD-buffer to RPARG
; CALL #CNV_BCD_FP ; Convert BCD (or binary) number to FP
; MOV #val3,RPARG ; Load address of FP number to continue
; CALL #FLT_xxx ; Calculate next result
; .... ........ ; Continue until final result is calculated
; CALL #CNV_FP_BCD ; Convert final FP result to BCD
; JN CNVERR ; FP number too big for BCD buffer
; POP bcdmsd ; BCD number MSDs and sign
; POP bcdmid ; BCD digits MSD-4 to LSD+4
; POP bcdlsd ; BCD digits LSD+3 to LSD
; ; Stack is corrected by POPs
; CALL #FLT_REC ; Restore registers
; .... ........ ; Continue with program
;
;===========================================================================
; The flag SW_RND is defined in the user's program:
;
; SW_RND EQU 0 ; 0: no rounding 1: rounding used
;
; BEGIN OF THE FLOATING POINT CONVERSION SUBROUTINES
;
; Integer to Floating Point Conversions. A 3-word buffer is prepared and
; and converted. All conversions use this register buffer BIN_MSB to BIN_LSB.
;---------------------------------------------------------------------------
; 40 Bit binary to floating point (signed and unsigned). RPARG points to MSBs
; of a 3 word buffer. Range: -2^40+1 to +2^40-1 (-1.099x10^12 to +1.099x10^12)
; FF00 0000 0001 to 00FF FFFF FFFF
;
; Call MOV #BINMSB,RPARG ; Pointer to MSBs of a 3 word number
; CALL #CNV_BIN40 ; Call conversion routine
; ... ; Result on TOS (2 or 3 words FP number)
;
CNV_BIN40 MOV @R5+,BIN_MSB
JMP CNVL$1
;---------------------------------------------------------------------------
; 32 Bit binary to floating point (signed). RPARG points to MSBs
; of a 2 word buffer. Range: -2^31 to +2^31-1 (-2.14x10^9 to +2.14x10^9)
;
; Call MOV #BINMSB,RPARG ; Pointer to MSBs of a 2 word number
; CALL #CNV_BIN32 ; Call conversion routine
; ... ; Result on TOS (2 or 3 words FP number)
;
CNV_BIN32 TST 0(R5) ; Check sign
JGE CNV_BIN32U ; Pos.: Use 32 bit unsigned conversion
MOV #0FFFFh,BIN_MSB ; Neg. number: set MSBs to FFFF
JMP CNVL$1
;
;---------------------------------------------------------------------------
; 32 Bit unsigned binary to floating point conversion. RPARG points to MSBs
; of a two word buffer. Rang e: 0...2^32-1
;
; Call MOV #BINMSB,RPARG ; Pointer to MSBs of a 2 word number
; CALL #CNV_BIN32U ; Call conversion routine
; ... ; Result on TOS (2 or 3 words FP number)
;
CNV_BIN32U CLR BIN_MSB ; High word is cleared
CNVL$1 MOV @R5+,BIN_MID
MOV @R5,BIN_LSB
JMP CNV_BIN
;
;---------------------------------------------------------------------------
; 16 Bit binary to floating point (signed). RPARG points to value.
; Range: -2^15 to +2^15-1 (-32768 to +32767)
;
; Call MOV #BINMSB,RPARG ; Pointer to MSBs of a 1 word number
; CALL #CNV_BIN16 ; Call conversion routine
; ... ; Result on TOS (2 or 3 words FP number)
;
CNV_BIN16 TST 0(R5) ; Check sign
JGE CNV_BIN16U ; Use 16 bit unsigned conversion
MOV #0FFFFh,BIN_MID ; Neg. number: set MSBs to FFFF FFFF
MOV #0FFFFh,BIN_MSB
JMP CNVL$2
;
;---------------------------------------------------------------------------
; 16 Bit binary to floating point (unsigned). RPARG points to value.
; Range: 0 to +2^16-1 (0 to 65365)
;
; Call MOV #BINMSB,RPARG ; Pointer to MSBs of a 1 word number
; CALL #CNV_BIN16U ; Call conversion routine
; ... ; Result on TOS (2 or 3 words FP number)
;
CNV_BIN16U CLR BIN_MSB ; Set MSBs to zero
CLR BIN_MID
CNVL$2 MOV @R5,BIN_LSB
;---------------------------------------------------------------------------
; 48-bit signed integer in BIN_MSB to BIN_LSB
; This call may be used if the 48-bit number is yet in BIN_MSB to BIN_LSB
;
; Call MOV binmsb,BIN_MSB ; Load MSBs of a signed 48 bit binary number
; MOV binmid,BIN_MID ;
; MOV binlsb,BIN_LSB ; Load LSBs
; CALL #CNV_BIN ; Call conversion routine
; ... ; Result on TOS (2 or 3 words FP number)
;
CNV_BIN MOV BIN_MSB,2(SP) ; Store MSBs with sign in result MSBs
TST BIN_MSB ; Check sign of number
JGE NORM ; Pos.: yet ok
INV BIN_LSB ; Neg.: Absolute value needed
INV BIN_MID ; Invert value of 3-word buffer
INV BIN_MSB
INC BIN_LSB ; Complement 3-word buffer
ADC BIN_MID
ADC BIN_MSB
JMP NORM ; Go to common conversion part
;
;---------------------------------------------------------------------------
; BCD to Floating Point Conversion. A 3-word buffer containing a signed BCD-
; integer number is converted to a 32 bit or 48 bit floating point number.
; RPARG points to the MSD word of the buffer. The MSB of this word contains
; the sign: 0 = positive, 1 = negative
; Range: -8x10^11 + 1 to +8x10^11 - 1
;
; Call: RPARG points to MSDs of BCD-Buffer (sign in MSB of MSD)
; Return: RPARG, RPRES and SP point to result on TOS
;
; Call MOV #BCDbuffer,RPARG ; Pointer to MSDs of a 3 word buffer
; CALL #CNV_BCD_FP ; Call conversion routine
; ... ; Result on TOS (2 or 3 words FP number)
;
;
CNV_BCD_FP EQU $
MOV RPARG,RPRES ; Copy pointer
IF DOUBLE=1
MOV @R11+,BCD_MSB ; Sign, MSD to MSD-3
MOV @R11+,BCD_MID ; MSD-4 to LSD+4
MOV @R11,BCD_LSB ; LSD+3 to LSD
ELSE
MOV @R9+,BCD_MSB ; Sign, MSD to MSD-3
MOV @R9+,BCD_MID ; MSD-4 to LSD+4
MOV @R9,BCD_LSB ; LSDs
ENDIF
MOV BCD_MSB,2(SP) ; Store MSBs with sign in result space
CLR BIN_MSB ; Clear binary buffer
CLR BIN_MID
CLR BIN_LSB
;
; BCD to Binary Conversion: 12 BCD-digits to 40 bit binary
;
MOV #12*4,COUNTER ; Digit counter x 4 bits
BIC #08000h,BCD_MSB ; Clear sign bit
BCD_LOP1 RLA BIN_LSB ; MPY binary result with 10
RLC BIN_MID
RLC BIN_MSB
PUSH BIN_MSB ; Store doubled value
PUSH BIN_MID
PUSH BIN_LSB
RLA BIN_LSB ; x 4
RLC BIN_MID
RLC BIN_MSB
RLA BIN_LSB ; x 8
RLC BIN_MID
RLC BIN_MSB
ADD @SP+,BIN_LSB ; x(8 + 2)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -