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 ...
随机推荐
- vue-先渲染dom载执行js
价格判断v-if=“dataList”有数据的时候才渲染
- 【shell脚本】 变量基础学习整理
1.linux系统环境 echo 'echo /etc/profile ' >> /etc/profile echo 'echo /etc/bashrc' >> /etc/ba ...
- LeetCode--018--四数之和(java)
给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满 ...
- python中mysql数据库的操作-sqlalchemy
MySQLdb支持python2.*,不支持3.* ,python3里面使用PyMySQL模块代替 python3里面如果有报错 django.core.exceptions.ImproperlyC ...
- rsync详细配置
1 说在前面的话 rsync官方网站: https://www.samba.org/ftp/rsync/rsync.html rsync是可以实现增量备份的工具.配合任务计划,rsync能实现定时或间 ...
- python学习(六)
- 使用cookie记录页面跳转次数,然后从最后一级页面跳转回首页面
1.首先,给出cookie设置,获取,删除的操作函数. function setCookie(name,value) { var Days = 30; var ex ...
- 32 C++常见错误集锦
1 下列程序中,K的值为:6 enum { a,b=5,c,d=4,e }k; K=c; 分析:enum中,首元素不赋值的话,默认为0:后一个元素不赋值的话比前一个元素大1. 2 程序运行正常. # ...
- Nginx源代码安装
1.确认系统平台及版本 [root@Trial html]# uname -r 2.6.32-696.6.3.el6.x86_64 [root@Trial html]# cat /etc/redhat ...
- 下载EU台网(欧洲台网)的地震波数据
retrievedata.py ### here first to check the existence of the focal mechanism event file in the NDK d ...