19_floating_point_arithmetic

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

FLOATING-POINT ARITHMETIC
CONVERTING SIGNED 32-BIT BINARY DATA TO SINGLE-PRECISION FLOATING-POINT FORMAT Overview The subroutine “S32Bin_SPFP” converts a signed 32-bit binary number to a single-precision, floating-point number. Table 21-1. Arguments and Register Allocations for “S32Bin_SPFP” Argument FPdata Addressing Working register Description The working register FPdata holds the starting point of a signed 32-bit binary number. After the routine executes, it contains the floating-point number. The Sign register is used to store temporary data (the sign of the operand). The Buf register is used to store temporary data. This working register holds the count for the number of shifts performed on the operand. Expnt is used to store temporary data (the exponent field of the floating point number).
SOURCE CODE FOR CONVERTING SIGNED 32-BIT BINARY DATA TO FLOATING-POINT FORMAT ;======================================================= ;==== Converting Signed Binary Data to Floating-Point Format ==== ;======================================================= ; Floating Point Format: ; IEEE type: sEEMMMMMM (32-bit, single-precision) ; Sign: 1-bit (bit 31), where plus ‘+’ = “0” and minus ‘–’ = “1” ; Exponent: 8-bit (bits 30–23) ; Mantissa: 23-bit (bits 22–0); does not include the implicit MSB ; ====================================================== ; Signed 32-bit binary data → Single-precision floating-point format: ; Input: r0, r1, r2, r3 FPdata ; Output: r0, r1, r2, r3 FPdata ; Registers: r0, r1, r2, r3, r4, r5, r6, r10 ; Register Definition Table: FPdata Sign Buf SftCntr Expnt S32Bin_SPFP: ld or or or jr ret SPFP00: ld tm jr Minussign: com com com com add adc adc adc or rFPdata rFPdata+1 rFPdata+2 rFPdata+3 rFPdata+3,#1H rFPdata+2,#0H rFpdata+1,#0H rFPdata,#0H rSign,#1H ; Negative ; Two’s complement (sign conversion) rSign,#0H rFPdata,#80H z,SPFP11 ; Test if sign is plus or minus ; Positive equ equ equ equ equ 0 10 6 4 5 ; ; ; ; ; r0, r1, r2, r3 r10 r6 r4 r5
Where, Sign bit = “1” Exponent field = “80H” Mantissa field = “400000H” (not including the implicit MSB) Procedure Description 1. Test if the sign of the 32-bit binary number is positive or negative. If it is negative, obtain the two's complement of the 32-bit binary number. 2. Test if the upper 8-bits (byte) is #0H. 3. If the upper byte is not #0H, shift the entire 32-bit data right until the upper byte contains all zeros. This step executes the 24-bit mantissa data and an 8-bit exponent from the 32-bit binary data. If the upper byte is #0H, shift the lower 24-bit data left until the MSB of lower 24-bit data is “1”. 4. Add #7FH to the exponent field. 5. Convert the exponent field and sign field to floating-point format.

FLOATING-POINT ARITHMETIC
APPLICATION NOTE: KS88APN21
Basic Operation Input parameter: FPdata (R0, R1, R2, R3) FFFFFFFDH (→ – 3 )
Output parameter: FPdata (R0, R1, R2, R3) C0400000H (→ – 3 )
rFPdata ← rExpnt
rSign = “1”? N Y rFPdata |= #80H rFPdata+1 &= #7FH
RET
Figure 21-2. Program Flowchart for “SPFP33”
21-4
APPLICATION NOTE: KS88APN21
FLOATING-POINT ARITHMETIC
21-2
APPLICATION NOTE: KS88APN21
FLOATING-POINT ARITHMETIC
S32Bin_SPFP
rFPdata+0,1,2,3 = #0H? Y N RET rFPdata’s sign =negative? N Minussign Y complement rFPdata rFPdata ++ rSign ← #1H rExpnt ← rSftCntr
CF ← “0” CF – –> rFPdata+0 – –> rFPdata+1 – –> rFPdata+2 – –> rFPdata+3 (rrc)
rFPdata = #0H? Y N rBuf ← rFPdata rSftCntr ← #32 N CF <– – rBuf (rlc) rSftCntr – – Y To SPFP33 N rFPdata = #0H? (– – rSftCntr) = #0H? Y
To SPFPform CF = “1”? Y N
Figure 21-1. Program Flowchart for “S32Bin_SPFP”
21-3
FLOATING-POINT ARITHMETIC
APPLICATION NOTE: KS88APN21
SPFP33
rExpnt ← #24
CF <– – rFPdata+1 <– – rFPdata+2 <– – rFPdata+3 rExpnt – – (rlc)
Sign Buf SftCntr Expnt
Working register Working register Working register Working register
Programming Guidelines — After this subroutine executes, rFPdata is overwritten because rFPdata contains the conversion result. (Prior to execution, rFPdata contains the signed binary value.) — If you need the original signed binary number when this routine has executed, you can store it in a RAM location. — If you need the original signed binary number, you can store it in a RAM location prior to executing this routine. — Please refer to application note APN20, “Single-Precision Floating-Point Formats,” for detailed information about floating-point operations.
CF = #1H? N Y CF – –> rFPdata+1 – –> rFPdata+2 – –> rFPdata+3 (rrc) SPFPform rExpnt += #7FH CF ← “0” CF – –> rExpnt (rrc)
CF = #1H? N Y (rFPdata+1) |= #80H (rFPdata+1) &= #7FH
rSign,rFPdata rSign,rFPdata+1 rSign,rFPdata+2 rSign,rFPdata+3 nz,SPFP00
; Test if binary number is zero
; No ; Yes, exit
; Save the sign
21-5
FLOATING-POINT ARITHMETIC
External Circuits and Programs to Support Hardware and Software Power-On/Reset Operations
Application Note: KS88APN September 1996 Application Engineering Department LSI Division, Micom Sector
APPLICATION NOTE: KS88APN21
SOURCE CODE FOR CONVERTING SIGNED 32-BIT BINARY DATA TO FLOATING-POINT FORMAT (Cont.) SPFP11: and jr ld ld SPFPloop0: rlc dec jr ld SPFPloop1: rcf rrc rrc rrc rrc dec jr and jr jr SPFP33: ld SPFPloop3: rlc rlc rlc dec jr rrc rrc rrc rFPdata+3 rFPdata+2 rFPdata+1 rExpnt nc,SPFPloop3 rFPdata+1 rFPdata+2 rFPdata+3 ; Change 32-bit binary to 24-bit mantissa rExpnt,#24 ; Change 32-bit binary to 24-bit mantissa rFPdata+0 rFPdata+1 rFPdata+2 rFPdata+3 rSftCntr z,SPFPform rFPdata,rFPdata nz,SPFPloop1 z,SPFPform rBuf rSftCntr nc,SPFPloop0 rExpnt,rSftCntr ; Shift rFPdata's image left one bit until CF = “1” ; Copy contents of SftCntr to Expnt rFPdata,rFPdata z,SPFP33 rBuf,rFPdata rSftCntr,#32 ; ; ; ; Test if upper 8 bits of the binary value are zero Yes No, change 32-bit binary to 24-bit mantissa This loop finds the exponent value
相关文档
最新文档