📄 q15tofloat.c
字号:
/******************************************************************************
; Module: Q15toFloa
; Filename: Q15toFloat.asm
; Project: DSP library for XC166 microcontroller
;------------------------------------------------------------------------------
; Compiler: Keil
;
; Version: V1.2
;
; Description: Changign the Q15 format to IEEE floating format
;
; Date: May 2003
;
; Copyright: Infineon Technologies AG
;*****************************************************************************/
/******************************************************************************
; float Q15toFloat(DataS X);
;
; INPUTS:
; X the input value in 1Q15 format
;
; RETURN:
; Y the output value in floating format
;
; ALGORITHM: According to the IEEE-754 format
;
; REGISTER USAGE:
; 1. From .c file to .asm file:
; defined by compiler
; 2. Output:
; (R4)=mmmmmmmmmmmmmmmm
; (R5)=seeeeeeeemmmmmmm (s:sign; e:exponent; m:mantissa)
;
; Assumption:
;
;*****************************************************************************/
#include "DspLib_Keil.h"
float Q15toFloat(DataS X)
{
__asm
{
MOV R1,X ;(R1)=X
//if X=0
CMP R1,#0
JMPR cc_NE,nozero
MOV R5,#0
MOV R4,#0
JMPR cc_UC,ende
nozero:
//if x=1
CMP R1,#7fffh
JMPR cc_NE,none
MOV R5,#3f7fh
MOV R4,#0ffffh
JMPR cc_UC,ende
none:
//get sign bit
MOV R2,R1 ;sign=(R2)=X in 1Q15
SHR R2,#0fh ;(R2)>>15
SHL R2,#0fh
//comput abs(x)
MOV MAH,R1 ;(ACC)=R1
CoABS
CoSTORE R1,MAS ;(R1)abs(x)
//compute exponent and mantissa
MOV R3,#1 ;initialize exp with 1, exp=(R3)
MOV R7,R1
MOV R6,R1 ;manti=(R6), initialize mantissa
loop1:
AND R7,#4000h ;look the most significant bit
JMPR cc_NZ,loop2
ADD R3,#1
SHL R6,#1
MOV R7,R6
JMPR cc_UC,loop1
loop2:
ADD R3,#1
SHL R6,#1
//build the floating output according to IEEE format
SUB R3,#127
NEG R3
SHL R3,#7
ADD R3,R2
MOV R7,R6 ;(R7)=manssi
SHR R7,#8
//first output
ADD R7,R3 ;building format for first register
MOV R5,R7 ;(R5)=sign + exponent
//second output
MOV R7,#0 ;output, (R4)=mantissa
SHL R6,#7
ADD R7,R6
MOV R4,R7
ende:
RET
}
}
//------------------- END OF FILE ----------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -