📄 fltoq15.asm
字号:
;***********************************************************
; Version 2.20.01
;***********************************************************
;****************************************************************
; Function: fltoq15
; Description: convert IEEE floating point to Q15
;
; Copyright Texas instruments Inc, 1998
;----------------------------------------------------------------
; Revision History:
; 1.00 - K. Baldwin. Original Release 8/31/98
;
;****************************************************************
.mmregs
.if __far_mode
.asg 2, offset
.else
.asg 1, offset
.endif
;----------------------------------------------------------------
; Set frame size for local variable space on stack
;----------------------------------------------------------------
.if __far_mode
.asg 12, frame_sz
.else
.asg 13, frame_sz
.endif
reg_save_sz .set 2
;----------------------------------------------------------------
; Set stack offsets to function arguments
;----------------------------------------------------------------
.asg offset + frame_sz + reg_save_sz, arg_offset
.asg arg_offset + 0, arg_r
.asg arg_offset + 1, arg_na
;----------------------------------------------------------------
; Set stack offsets to local variables
;----------------------------------------------------------------
.asg 0, sign_mask
.asg 2, mantissa
.asg 3, exponent
.asg 4, overflow
.asg 5, exp_bias
.asg 6, min_exp
.asg 7, minus_one
.asg 8, one
.asg 9, saturate
.asg 10, underflow
.asg 11, sign_bit
;----------------------------------------------------------------
; Assign auxiliary registers for temporaries and address
; calculations.
;----------------------------------------------------------------
.asg AR2, reg_aptr
.asg AR3, reg_rptr
;----------------------------------------------------------------
; Function definition:
;----------------------------------------------------------------
.global _fltoq15
_fltoq15
;----------------------------------------------------------------
; Prologue: establish local frame, reset sign extension mode
;----------------------------------------------------------------
PSHM ST0 ; 1 cycle
PSHM ST1 ; 1 cycle
RSBX OVA ; 1 cycle
RSBX OVB ; 1 cycle
frame #-frame_sz ; 1 cycle
rsbx sxm ; 1 cycle
;----------------------------------------------------------------
; Process function arguments
;----------------------------------------------------------------
stlm a, reg_aptr ; 1 cycle
mvdk *sp(arg_r), reg_rptr ; 1 cycle
ld *sp(arg_na), b ; 1 cycle
sub #1, b ; 2 cycles
stlm b, BRC ; 1 cycle
;----------------------------------------------------------------
; Store function constants
;----------------------------------------------------------------
st #127, *sp(exp_bias) ; 2 cycles
st #15, *sp(min_exp) ; 2 cycles
ld #8000h, 16, b ; 2 cycles
sth b, *sp(minus_one) ; 1 cycle
cmpl b,b ; 1 cycle
dst b, *sp(sign_mask) ; 1 cycle
st #8000h, *sp(minus_one) ; 2 cycles
st #1, *sp(one) ; 2 cycles
st #7fffh, *sp(saturate) ; 2 cycles
;----------------------------------------------------------------
; Convert each element of vector A, to Q15 format
; Pre-Load first vector element
;----------------------------------------------------------------
rptbd end_loop-1 ; 2 cycles
dld *reg_aptr+, a ; 1 cycle - delay slot
nop ; 1 cycle - delay slot
loop_start:
and #8000h,#16,a,b ; 2 cycles
sth b,*sp(sign_bit) ; 1 cycle
dld *sp(sign_mask),b ; 1 cycle
and b,a ; 1 cycle
bc zero, AEQ ; 5 cycles
and #7f80h,#16,a,b ; 2 cycles
ld *(bh),#-7,b ; 1 cycle
sub *sp(exp_bias),b ; 1 cycle
;----------------------------------------------------------------
; If unbiased exponent is >= 0, then value is too large to
; represent in Q15 format
;----------------------------------------------------------------
bc too_large, BGEQ ; 5 cycles
;----------------------------------------------------------------
; If exponent (abs) exp > abs(min_exp) then value is too small
; to represent in Q15 format. (min_exp = -15, since 2^-15 is
; least significant bit of Q15 number
;----------------------------------------------------------------
stl b, *sp(exponent) ; 1 cycle
abs b,b ; 1 cycle
sub *sp(min_exp), b, b ; 1 cycle
bc too_small, BGT ; 5 cycles
;----------------------------------------------------------------
; Shift floating point mantissa to keep only the most significant
; 15 bits. The implied 1 of the IEEE floating point format is ORed
; in as most significant bit.
;----------------------------------------------------------------
ld *sp(sign_bit), b ; 1 cycle
sfta a, #-7, a ; 1 cycle
ld *(AL), #-1, a ; 2 cycles
ld *sp(exponent), ASM ; 1 cycle
or *sp(minus_one), a ; 1 cycle
ld a, ASM, a ; 1 cycle
xc 1, bneq ; 1 cycle
neg a ; 1 cycle
b store_result ; 4 cycles
too_small:
st #2,*sp(underflow) ; 2 cycles
zero:
bd store_result ; 2 cycles
ld #0, a ; 1 cycle - delay slot
nop ; 1 cycle - delay slot
too_large:
ld *sp(sign_bit), b ; 1 cycle
st #1, *sp(overflow) ; 2 cycles
ld *sp(saturate), a ; 1 cycle
xc 1, bgt ; 1 cycle
add *sp(one), a ; 1 cycle
store_result:
stl a, *reg_rptr+ ; 1 cycle
dld *reg_aptr+, a ; 1 cycle
end_loop:
;----------------------------------------------------------------
; Return to calling program. Set error conditions on return
;----------------------------------------------------------------
Epilogue:
ld *sp(overflow), a ; 1 cycle
or *sp(underflow),a ; 1 cycle
frame #frame_sz ; 1 cycle
POPM ST1 ; 1 cycle
POPM ST0 ; 1 cycle
.if __far_mode
fret ; 6 cycles
.else
ret ; 5 cycles
.endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -