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

📄 exp43.txt

📁 实现16位DSP TMSC5416 32位浮点数乘法
💻 TXT
字号:
res_hm .usect ”flt_add”,1 ;result high mantissa
res_lm .usect ”flt_add”,1 ;result low mantissa
res_exp .usect ”flt_add”,1 ;result exponent
res_sign .usect ”flt_add”,1 ; result sign
op2_hm .usect ”flt_add”,1 ; OP2 high mantissa
op2_lm .usect ”flt_add”,1 ; OP2 low mantissa
op2_se .usect ”flt_add”,1 ; OP2 sign and exponent
op1_se .usect ”flt_add”,1 ; OP1 sign and exponent
op1_hm .usect ”flt_add”,1 ; OP1 high mantissa
op1_lm .usect ”flt_add”,1 ; OP1 low mantissa
op1_msw .usect ”flt_add”,1 ; OP1 packed high word
op1_lsw .usect ”flt_add”,1 ; OP1 packed low word
op2_msw .usect ”flt_add”,1 ; OP2 packed high word
op2_lsw .usect ”flt_add”,1 ; OP2 packed low word
err_no .usect ”flt_add”,1 ;
*******************************************************************
* Floating point number 12.0 can be represented as 1100 = 1.100 x 23 => sign =0
* biased exponent = 127+3 = 130
* 130 = 10000010
* Mantissa 10000000000000000000000
* Thus 12.0 can be represented as 01000001010000000000000000000000= 4140h
**********************************************************************************
*
K_OP1_HIGH .set 4140h ; floating point number 12.0
K_OP1_LOW .set 0000h
K_OP2_HIGH .set 4140h ; floating point number 12.0
K_OP2_LOW .set 0000h
	.mmregs
	.text
start_flt:
	RSBX C16 ; Insure long adds for later
	LD #res_hm,DP ; initialize the page pointer
	LD #K_OP2_HIGH,A ; load floating #2 – 12
	STL A,op2_msw
	LD #K_OP2_LOW,A
	STL A,op2_lsw
	LD #K_OP1_HIGH,A ; load floating #1 – 12
	STL A,op1_msw
	LD #K_OP1_LOW,A
	STL A,op1_lsw
*
*;*****************************************************************************
*; CONVERSION OF FLOATING POINT FORMAT – UNPACK
*; Test OP1 for special case treatment of zero.
*; Split the MSW of A in the accumulator.
*; Save the sign and exponent on the stack [xxxx xxxS EEEE EEEE].
*; Add the implied one to the mantissa value
*; Store entire mantissa with a long word store
*;*****************************************************************************
	DLD op1_msw,A ; OP1
	SFTA A,8
	SFTA A,–8
	BC op_zero,AEQ ; if op1 is 0, jump to special case

	STH A,–7,op1_se ; store sign AND exponent to stack
	STL A,op1_lm ; store low mantissa
	AND #07Fh,16,A ; mask off sign & exp to get high mantissa
	ADD #080h,16,A ; ADD implied 1 to mantissa
	STH A,op1_hm ; store mantissa to stack
*;*****************************************************************************
*; CONVERSION OF FLOATING POINT FORMAT – UNPACK
*; Test OP2 for special case treatment of zero.
*; Split the MSW of A in the accumulator.
*; Save the sign and exponent on the stack [xxxx xxxS EEEE EEEE].
*; Add the implied one to the mantissa value.
*; Store entire mantissa with a long word store
*;*****************************************************************************
	DLD op2_msw,A ; load acc a with OP2
	BC op_zero,AEQ ; if OP2 is 0, jump to special case
	STH A,–7,op2_se ; store sign and exponent to stack
	STL A,op2_lm ; store low mantissa
	AND #07Fh,16,A ; mask off sign & exp to get high mantissa
	ADD #080h,16,A ; add implied 1 to mantissa
	STH A,op2_hm ; store mantissa to stack
*;*****************************************************************************
*; SIGN EVALUATION
*; Exclusive OR sign bits of OP1 and OP2 to determine sign of result.
*;*****************************************************************************
	LD op1_se,A ; load sign and exp of op1 to acc
	XOR op2_se,A ; xor with op2 to get sign of result
	AND #00100h,A ; mask to get sign
	STL A,res_sign ; save sign of result to stack
*;*****************************************************************************
*; EXPONENT SUMMATION
*; Sum the exponents of OP1 and OP2 to determine the result exponent. Since
*; the exponents are biased (excess 127) the summation must be decremented
*; by the bias value to avoid double biasing the result
*; Branch to one of three blocks of processing
*; Case 1: exp OP1 + exp OP2 results in underflow (exp < 0)
*; Case 2: exp OP1 + exp OP2 results in overflow (exp >= 0FFh)
*; Case 3: exp OP1 + exp OP2 results are in range (exp >= 0 & exp < 0FFh)
*; NOTE: Cases when result exp = 0 may result in underflow unless there
*; is a carry in the result that increments the exponent to 1.
*; Cases when result exp = 0FEh may result in overflow if there
*; is a carry in the result that increments the exponent to 0FFh.
*;*****************************************************************************
	LD op1_se,A ; Load OP1 sign and exponent
	AND #00FFh,A ; Mask OP1 exponent
	LD op2_se,B ; Load OP2 sign and exponent
	AND #0FFh,B ; Mask OP2 exponent
	SUB #07Fh,B ; Subtract offset (avoid double bias)
	ADD B,A ; Add OP1 exponent
	STL A,res_exp ; Save result exponent on stack
	BC underflow,ALT ; branch to underflow handler if exp < 0
	SUB #0FFh,A ; test for overflow
	BC overflow,AGT ; branch to overflow is exp > 127
