完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
你好,我想知道为什么模拟器中的断点在while循环和返回显示直接从i++到i+=10返回0?显然,它不会停留在while循环,我犯了什么明显的错误?它不通过i=0语句,它似乎在while循环结束时返回,不确定发生了什么。让弗兰SouthOIs//TestPro程序包含和lt;CSTDLIB & Gt;int main(int ARCC,CHAR**ARGV){int i;而(1){i++;i+=10;} i=0;返回0;}
以上来自于百度翻译 以下为原文 Hello, I was wondering why the simulator with break points in the while loop and and on return shows going straight from i++ to i+=10 to return 0 ? Apparently it won't stay in the while loop, any obvious mistake I made ? It does'nt pass the i = 0 statement, it seems to return at the end of while loop, not sure what's happening. Jean-François // TEST PROGRAM #include int main(int argc, char** argv) { int i; while (1) { i++; i+=10; } i = 0; return 0; } |
|
相关推荐
12个回答
|
|
|
它可能是由于优化。尝试删除所有优化,或使“I”易失性。
以上来自于百度翻译 以下为原文 It *could* be due to optimizations. Try removing all optimizations, or making "i" volatile. |
|
|
|
|
|
正如达里奥所说的,编译器足够聪明,可以看到你的测试没有任何用处,并将其全部优化。使“I”易失性会迫使它继续做所有毫无意义的事情。
以上来自于百度翻译 以下为原文 As Dario said, the compiler is smart enough to see that your test does nothing useful, and optimises it all away. Making "i" volatile will force it to keep doing all the pointless stuff. |
|
|
|
|
|
谢谢你的通知。在这种情况下,在添加了易失性限定符之后,行为仍然存在。i++和返回0上的断点被调用。i=0的断点从未被调用。根据模拟器,5条指令按此顺序处理:4从i++到i=10,然后返回0,返回到第一个while循环。为什么回环0语句在while循环结束时被调用?int main(int ARCC,char **ARGV){易变量int i,j;而(1){i++;i=10;i=10;} i=0;而(1){j++;++j;j+= 10;j*= 0xFF;}返回0;},弗兰。
以上来自于百度翻译 以下为原文 Thanks for the notice. In that case the behaviour remains after adding the volatile qualifier. Break points on i++ and on return 0 are called. Break point on i = 0 is never called. According to the simulator, 5 instructions are processed in this order : the 4 from i++ to i -= 10, then return 0, back to the first while loop. Any idea why the return 0 statement is called at the end of the while loop ? int main(int argc, char** argv) { volatile int i, j; while (1) { i++; i--; i+=10; i-=10; } i = 0; while (1) { j++; ++j; j+=10; j*=0xff; } return 0; } Regards, Jean-François |
|
|
|
|
|
你没有显示你的配置语句。看门狗定时器被禁用了吗?(应该是)。
以上来自于百度翻译 以下为原文 You didn't show your config statements. Is the Watchdog Timer disabled? (It should be). |
|
|
|
|
|
此外,如果可以,则显示反汇编(生成)代码。
以上来自于百度翻译 以下为原文 Also, if you can, show the disassembly (generated) code. |
|
|
|
|
|
不是这样。切换到拆卸视图以获得更精确的视图。
以上来自于百度翻译 以下为原文 It's not. Switch to the disassembly view for a more accurate view. |
|
|
|
|
|
看起来你有无尽的循环,所以你永远不会退出“(1)”循环:同样,我认为它应该是无效的主(空),并且没有返回0因为没有什么可以返回。至少XC8和C是这样的。我对XC32或者C++没有太多的了解。
以上来自于百度翻译 以下为原文 It looks like you have endless loops, so you will never exit the "while(1)" loop: int main(int argc, char** argv) { int i; while (1) { i++; i+=10; } i = 0; return 0; } Also, I think it should be void main(void), and no return 0 because there is nothing to return to. At least that is the case for XC8 and C. I don't know much about XC32 or C++. |
|
|
|
|
|
最好的回报是跳转到重置向量。最坏的情况就是逃跑。如果您的代码是在简单的情况下测试编译器,那么您将与优化器进行战斗。可以假定简单的C构造可以工作。
以上来自于百度翻译 以下为原文 A best a return would be a jump to the reset vector. At worst it would run away. If your code is to test the compiler in a simple case you will be fighting the optimizer. You can assume simple c constructs will work. |
|
|
|
|
|
它应该是编译器文档告诉你它应该是什么。即使空虚,主(),就像任何没有显式返回语句的函数一样,都会在它的关闭支架上返回。或者,如果执行决定做其他事情,比如XC8分支到地址0,你怎么知道没有什么可以返回?它可以很好地返回到C启动代码专门处理的情况下(我模糊地记得XC16将返回并执行一个复位指令),虽然它不可能是一些未定义的,它也不太可能是程序员所期望的。
以上来自于百度翻译 以下为原文 It should be whatever the compiler documentation tells you it should be. And even if void, main(), like any other function without an explicit return statement, returns at its closing brace anyway. Or not, if the implementation decides to do something else, like XC8 which branches to address 0. And how do you know there's nothing to return to? It could very well return to the C startup code which specifically handles the situation (I vaguely remember XC16 would return and execute a RESET instruction). While it's unlikely to be something undefined, it's also unlikely to be what the programmer expects. |
|
|
|
|
|
我已经设置了一个Office Type BIT.CPP,除了看门狗OFF之外://PIC32 MZ2048 ECG064配置位设置//' C源代码配置语句/ /DVCFG3//USERID=不设置μ-PracMA配置FMIIN = //Ethernet RMII/MII启用(MII启用)PIN选择(默认以太网I/O)α-PrAPMA配置PGL1WORE=//许可组锁单向配置(仅允许一个重新配置),γ-PracMA配置PMDL1WORE = / /外围模块禁用配置(仅允许一个重新配置)构形(只允许一个重新配置)(PLL Input Divider),A/USB UBID选择(由USB模块控制)//DVCFG2α-PracMA配置,FPLLIDEV=DIVI8//系统(8x除法器)α-PrAPMA配置FPLLRNG=RangeEY34配置FPLILLK=PLLYFRC//系统PLL输入时钟选择(FRC输入到系统PLL)α-PrAPMA配置FLLMult=Muli1212//PLL乘法器(PLL乘以128)α-PrAPMA配置FPLLoDIV=DIVY32//系统PLL输出时钟分频器(32 X分频器)PLL输入频率选择(USB锁相环输入为24 MHz)(α-PracMA配置),ON//USB PLL使能(启用了USB PLL)//DVCFG1α-PrAPMA配置FFNC=FRCdIV/ /振荡器选择位(快速RC OSC W/DIV-N(FRCDEDI))α-PrimaMac配置DMTINV= WIN12127Y128//DMT计数窗口间隔(Window/INT)ErValue值为127/128计数器值(Oracle配置),FSCONEN=ON//次振荡器使能(启用SOSC),PrimaMac配置,IOSO=ON//内部/外部切换(启用)α-PracMA配置,POSCMOD=OF//主振荡器配置(初级OSC禁用)α-PracMA配置OSCIOFNC=OF//CLKo输出信号在OSCO PIN(禁用)上激活,Timer Postscaler,PraceMac配置,FCKSM=CSEME//时钟切换和监视器选择(启用时钟开关,启用FSCM)。打夯(WDT在Flash编程中停止){ PrimaMac配置= Window=正常/ /看门狗定时器窗口模式(看门狗定时器在非窗口模式下)* PrimaMac配置FFDTEN=OF//看门狗定时器启用(WDT禁用)* PrimaMac配置FFDSTWSNZ=WiSZZ25//看门狗定时器窗口大小(窗口大小为25%)AGMA配置DMTCnt= DMT31//Debug定时器计数选择(2 ^ 31(2147483648))* PrimaMac配置FDMTEN = //Debug定时器启用(Deadman Timer启用)//DVCFG0*PracMA配置调试=关闭/背景调试器启用(调试器被禁用),γ-PrAPMA CONFIG JTAGEN = ON//JTAG启用(JTAG端口E)NeTalk PrimaMac配置,ICSEL=ICSUPGX1//ICE/ICD COMM通道选择(PGEC1/PGED1通信),TraceMeCon,TrCEN= ON/TraceNo启用(启用CPU中的跟踪特性)OFF解锁/ /动态Flash ECC配置(ECC和动态ECC被禁用(ECCCON位可写))γ* PrimaMac配置FFAIL= OF//FLASH睡眠模式(当设备处于休眠模式时FLASH被关闭)* PrimaMac配置=PGYALAL//Debug模式CPU访问权限(允许CPU访问T)o所有的许可区域)E.ApTracMaungEJTAGBEN =正常//EJTAG引导(正常EJTAG功能)//DeCP00*PrimaMac配置(CPU=关闭/ /代码保护(保护禁用)//SEQ0//DEVADC1//DEVADC2//DEVADC3//DEVADC4//DEVADC5//OXY PracMA配置语句应该在项目文件之前包括/ /使用)项目枚举,而不是γ定义为ON和OFF。
以上来自于百度翻译 以下为原文 I have set up a configuration_bits.cpp with defaults except watchdog off: // PIC32MZ2048ECG064 Configuration Bit Settings // 'C' source line config statements // DEVCFG3 // USERID = No Setting #pragma config FMIIEN = ON // Ethernet RMII/MII Enable (MII Enabled) #pragma config FETHIO = ON // Ethernet I/O Pin Select (Default Ethernet I/O) #pragma config PGL1WAY = ON // Permission Group Lock One Way Configuration (Allow only one reconfiguration) #pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration) #pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration) #pragma config FUSBIDIO = ON // USB USBID Selection (Controlled by the USB Module) // DEVCFG2 #pragma config FPLLIDIV = DIV_8 // System PLL Input Divider (8x Divider) #pragma config FPLLRNG = RANGE_34_68_MHZ// System PLL Input Range (34-68 MHz Input) #pragma config FPLLICLK = PLL_FRC // System PLL Input Clock Selection (FRC is input to the System PLL) #pragma config FPLLMULT = MUL_128 // System PLL Multiplier (PLL Multiply by 128) #pragma config FPLLODIV = DIV_32 // System PLL Output Clock Divider (32x Divider) #pragma config UPLLFSEL = FREQ_24MHZ // USB PLL Input Frequency Selection (USB PLL input is 24 MHz) #pragma config UPLLEN = ON // USB PLL Enable (USB PLL is enabled) // DEVCFG1 #pragma config FNOSC = FRCDIV // Oscillator Selection Bits (Fast RC Osc w/Div-by-N (FRCDIV)) #pragma config DMTINTV = WIN_127_128 // DMT Count Window Interval (Window/Interval value is 127/128 counter value) #pragma config FSOSCEN = ON // Secondary Oscillator Enable (Enable SOSC) #pragma config IESO = ON // Internal/External Switch Over (Enabled) #pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled) #pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled) #pragma config FCKSM = CSECME // Clock Switching and Monitor Selection (Clock Switch Enabled, FSCM Enabled) #pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576) #pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming) #pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode) #pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled) #pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%) #pragma config DMTCNT = DMT31 // Deadman Timer Count Selection (2^31 (2147483648)) #pragma config FDMTEN = ON // Deadman Timer Enable (Deadman Timer is enabled) // DEVCFG0 #pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled) #pragma config JTAGEN = ON // JTAG Enable (JTAG Port Enabled) #pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (Communicate on PGEC1/PGED1) #pragma config TRCEN = ON // Trace Enable (Trace features in the CPU are enabled) #pragma config BOOTISA = MIPS32 // Boot ISA Selection (Boot code and Exception code is MIPS32) #pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration (ECC and Dynamic ECC are disabled (ECCCON bits are writable)) #pragma config FSLEEP = OFF // Flash Sleep Mode (Flash is powered down when the device is in Sleep mode) #pragma config DBGPER = PG_ALL // Debug Mode CPU Access Permission (Allow CPU access to all permission regions) #pragma config EJTAGBEN = NORMAL // EJTAG Boot (Normal EJTAG functionality) // DEVCP0 #pragma config CP = OFF // Code Protect (Protection Disabled) // SEQ0 // DEVADC1 // DEVADC2 // DEVADC3 // DEVADC4 // DEVADC5 // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include |
|
|
|
|
|
):Li K0、-2534、K0、229 6Jr K0NopAudiu SP、SP、-8SW AT、4(SP)SW V1、8(SP)SW A0、16(SP)SW A1、20(SP)SW A2、24(SP)SW A3、28(SP)SW T0、32(SP)SW T1、36(SP)SW T2、40(SP)SW T3、44(SP)SW T4、48(SP)SW T5、52(请在下面的DISSCOM中找到(不能上传文件到帖子)T0SWW T0、76(SP)MFHI T0SW T0、80(SP)Lui K0、-2534 4Addiu K0、K0、28 8NOPMFC0 A0、CaseMFC0 0 A1、STATUS JALR K0NOPLW T0、80(SP)MTHI T0LW T0、76(SP)MTLO T0LW AT、4(SP)LW V0、8(SP)LW V1、12(SP)LW A0、16(SP)LW A1、Y(SP)LW A2、Y(SP)L SW T6,56(SP)SW T7,60(SP)SW T8,64(SP)SW T9,68(SP)SW RA,72(SP)MFLOLW T3、44(SP)LW T5、52(SP)LW T6、56(SP)LW T7、60(SP)LW T8、64(SP)LW Ta、68(SP)LW RA、72(SP)Audiu SP、SP、88 eHBJON重置Erjjr Raunon BooTrand Nopjr RANOPULI K0、-2534 4Addiu K0、K0、2080JR K0NoPuli V0、-2534 4LW V0、SUN(V0)Addiu V1、ZER W 3,28(SP)LW T0,32(SP)LW T1,36(SP)LW T2,40(SP)SW S1、24(SP)SW S0、20(SP)LuI S0、S0、644 Addiu S1、0、-1Jalr V0Audiu S0、S0、-4LW V0、4(S0)BNE V0、S1、0x9D000 0140W La、28(SP)LW S1、24(SP)LW S0、20(SP)Audiu SP、SP、32 JR RANOPMFC0 K0、STATUS LUI K1、-65 ORI K1、K1、-1和O,-1Beq V0,V1,0x9D000 0160NopAudiu SP,SP,-32 SW RA,28(SP)16JR K0NoPuli A0、-2534 4Addiu SP、SP、-244UDU A0、0、0x9D000 01ACSW RA、20(SP)JALR A0NopANDI A0、A0、0ANDI A1、A1、0LUI T0、-2534 4Addiu T0、T0、T2、27 0 JAALR T0NopPyCRT00出口LUI V0、0ADUVU V0、V0、0BEQ V0、0、0x9D000 01DCNopjalr K0,K0,K1MTC0 K0,StaseSerETLUI K0,-2534 4Addiu K0,K0,0默认中断LUI V0、0Audiu V0、V0、1Beq V0、0x9D00228 LUI V0、0Audiu V0、V0、0BEQL V0、0、-0x9D000 022Culi V0、-2534 4SDBBP 0JR RANOLIPI V0、-2534 4Addiu V0、V0、3064 BEQ V0、0、0x9D000 0240Nopjalr V0Nopjr RANOPADIUP SP、SP、-32 SW RA、20(SP)JAL帧V0Nopeq零,零,α-CRT00Extnopop.MMyopopjal-OxNoopaljcToSuxNoPulw RA,20(SP)JR RAUDUU SP,SP,32,SW RA,20(SP)JAL,DoGualLaLuxdTrsS.AuxNoPulw RA,20(SP)JR RADuuu SP,SP,32 NopopydOrthEnthoNoLB零,720(零)SLLV零,零,Zr0OVF零,零,0NOPLB零,688(零)加零,零,零NOPLB零,648(零)sLLV零,零,Zr0OVF零,零,0NopCax 1, 1344(GP)TEQ零,Zr0OVF零,零,0SLL零,零,8
以上来自于百度翻译 以下为原文 Please find hereunder the dissassembly (could'nt upload the file to the post): LUI K0, -25344 ADDIU K0, K0, 2296 JR K0 NOP ADDIU SP, SP, -88 SW AT, 4(SP) SW V0, 8(SP) SW V1, 12(SP) SW A0, 16(SP) SW A1, 20(SP) SW A2, 24(SP) SW A3, 28(SP) SW T0, 32(SP) SW T1, 36(SP) SW T2, 40(SP) SW T3, 44(SP) SW T4, 48(SP) SW T5, 52(SP) SW T6, 56(SP) SW T7, 60(SP) SW T8, 64(SP) SW T9, 68(SP) SW RA, 72(SP) MFLO T0 SW T0, 76(SP) MFHI T0 SW T0, 80(SP) LUI K0, -25344 ADDIU K0, K0, 2848 NOP MFC0 A0, Cause MFC0 A1, Status JALR K0 NOP LW T0, 80(SP) MTHI T0 LW T0, 76(SP) MTLO T0 LW AT, 4(SP) LW V0, 8(SP) LW V1, 12(SP) LW A0, 16(SP) LW A1, 20(SP) LW A2, 24(SP) LW A3, 28(SP) LW T0, 32(SP) LW T1, 36(SP) LW T2, 40(SP) LW T3, 44(SP) LW T4, 48(SP) LW T5, 52(SP) LW T6, 56(SP) LW T7, 60(SP) LW T8, 64(SP) LW T9, 68(SP) LW RA, 72(SP) ADDIU SP, SP, 88 EHB _on_reset ERET JR RA _on_bootstrap NOP JR RA NOP LUI K0, -25344 ADDIU K0, K0, 2080 JR K0 NOP LUI V0, -25344 LW V0, 648(V0) ADDIU V1, ZERO, -1 BEQ V0, V1, 0x9D000160 NOP ADDIU SP, SP, -32 SW RA, 28(SP) SW S1, 24(SP) SW S0, 20(SP) LUI S0, -25344 ADDIU S0, S0, 644 ADDIU S1, ZERO, -1 JALR V0 ADDIU S0, S0, -4 LW V0, 4(S0) BNE V0, S1, 0x9D000140 LW RA, 28(SP) LW S1, 24(SP) LW S0, 20(SP) ADDIU SP, SP, 32 JR RA NOP MFC0 K0, Status LUI K1, -65 ORI K1, K1, -1 AND K0, K0, K1 MTC0 K0, Status ERET LUI K0, -25344 ADDIU K0, K0, 16 JR K0 NOP LUI A0, -25344 ADDIU SP, SP, -24 ADDIU A0, A0, 584 BEQ A0, ZERO, 0x9D0001AC SW RA, 20(SP) JALR A0 NOP ANDI A0, A0, 0 ANDI A1, A1, 0 LUI T0, -25344 ADDIU T0, T0, 2700 JALR T0 NOP __crt0_exit LUI V0, 0 ADDIU V0, V0, 0 BEQ V0, ZERO, 0x9D0001DC NOP JALR V0 NOP BEQ ZERO, ZERO, __crt0_exit NOP _DefaultInterrupt LUI V0, 0 ADDIU V0, V0, 1 BEQ V0, ZERO, 0x9D000228 LUI V0, 0 ADDIU V0, V0, 0 BEQL V0, ZERO, 0x9D00022C LUI V0, -25344 SDBBP 0 JR RA NOP LUI V0, -25344 ADDIU V0, V0, 3064 BEQ V0, ZERO, 0x9D000240 NOP JALR V0 NOP JR RA NOP ADDIU SP, SP, -32 SW RA, 20(SP) JAL frame_dummy NOP JAL __do_global_ctors_aux NOP LW RA, 20(SP) JR RA ADDIU SP, SP, 32 ADDIU SP, SP, -32 SW RA, 20(SP) JAL __do_global_dtors_aux NOP LW RA, 20(SP) JR RA ADDIU SP, SP, 32 NOP __DTOR_END__ NOP LB ZERO, 720(ZERO) SLLV ZERO, ZERO, ZERO MOVF ZERO, ZERO, 0 NOP LB ZERO, 688(ZERO) ADD ZERO, ZERO, ZERO NOP LB ZERO, 648(ZERO) SLLV ZERO, ZERO, ZERO MOVF ZERO, ZERO, 0 NOP CACHE 1, 1344(GP) TEQ ZERO, ZERO MOVF ZERO, ZERO, 0 SLL ZERO, ZERO, 8 |
|
|
|
|
|
您好,是的,目的是永远留在这个while循环,这只是模拟器亮点在绿色的返回0语句结束后while循环。但是有人说这个返回实际上是不被调用的,我不知道它为什么在模拟器模式下显示和停止(断点),但是我确认它应该留在这个while循环中。这个函数main返回一个int并期望一个int,但是那是默认生成的CPP文件。当然是N。在一个OS中,主函数会退出,另一个进程可能会看到函数正确返回。但是在实践中,它可能不会有太大的变化。
以上来自于百度翻译 以下为原文 Hello, Yes the purpose was to stay forever in this while loop, it's just the Simulator highlights in green the Return 0 statement after the end of the while loop. But someone stated this return is in effect not called, I'm not sure why it's showed and stopped at (break point) in simulator mode, but I confirm it should stay in this while loop. This function main return an int and expects an int, however that' was the default generated CPP file. Of course it's not an os where the main function would excit and another process may expect to see that the function returned properly. But in practice it may not change much. The arguments received might probably be not applicable for the microchip either. |
|
|
|
|
只有小组成员才能发言,加入小组>>
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 08:03 , Processed in 1.237737 second(s), Total 95, Slave 78 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
500