以上来自于百度翻译

以下为原文

Yeah, the second is possibly less portable , but can do the job efficiently in this case

2019-6-28 07:12:13

评论

提交评论

以上来自于百度翻译

以下为原文

Thakns!

i need clean asms,so i will take the second.

2019-6-28 07:28:20

评论

提交评论

以上来自于百度翻译

以下为原文

this declaration cost 0 instructions, possibly less portable ;

union timer {

uint16_t i2cTimer;

uint8_t  val[2];

}  i2ct  ;

2019-6-28 07:43:39

评论

提交评论

以上来自于百度翻译

以下为原文

yes,better idea to take advantage of union,clean in c  too...

2019-6-28 07:58:38

评论

提交评论

以上来自于百度翻译

以下为原文

That's also true

2019-6-28 08:06:55

评论

提交评论

以上来自于百度翻译

以下为原文

Just curious. Could you post the disassembly for this line? I don't see how it can take 10 instructions, even for Free mode.

2019-6-28 08:14:18

评论

提交评论

以上来自于百度翻译

以下为原文

*(uint16_t*)val = i2cTimer; // assuming val is word-aligned edit: doesn't matter for XC8

If you're building a buffer, just copy i2cTimer diectly to where it should be in the buffer.

2019-6-28 08:34:14

评论

提交评论

以上来自于百度翻译

以下为原文

@NorthGuy:Thanks! all of your advice have been of great help!

2019-6-28 08:51:51

评论

提交评论

以上来自于百度翻译

以下为原文

Hi,1and0,below was asm lines i tried to restore,really confused,please kindly check if something was wrong:

5417 ;RSN-1601A_Functions.c: 126: ToSendDataBuffer[8] = i2cTimer;

5418 015B 0023 movlb 3 ; select bank3

5419 015C 085B movf _i2cTimer^(0+384),w

5420 015D 0022 movlb 2 ; select bank2

5421 015E 00A8 movwf 40

5422

5423 ;RSN-1601A_Functions.c: 127: ToSendDataBuffer[9] = i2cTimer>>8;

5424 015F 0023 movlb 3 ; select bank3

5425 0160 085C movf (_i2cTimer+1)^(0+384),w

5426 0161 0022 movlb 2 ; select bank2

5427 0162 00E3 movwf (??_CmdService^(0+256)+1)//_CmdService is the function name which contain the codes

5428 0163 0023 movlb 3 ; select bank3

5429 0164 085B movf _i2cTimer^(0+384),w

5430 0165 0022 movlb 2 ; select bank2

5431 0166 00E2 movwf ??_CmdService^(0+256)

5432 0167 0863 movf (??_CmdService^(0+256)+1),w

5433 0168 00E2 movwf ??_CmdService^(0+256)

5434 0169 01E3 clrf (??_CmdService^(0+256)+1)

5435 016A 0862 movf ??_CmdService^(0+256),w

5436 016B 00A9 movwf 41

5437

5438 ;RSN-1601A_Functions.c: 128: break;//i do above in a "case:",so "break" is here

5439 016C 0008 return

2019-6-28 09:10:59

评论

提交评论

以上来自于百度翻译

以下为原文

Use pointer conversion,only 4 instructions:

5417 ;RSN-1601A_Functions.c: 126: ToSendDataBuffer[8] = i2cTimer;

5418 015B 0023 movlb 3 ; select bank3

5419 015C 085B movf _i2cTimer^(0+384),w

5420 015D 0022 movlb 2 ; select bank2

5421 015E 00A8 movwf 40

5422

5423 ;RSN-1601A_Functions.c: 127: ToSendDataBuffer[9] = ((uint8_t *)&i2cTimer)[1];

5424 015F 0023 movlb 3 ; select bank3

5425 0160 085C movf (_i2cTimer^(0+384)+1),w

5426 0161 0022 movlb 2 ; select bank2

5427 0162 00A9 movwf 41

5428

5429 ;RSN-1601A_Functions.c: 128: break;

5430 0163 0008 return

2019-6-28 09:16:40

评论

提交评论

以上来自于百度翻译

以下为原文

Union Version:only cost 2 instructions!!!(XC8,free mode,what happeded with you)

typedef union

{ uint16_t  valUint16;

uint8_t    byte[2];

} union_uint16_t;

extern union_uint16_t  i2cTimer;

//

ASM lines:

5419 ;RSN-1601A_Functions.c: 126: ToSendDataBuffer[8] = i2cTimer.byte[0];

5420 015B 086E movf _i2cTimer^(0+256),w

5421 015C 00A8 movwf 40

5422

5423 ;RSN-1601A_Functions.c: 127: ToSendDataBuffer[9] = i2cTimer.byte[1];//cost 2 instructions!!!

5424 015D 086F movf (_i2cTimer^(0+256)+1),w

5425 015E 00A9 movwf 41

5426

5427 ;RSN-1601A_Functions.c: 128: break;

5428 015F 0008 return

2019-6-28 09:24:29

评论

提交评论

以上来自于百度翻译

以下为原文

The comparisons are not representative and depend mostly on the way the compiler allocates variables. If they're in different banks it takes 8 instructions to move 2 bytes. If they're in the same bank - 5 instructions (4 if the bank is already selected). Otherwise, it's all the same.

2019-6-28 09:41:57

评论

提交评论

以上来自于百度翻译

以下为原文

WTF...even Free mode cannot be that stupid! Lines 5427 to 5435 are totally unnecessary. That disassembly does this:

uint16_t CmdService;

CmdService = i2cTimer;

CmdService >>= 8;

ToSendDataBuffer[9] = CmdService;

2019-6-28 09:56:44

评论

提交评论

以上来自于百度翻译

以下为原文

Hi 1and0,

i just built a simple prj of xc8 under free mode to test this,by simulator,the last line did not work at all,i am afraid it is a bug of XC8 ver1.38,you could also test it on you side.

#include

#include

void main(void) {

uint16_t u16t=0xABCD;

uint8_t val[2];

val[0]= u16t;//it works,val[0] is 0xCD

val[1]= (u16t>>8) ;//vars got lost......

return;

}

asm lines:

217 ;psect for function _main

218 07EF _main:

219

220 ;main.c: 12: uint16_t u16t=0xABCD;

221

222 ;incstack = 0

223 ; Regs used in _main: [wreg+status,2]

224 07EF 30CD movlw 205

225 07F0 00F3 movwf main@u16t

226 07F1 30AB movlw 171

227 07F2 00F4 movwf main@u16t+1

228

229 ;main.c: 13: uint8_t val[2];

230 ;main.c: 14: val[0]= u16t;

231 07F3 0873 movf main@u16t,w

232 07F4 00F0 movwf ??_main

233 07F5 0870 movf ??_main,w

234 07F6 00F1 movwf main@val

235

236 ;main.c: 15: val[1]= (u16t>>8) ;

237 07F7 0874 movf main@u16t+1,w

238 07F8 00F0 movwf ??_main

239 07F9 0870 movf ??_main,w

240 07FA 00F2 movwf main@val+1

241

242 ;main.c: 17: return;

2019-6-28 10:15:35

评论

提交评论

以上来自于百度翻译

以下为原文

Hi 1and0,is that possible to know result on you side? MPLAB x blue-screened my PC several times while compiling these days,maybe i need to re install them.

2019-6-28 10:27:02

评论

提交评论

以上来自于百度翻译

以下为原文

That is an invalid test.

If your variable is never used after being written (as you have done here),

and if you don't make your variable "volatile",

then the compiler is free to discard the writing code altogether as part of its optimisation.

2019-6-28 10:34:40

评论

提交评论

以上来自于百度翻译

以下为原文

in fact,if i just add a while(1); at the end,things are in order...

2019-6-28 10:50:52

评论

提交评论

以上来自于百度翻译

以下为原文

No, it looks like it is still there at line 240.

2019-6-28 11:07:31

评论

提交评论

以上来自于百度翻译

以下为原文

sorry,i just check the output result when debugging after adding the while(1);without review asm lines;

does that mean something wrong with XC8? or need update.

2019-6-28 11:16:55

评论

提交评论

只有小组成员才能发言,加入小组>>

uint16 累加_如何把一个uint16整数分解成两个字节并传输?相关推荐

  1. 借用该函数验证哥德巴赫猜想:任意一个大的偶数都可以分解成两个素数之和。

    定义一个函数,实现判断某个整数是否是素数.借用该函数验证哥德巴赫猜想:任意一个大的偶数都可以分解成两个素数之和.从键盘输入一个偶数,输出该偶数的两个素数之和. 代码段: #include <io ...

  2. Java编程验证哥德巴赫猜想:任何一个大于6的偶数,都能分解成两个质数的和

    package com.pzhu.demo;import java.util.Scanner;public class Goldbach {//Java编程验证哥德巴赫猜想:任何一个大于6的偶数,都能 ...

  3. 整数n分解成素数乘积c语言,用C语言和汇编语言实现将1个整数分解成几个素数的乘积...

    任何1个大于2的整数都可以分解成几个素数的乘积.将1个整数分解成几个素数的乘积是个热门话题. 经常有人问到.本文试图用C语言和32位X86汇编语言给出一个比较好的实现.希望对c语言学习者和 汇编语言学 ...

  4. 整数分解成若干项之和(DFS)拓展延伸

    在深度优先搜索的例题中,有一种题型是整数分解成若干项之和. 例如将一个正整数N分解成几个正整数相加,可以有多种分解方法,例如7=1+6,7=2+5,7=1+1+5,-.编程求出正整数N的所有整数分解式 ...

  5. 请拆招:将两个已排序集合分解成两个独立部分的集合和一个共有部分的集合?...

    请拆招:将两个已排序集合分解成两个独立部分的集合和一个共有部分的集合? 请看下面的代码. using System; using System.Collections.Generic; namespa ...

  6. 数学领域著名的“哥德巴赫猜想”的大致意思是:任何一个大于2的偶数总能表示为两个素数之和。比如:24=5+19,其中5和19都是素数。本实验的任务是设计一个程序,验证20亿以内的偶数都可以分解成两个素数

    数学领域著名的"哥德巴赫猜想"的大致意思是:任何一个大于2的偶数总能表示为两个素数之和.比如:24=5+19,其中5和19都是素数.本实验的任务是设计一个程序,验证20亿以内的偶数 ...

  7. 【8558】编写算法建立的链表,实现将其分解成两个链表,其中一个全部为奇数,另一个全部为偶数(尽量利用已知存储空间)

    关注公众号程序猿从入门到入土查询更方便哦 编写算法建立的链表,实现将其分解成两个链表,其中一个全部为奇数,另一个全部为偶数(尽量利用已知存储空间) #include<bits/stdc++.h& ...

  8. html拆分单元格成两列,在excel中怎样把一个单元格拆分成两个单元格

    excel表格中如何拆分带括号的单元格比如说我有一个表格单元格内容是 :张三李四(000001) 如何将括号内的选中需要拆分的单元格,Ctrl +F把单元格里面的括号或者书名号换成逗号,然后在数据选项 ...

  9. 分解 python_面试官:如何用Python实现将一个整数分解成质因数?

    概述 今天主要分享一个关于分解质因数的实例,判断的逻辑稍微多了点,一起来看看吧~ 需求 将一个整数分解质因数.例如:输入90,打印出90=233*5 思路 其实根本不需要判断是否是质数,从2开始向数本 ...

最新文章

  1. 使用 expect 命令执行自动分发系统
  2. TMS320F28335时钟(1)
  3. 两个女孩的生日最后演变成了鬼节
  4. boot整合redis
  5. Hbase单点安装Version1.1.5
  6. EJB+JSF开发示例(附源码)
  7. 【snmp】测试流程
  8. python之celery使用详解一
  9. 深延科技:基于深度学习的智能OCR识别技术大有可为
  10. kaggle泰坦尼克号
  11. 视觉三维重建:colmap从理论到实战
  12. JAVA实训项目第一次日志
  13. HDU 5773 (DP)
  14. idea、webStrom 集成 svn 报错 Error: Node remains in conflict
  15. c#加粗代码_C# 字体加粗按钮
  16. video标签(获取视频时间总长度,视频当前时间,播放暂停方法,视频封面,)
  17. php发邮件错误,从PHP发送邮件 – 是我的错误还是邮件服务器?
  18. Word中批量更新域的两个小方法
  19. Docker总结(配合阿里云容器镜像服务)
  20. 【极简教程】用 Mkdocs 库发布你的网站

热门文章

  1. android组件间共享数据的常用方法
  2. Linux的环境变量配置
  3. SQL Server死锁
  4. 两种极端情况的案例:N+1次查询和笛卡尔积
  5. 程序员工资高,但为什么越来越多的人都不再愿意做程序员呢?
  6. 收录批量查询神器 bluecattools
  7. 免费软件做的不错的,这里要说一个叫《飞秋》的软件
  8. 一种被忽视的构造和整数溢出重现
  9. 程序员如何接私单做SOHO一族
  10. Python常见数据结构整理,分享给你们