完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
在XC8下,我有一个uint16_t整数分解成两个字节,通过USB传输到host.uint16_t i2ctimer;//这就是我要传输到host//demo:uint8_t val[2];val[0]=i2cTimer;//low byte ofi2cTimer将被复制到Val[0]?Val[1 ]=I2cTime≫Gt;8;/HyByLoFi2cTimeT将被复制到Val[1 ]?//但这个单线“C”行在XC8下花费超过10条指令(@ $ $@ $ $!!!!)或者:Val[1 ] =((UIT88T**)和I2cTIMER)[1 ];/它会起作用吗?它只需要4个指令,如果它真的起作用,那就太神奇了!!
以上来自于百度翻译 以下为原文 under XC8,i have one uint16_t integer to break into two bytes to transfer via USB to host. uint16_t i2cTimer;//this is what i want to transfer to host //demo: uint8_t val[2]; val[0] = i2cTimer;//low byte of i2cTimer will be copied to Val[0]?? val[1] = i2cTimer>>8;//hi byte of i2cTimer will be copied to Val[1]?? //but this singel "C" line cost more than 10 instructions under XC8(@$$@#$!!!) or:val[1] = ((uint8_t*)&i2cTimer)[1];//will it work? it only cost 4 instructions,amazing if it does work!! |
|
相关推荐
19个回答
|
|
|
是的,第二个可能不那么便携,但在这种情况下可以有效地完成工作。
以上来自于百度翻译 以下为原文 Yeah, the second is possibly less portable , but can do the job efficiently in this case |
|
|
|
|
|
谢谢!我需要干净的ASM,所以我要第二个。
以上来自于百度翻译 以下为原文 Thakns! i need clean asms,so i will take the second. |
|
|
|
|
|
此声明花费0个指令,可能较少便携;联合定时器{UTI1616T I2CTTIMER;UIT88T VAL〔2〕;}I2CT;
以上来自于百度翻译 以下为原文 this declaration cost 0 instructions, possibly less portable ; union timer { uint16_t i2cTimer; uint8_t val[2]; } i2ct ; |
|
|
|
|
|
是的,更好的想法利用联盟,在C中也清洁…
以上来自于百度翻译 以下为原文 yes,better idea to take advantage of union,clean in c too... |
|
|
|
|
|
|
|
|
|
|
|
只是好奇而已。你能把这条线拆开吗?我不知道它怎么能接受10个指令,即使是免费模式。
以上来自于百度翻译 以下为原文 Just curious. Could you post the disassembly for this line? I don't see how it can take 10 instructions, even for Free mode. |
|
|
|
|
|
如果正在构建缓冲区,只需将I2cTimeIt直接复制到缓冲区中的位置即可。
以上来自于百度翻译 以下为原文 *(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. |
|
|
|
|
|
@ NorthGuy:谢谢!你所有的建议都帮了大忙!
以上来自于百度翻译 以下为原文 @NorthGuy:Thanks! all of your advice have been of great help! |
|
|
|
|
|
嗨,1和0,下面是我试图恢复的asm行,非常困惑,请检查是否有错误:5417;RSN-1601A_Functions.c:126:ToSendDataBuffer[8]=i2cTimer;5418 015B 0023movlb 3;选择bank3 5419 015C 085B movf_i2cTimer^(0+384),w 5420 015D 0022movlb 2;选择bank2 5421 015E00A8movwf405422 5423;RSN-1601A_Functions.c:127:ToSendDataBuffer[9]=i2cTimer>>8;5424015F0023movlb3;选择bank35250160085Cmovf(_i2cTimer+1)^(0+384),w 5426 0161 0022 movlb 2;选择bank25706200E3movwf(??_CmdService^(0+256)+1)//_CmdService是包含代码5428 0163 0023movlb 3的函数名;选择bank3 5429 0164 085Bmovf_i2cTimer^(0+384),w 5430 0165 0022movlb 2;选择bank2 5431 0166 00E2 movwf???CMDService ^(0 + 256)5432?0167 0863 MOVF(?)?* CMDService ^(0 + 256)+ 1),W 5433 0168 00 E2 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在上面做“case:”,所以“break”在这里是5439016C0008.。
以上来自于百度翻译 以下为原文 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 |
|
|
|
|
|
使用指针转换,只有4个指令:5417;RSN-1601AY函数。C:126:SoTunDigabuffER(8)=I2cTIMER;5418 015B 0023 MOVLB 3;选择BANG3 5419 015C 085 B MOVFF I2CTIME ^(0±384),W 5420 015D 0022 MOVLB 2;选择BAN2 015E 0A8 MOVWFα;RSN-1601AII函数。缓冲器〔9〕=((uTn8*T*)和I2cTIMER)〔1〕;5424 015F 0023 MOVLB 3;选择BANG3 5425 0160 085 C MOVF(αi2cTime^(0+384)+1),W 5426 0161 0161 MOVLB;选择BANG2Y-A00 A9 MOVWFα;RSN-1601AII函数。C::中断;
以上来自于百度翻译 以下为原文 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 |
|
|
|
|
|
联合版:只需花费2条指令!!!!(XC8,自由模式,与你有关的)打字工会{uint16_t值Uint16;uint8_t字节[2];}uni_uni_2616161616162616161616161616}联合{uint8_昶昶联合{{{{XC8(XC8,自由模式,与你有关的)打字工会)打字工会{{uint16_uint16_262626166666号联合{/////{///////////////////////////////////////////////////i2cTimer.byte[0];5420 015B 086Emovf_i2cTimer^(英文)0+256),w 5421 015C 00A8 movwf 40 5422 5423;RSN-1601A_Functions.c:127:ToSendDataBuffer[9]=i2cTimer.byte[1];//cost 2指令!!!!5424015D086Fmovf(_i2cTimer^(0+256)+1),w 5425 015E 00A9 movwf 41 5426 5427;RSN-1601A_Functions.c:128:break;5428015F0008.
以上来自于百度翻译 以下为原文 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 |
|
|
|
|
|
比较并不具有代表性,主要取决于编译器分配变量的方式。如果它们在不同的银行,则需要8个指令来移动2字节。如果他们在同一家银行- 5条指令(4如果银行已经被选中)。否则,一切都是一样的。
以上来自于百度翻译 以下为原文 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. |
|
|
|
|
|
即使是自由模式也不可能那么愚蠢!线5427至5435完全是不必要的。这种分解是这样做的:
以上来自于百度翻译 以下为原文 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; |
|
|
|
|
|
嗨,1and0,我刚在自由模式下构建了一个简单的xc8 prj来测试它,通过模拟器,最后一行根本不起作用,恐怕是XC8 ver1.38的bug,您也可以在您这边测试它。include
以上来自于百度翻译 以下为原文 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; |
|
|
|
|
|
嗨1和0,你能知道结果吗?MPLAX-Blue在我编译这些天的时候多次筛选了我的PC,也许我需要重新安装它们。
以上来自于百度翻译 以下为原文 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. |
|
|
|
|
|
这是一个无效的测试。如果你的变量在被写完之后从未被使用(就像你在这里所做的),并且如果你没有使你的变量“易失性”,那么编译器可以自由地完全放弃写代码作为其优化的一部分。
以上来自于百度翻译 以下为原文 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. |
|
|
|
|
|
事实上,如果我只添加一段时间(1);最后,事情就好了…
以上来自于百度翻译 以下为原文 in fact,if i just add a while(1); at the end,things are in order... |
|
|
|
|
|
|
|
|
|
|
|
对不起,在添加.(1)之后调试时,我只是检查输出结果,没有检查asm行,这是否意味着XC8有问题?或者需要更新。
以上来自于百度翻译 以下为原文 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. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
503 浏览 0 评论
5812 浏览 9 评论
2350 浏览 8 评论
2237 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3544 浏览 3 评论
1160浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1122浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
889浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
503浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-14 07:47 , Processed in 1.241377 second(s), Total 110, Slave 93 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
962