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

📄 floatto1q15.c

📁 基于c166的 FFT算法源程序
💻 C
字号:
/****************************************************************************** 
;  Module:		FloatTo1Q15
;  Filename:	FloatTo1Q15.c
;  Project:		DSP library for C166S V2 Core
;------------------------------------------------------------------------------
;  Compiler:	Keil
;
;  Version:		V1.2
;
;  Description: Changign the float format to 1Q15 format
;             
;  Date:		May 2003 
;
;  Copyright:	Infineon Technologies AG
;*****************************************************************************/

/******************************************************************************
; DataS	FloatTo1Q15(float 	X);
;
; INPUTS:	
;		X		the input value in float format
;
; RETURN:	
;		Y	 	the output value in 1Q15 format	   	
;		
; ALGORITHM: According to the IEEE-754 format
;			   
; REGISTER USAGE:
;	1. 	From .c file to .asm file:
;			(R8)=mmmmmmmmmmmmmmmm
;		   	(R9)=seeeeeeeemmmmmmm (s:sign; e:exponent; m:mantissa)
;			
;	2.	From .asm file to .c file:
;			(R4)=y
;
; Assumption:
;
;*****************************************************************************/

#include "DspLib_Keil.h"

DataS FloatTo1Q15(float x)				
{
   __asm
  {
//read the exponent bits in R3
	MOV		R3,R9		;(R3)=R9
	SHL		R3,#1h		;(R3)<<1
	SHR		R3,#8h		;(R3)>>8 = e
 	SUB		R3,#7fh
 	JMPR	cc_ULT,next	;if((R3)<127), jump
//if x=1
	MOV		R4,#07fffh	;(R4)=32767, in the case x=1
//read sign bit
	MOV		R2,R9		;(R2)=(R9)
	SHR		R2,#0fh		;(R2)=(R2)>>15 =s
 	JMPR	cc_Z,ende
//if x=-1
	MOV		R4,#8000h	;(R4)=32768, in the case x=-1

	RET

next:
//read the mantissa in R4
 	MOV		R4,R9		;(R4)=(R9)
	SHL		R4,#9h		;(R4)<<9
 	SHR		R4,#1h		;(R4)>>1
	SHR		R8,#8h		;(R8)>>8
	ADD		R4,R8		;(R4)=(R4)+(R8)
	SHR		R4,#1h		;(R4)=(R4)>>1
	ADD		R4,#4000h	;(R4)=(R4)+2^14

//output in 1Q15 format
   	ADD		R3,#1h		;(R3)=(R3)+1
	NEG		R3			;(R3)=-(R3)
	CMP		R3,#0fh		
	JMPR	cc_SLT,next1;if (R3)<15, jump
	MOV		R4,#0h;

	RET

next1:
	SHR		R4,R3
//read the sign bit R2
	MOV		R2,R9		;(R2)=(R9)
	SHR		R2,#0fh		;(R2)=(R2)>>15 =s
 	JMPR	cc_Z,ende
	NEG		R4

ende: 
					
   	RET

 }
}
//------------------- END OF FILE ----------------------------------------------
					

⌨️ 快捷键说明

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