C166 -MDH
Writing a C logic for moving MDH register contents after MUL instruction http://www.keil.com/forum/5231/
unnecessary code generation http://www.keil.com/forum/3528/
Hi Heinz,
I made a similar observation. Consider this example:
int a, b, c, d; void main(void)
{
a = c / d;
b = c % d;
} 0000 F2F70000 R MOV R7,d
0004 F2F60200 R MOV R6,c
0008 F6F60EFE MOV MDL,R6
000C 4B77 DIV R7
000E F6070600 R MOV a,MDL
0012 F6F60EFE MOV MDL,R6
0016 4B77 DIV R7
0018 F2F40CFE MOV R4,MDH
001C F2F50EFE MOV R5,MDL
0020 F6F40400 R MOV b,R4
0024 CB00 RET
Whereas the more optimal code would be
MOV R6,d
MOV MDL,c
DIV R6
MOV a,MDL
MOV b,MDH
RET
Quite a difference, isn't it? Oh well, maybe we are spoilt by modern compilers like gcc or msvc?
Are you trying to do a 32-bit multiplication? You may have forgotten to use a type cast to long. Remember that in C the product of two ints is int. Compile this and see the difference:
int a, b, c, d;
c = ( a * b ) >> 16;
d = ( (long)a * (long)b ) >> 16;
u16 u_16;
u32 u_32;
void main ()
{
int a,b,c;
short d,e;
long f;
f = (long)a*b ;
u_16 = ((u16)(f >> 16)<<1) | ((u16)f>>15);
上述代码可以实现 32位整体移位15并赋值到 16位变量;中间代码会有 MDH,MDL参与移位操作;
C166 -MDH的更多相关文章
- C166 Interfacing C to Assembler
Interfacing C to Assembler You can easily interface your C programs to routines written in XC16x/C16 ...
- c166 -div
unsigned short a=10; unsigned short b; unsigned short c;unsigned long d; b = (unsigned short)(d/2400 ...
- Fixed-point multiplication (C166 A*B/B)
I want to multiply two fixed point numbers. After the multiplication I have to shift the result so t ...
- C166 结构按字节访问的设置
PACK Compiler Directive Home » Compiling Programs » Directives » Reference » PACK Abbreviation None. ...
- 标准6轴机器人正反解(1)-坐标系和MDH参数表
刚来新公司不久,部门给安排了新人作业,我被分到的任务是求标准6轴机器人的正反解,以及利用就近原则选择最优解.从今天开始,逐步将这部分内容总结出来: 本文以及后续文章均使用改进DH法: 连杆坐标系: 坐 ...
- C166 8位字节位运算赋值-代码优化
8位字节位运算赋值优化特记录下: unsigned short func1(){ unsigned short a; return a;} unsigned char func2(){ unsigne ...
- [转]keil使用详解
第一节 系统概述 Keil C51是美国Keil Software公司出品的51系列兼容单片机C语言软件开发系统,与汇编相比,C语言在功能上.结构性.可读性.可维护性上有明显的优势,因而易学易用.用过 ...
- JAVA WEB WITH IDEA
本文主要介绍使用IDEA开发环境,创建JAVA WEB 工程,并介绍war包的制作过程. 1 创建MAVEN工程
- TPC-H生成.tbl文件导入postgresql数据库的坑
数据库project好好的不用主流的MySQL和Microsoft server而要求用听都没听过的postgresql (当然,可能你三个都没听过) 这里的坑主要是把生成的那八张.tbl的表导入pg ...
随机推荐
- js的柯里化currying
转载:http://www.zhangxinxu.com/wordpress/2013/02/js-currying/ 我自己的理解柯里化就是这样的,(1)必须返回匿名函数,(2)参数复用. 1. 参 ...
- 【转】Angular学习总结--很详细的教程
*这篇文章是转来的,做了自己的一点修改,排版.原始出处不明,如涉及原博主版权问题,请及时告知,我将会立即删除*. 1 前言 前端技术的发展是如此之快,各种优秀技术.优秀框架的出现简直让人目不暇接,紧跟 ...
- [Java] int 转换为BigDecimal
new BigDecimal(int i); BigDecimal.parseBigDecimal(String.valueOf(int i));
- yum命令报错 yum update File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: --CentOS7.5
1.问题: 使用yum命令如:yum update 报SyntaxError invalid syntax 2.原因分析 yum的解释器是Python,CentOS自带的yum采用(自带的)pytho ...
- 7.9 GRASP原则九: 隔离变化
GRASP原则九: 隔离变化 Protected Variations 需求一定会变化的!如何做到以系统的局部变化为代价就可以应对这一点?4.1 GRASP rule9: Protected ...
- css实现0.5px
使用缩放来0.5来实现,注意兼容各种浏览器 .frz-list li:after { content: ''; position: absolute; bottom:; height: 1px; wi ...
- TCP建立连接为什么是三次握手,为什么不是两次或四次?
什么是三次握手 学过网络编程的人,应该都知道TCP建立连接的三次握手,下面简单描述一下这个过程. 如图所示 第一次握手:客户端发送TCP包,置SYN标志位为1,将初始序号X,保存在包头的序列号(Seq ...
- JAVA中经过nginx反向代理获取客户端ip并获取相关坐标等信息
关于搜狐新浪ip库查询接口的使用 直接输出访客ip及所在城市: <script src="http://pv.sohu.com/cityjson?ie=utf-8" > ...
- [hdu P1599] find the mincost route
[hdu P1599] find the mincost route 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V ...
- 小程序都报wxss编译错误
解决方法: 在控制台输入openVendor() ,清除里面的wcc.exe wcsc.exe 然后重启工具