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 ...
随机推荐
- Spark面试相关
Spark Core面试篇01 随着Spark技术在企业中应用越来越广泛,Spark成为大数据开发必须掌握的技能.前期分享了很多关于Spark的学习视频和文章,为了进一步巩固和掌握Spark,在原有s ...
- Vnpy二次开发应用所需图标
在针对Vnpy二次开发时,很多窗口中需要使用到“小图标” 给大家分享一个UI的专业图标网,上面资源齐全. https://www.iconfont.cn/collections?personal=1
- 利用iframe实现无刷新提交
服务器里边:
- 路由表flags的U值引起的能ping通网关,ping不通其它网段的案例
故障的: 正常的: 初步分析: 看路由表的flags ,之前故障时是U.现在正常的是UG查了下说明,应该是这个原因.U — 路由是活动的G — 路由指向网关
- 文献导读 | A Pan-Cancer Analysis of Enhancer Expression in Nearly 9000 Patient Samples
Chen, H., Li, C., Peng, X., Zhou, Z., Weinstein, J.N., Liang, H. and Cancer Genome Atlas Research Ne ...
- jQuery操作iframe中js函数的方法小结
1.jquery操作iframe中的元素(2种方式) ? 1 2 var tha = $(window.frames["core_content"].document).find( ...
- SSH免密码登录教程
在一些受信任的环境中配置免密码登录,是比较方便的:而对于ansible等自动化工具配置免密码登录更是必要的. 免密码登录的要点就是,把想让服务器信任的客户机的公钥发送到服务器. 当客户机连接服务器时直 ...
- 实现首字母或拼音检索-sql语句方式
create function [dbo].[fn_GetPY](@str nvarchar(max),@type int) returns nvarchar(max) as begin ) begi ...
- JS-使用indexof来统计字符出现次数
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android stdio 报错 error invoking main method
打开Android stdio失败 报错:error invoking main method 想想前一天做了什么事?? 昨天把企图把Android Stdio文件包移盘,但是中途截止了,也就是说移动 ...