*;*****************************************************************************

*; MULTIPLICATION
*; Multiplication is implemented by parts. Mantissa for OP1 is three bytes
*; identified as Q, R, and S
*; (Q represents OP1 high mantissa and R and S represent the two bytes of OP1 low
*; mantissa). Mantissa for
*; OP2 is also 3 bytes identified as X, Y, and Z (X represents OP2 high mant and
*; Y and Z represent the two bytes
*; of OP2 low mantissa). Then
*; 0 Q R S (mantissa of OP1)
*; x 0 X Y Z (mantissa of OP2)
*; ===========
*; RS*YZ <–– save only upper 16 bits of result
*; RS*0X
*; 0Q*YZ
*; 0Q*0X <–– upper 16 bits are always zero
*; ===========
*; result <–– result is always in the internal 32 bits
*;(which ends up in the accumulator) of the possible 64 bit product
*;*****************************************************************************
	LD op1_lm,T ; load low mant of op1 to T register
	MPYU op2_lm,A ; RS * YZ
	MPYU op2_hm,B ; RS * 0X
	ADD A,–16,B ; B = (RS * YZ) + (RS * 0X)
	LD op1_hm,T ; load high mant of op1 to T register
	MPYU op2_lm,A ; A = 0Q * YZ
	ADD B,A ; A = (RS * YZ) + (RS * 0X) + (0Q * YZ)
	MPYU op2_hm,B ; B = 0Q * 0X
	STL B,res_hm ; get lower word of 0Q * 0X
	ADD res_hm,16,A ; A = final result
*;*****************************************************************************
*; POST–NORMALIZATION ADJUSTMENT AND STORAGE
*; Set up to adjust the normalized result.
*; The MSB may be in bit 31. Test this case and increment the exponent
*; and right shift mantissa 1 bit so result is in bits 30 through 7
*; Right shift mantissa by 7 bits.
*; Store low mantissa on stack.
*; Mask implied 1 and store high mantissa on stack.
*; Test result for underflow and overflow.
*********************************************************************************
	ADD #040h,A ; Add rounding bit
	SFTA A,8 ; sign extend result to check if MSB is in 31
	SFTA A,–8
	RSBX SXM ; turn off sign extension for normalization
	LD res_exp,B ; load exponent of result
	BC normalized,AGEQ ; check if MSB is in 31
	SFTL A,–1 ; Shift result so result is in bits 30:7
	ADD #1,B ; increment exponent
	STL B,res_exp ; save updated exponent normalized
	BC underflow,BLEQ ; check for underflow
	SUB #0FFh,B ; adjust to check for overflow
	BC overflow,BGEQ ; check for overflow
	SFTL A,–7 ; shift to get 23 msb bits of mantissa result
	STL A,res_lm ; store low mantissa result

	AND #07F00h,8,A ; remove implied one
	STH A,res_hm ; store the mantissa result
*;*****************************************************************************
*; CONVERSION OF FLOATING POINT FORMAT – PACK
*; Load sign.
*; Pack exponent.
*; Pack mantissa.
*;*****************************************************************************
	LD res_sign,16,A ; 0000 000S 0000 0000 0000 0000 0000 0000
	ADD res_exp,16,A ; 0000 000S EEEE EEEE 0000 0000 0000 0000
	SFTL A,7 ; SEEE EEEE E000 0000 0000 0000 0000 0000
	DADD res_hm,A ; SEEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM
*;*****************************************************************************
*; CONTEXT RESTORE
*;*****************************************************************************
return_value
op_zero
	nop
	nop
	ret
*;*****************************************************************************
*; overflow PROCESSING
*; Push errno onto stack.
*; Load accumulator with return value.
*;*****************************************************************************
overflow
	ST #2,err_no ; Load error no
	LD res_sign,16,B ; Load sign of result
	LD #0FFFFh,A ; Result low mantissa = 0FFFFh
	OR B,7,A ; Add sign bit
	BD return_value ; Branch delayed
	ADD #07F7Fh,16,A ; Result exponent = 0FEh
; Result high mant = 07Fh
*;*****************************************************************************
*; UNDERFLOW PROCESSING
*; Push errno onto stack.
*; Load accumulator with return value.
*;*****************************************************************************
underflow
	ST #1,err_no ; Load error no
	BD return_value ; Branch delayed
	SUB A,A ; For underflow result = 0
	NOP
here: 	B here
	.end

⌨️ 快捷键说明

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