I want to multiply two fixed point numbers. After the multiplication I have to shift the result so that the binary point is correct.
Example:

int a;
int b;
int c;
c = (a * b) >> 10

The multiplication a*b produces a long int value in the MD register. After the shift operation the int result (the lower byte) should be stored in c.
My problem is how to use then 32-bit MD register. When I look at the assembler code only the lower byte of the MD register is used for the shift operation, but I first I want to shift the whole register and then take only the lower byte.
How can I implement that in C? Who knows an application note about fixed-point arithmetic with the C166?

 
Read-Only
Author
Andrew Neil
Posted
22-Oct-2003 09:34 GMT
Toolset
C166
 RE: Fixed-point multiplication

I don't know the '166, but I suspect this is a 'C' issue rather than a processor issue.

You could look up the promotion rules in K&R, or you could just try experimenting with casting a, b, and/or the product to long.

 
Read-Only
Author
Mike Kleshov
Posted
22-Oct-2003 09:56 GMT
Toolset
C166
 RE: Fixed-point multiplication

As Andrew said, this is a C issue. Take your favourite book on C and read about types and expressions. There are a few pitfalls there.
If both operands a and b are of type int, then the product (a * b) will be of type int, which is not what you are expecting. If you want the result to be of type long, try ((long)a * b): it will suffice to cast one of the operands to long.
Make sure you take care of overflows and that you understand the differences between signed and unsigned arithmetics.

- mike

 
Read-Only
Author
Bruno Büsser
Posted
22-Oct-2003 10:45 GMT
Toolset
C166
 RE: Fixed-point multiplication

That's it!
The following line produces just what I wanted:
c = ((long)a * b)>>10;

The product a*b is stored as 32 bit value in MD register, then the MD register value is arithmetic shifted right by 10 and the lower 16 bits stored in c.
Thanks to Andrew and Mike!

http://www.keil.com/forum/3549/

Fixed-point multiplication (C166 A*B/B)的更多相关文章

  1. ADC In An FPGA

    http://davidkessner.wordpress.com/2011/05/01/adc-in-an-fpga/ Geek Alert!  What follows is very techn ...

  2. c166 -div

    unsigned short a=10; unsigned short b; unsigned short c;unsigned long d; b = (unsigned short)(d/2400 ...

  3. Position属性四个值:static、fixed、relative、absolute的区别和用法

    1.static(静态定位):默认值.没有定位,元素出现在正常的文档流中(如果设置 top, bottom, left, right, z-index这些属性就不起做作了). 2.relative(相 ...

  4. fixed数据类型

    在处理图形运算,特别是3D图形生成运算时,往往要定义一个Fixed数据类型,我称它为定点数,定点数其时就是一个整形数据类型,他的作用就是把所有数 进行转换,从而得到相应类型的整型表达,然后使用定点数进 ...

  5. CSS:position:fixed使用(转)

    position属性规定元素的定位类型,即建立元素布局所用的定位机制.任何元素都可以定位,不过绝对定位或固定定位元素会生成一个块级框,而不论该元素本身是什么类型.相对定位元素会相对于它在正常流中的默认 ...

  6. setprecision **fixed

    #include <iostream> #include <iomanip> using namespace std; int main( void ) { const dou ...

  7. Position属性四个值:static、fixed、absolute和relative的区别和用法

    Position属性四个值:static.fixed.absolute和relative的区别和用法 在用CSS+DIV进行布局的时候,一直对position的四个属性值relative,absolu ...

  8. iframe中positioin:fixed失效问题

    页面中嵌套的iframe 内的 position:fixed元素定位失效fixed正常页面 此时position:fixed是根据浏览器窗口定位的,下拉一直位于左上角:以iframe形式嵌入后 此时p ...

  9. setprecision、fixed、showpoint的用法总结

    首先要加头文件:iomanip 一:setprecision 作用:控制输出流显示浮点数的数字个数,setprecision(n)就是输出的n个数,会有四舍五入. 比如:double s=20.784 ...

随机推荐

  1. dos命令:文件操作

    文件操作 一.assoc命令 1.介绍 显示或修改文件扩展名关联 2.语法 ASSOC [.ext[=[fileType]]] .ext     指定跟文件类型关联的文件扩展名 fileType 指定 ...

  2. chromium ⑤

    我们都知道chromium是用webkit完成页面显示的,   那么chromium是怎样集成和封装webkit的呢?   是怎样将webkit整合到自己的框架中,并将一个页面渲染出来的?   这篇我 ...

  3. office web apps server安装部署

    操作系统:windows 2012 软件下载地址: 链接:https://pan.baidu.com/s/1c3WWFs8 密码:4dcy NDP452-KB2901954-Web.exe(.Net ...

  4. 用MFC库函数AfxBeginThread()来创建线程

    在进行多线程程序设计的时候,我们经常用到AfxBeginThread函数来启动一条线程该函数使用起来非常的简单方便,其定义如下: 1.函数原型 CWinThread* AfxBeginThread( ...

  5. win10---cmd终端下连接ubantu--SSH SERVER服务

    在win10 cmd终端下输入 SSH  ubantu@192.168.124.134 之后输入yes 在输入yes

  6. Python MRO_C3

    class A: pass class B(A): pass class C(A): pass class D(B, C): pass class E(C, A): pass class F(D, E ...

  7. n 中选 m —— 随机采样的艺术

    0,1,2-n-1,n 个数中随机取 m 个数,要求 0, 1, n-1,此 n 个数每个数被取到的概率相同: Knuth 书中的随机化方法,很容易写出: void genkunth (int n, ...

  8. 模拟主库创建数据文件,dg备库空间不足时问题处理

    本篇文档测试目的: 模拟实际环境中,主库对表空间添加数据文件,备库空间不足,最终导致MRP进程自动断开,处理方式. 1.问题环境模拟 1)正常情况下的dg 主库创建数据文件,备库接受日志,自动创建表空 ...

  9. 使用Git去管理修改

    Git跟踪的是修改而不是文件本身. 看下面一个例子 首先我们修改我们Git管理的git.txt文件 如下: 然后添加: 然后我们再去修改git.txt这个文件 然后直接提交到分支里如图: 也就是说我们 ...

  10. Gym - 101889D:Daunting device (老司机树)

    题意:N个格子排出一排,开始格子颜色都是1:现在有M个操作: 或,把区间[L,R]颜色改为c: 或,查询一共有多少格子颜色为c. 最后求颜色最多的数量. 数据是随机的,且强制在线. 思路:ODT裸题. ...