大会code使用AVR-GCC switch语句 [英] Assembly code for a switch statement using AVR-GCC

查看:173
本文介绍了大会code使用AVR-GCC switch语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解大会code编译器为以下开关statemet省略。它比一般的组装code我使用看到不同的gcc等。

Hey I am having trouble understanding the assembly code omitted by the compiler for the following switch statemet. It is different than the usual assembly code I see from using gcc etc.

switch(instr){ 

 case OP_NOP: 
      break;

 case OP_BIPUSH: 
    stack_push(arg0.z.bh); pc_inc = 2;break

}

大会code为上述C code:

Assembly code for the above C code:

switch(instr){ 
+00001482: 8529 LDD R18,Y+9 Load indirect with displacement 
+00001483: 2F82 MOV R24,R18 Copy register 
+00001484: E090 LDI R25,0x00 Load immediate 
+00001485: 01FC MOVW R30,R24 Copy register pair 
+00001486: 9732 SBIW R30,0x02 Subtract immediate from word 
+00001487: 3BED CPI R30,0xBD Compare with immediate 
+00001488: 05F1 CPC R31,R1 Compare with carry 
+00001489: F008 BRCS PC+0x02 Branch if carry set 
+0000148A: C39D RJMP PC+0x039E Relative jump 
+0000148B: 57E0 SUBI R30,0x70 Subtract immediate 
+0000148C: 4FFF SBCI R31,0xFF Subtract immediate with carry 
+0000148D: 0FEE LSL R30 Logical Shift Left 
+0000148E: 1FFF ROL R31 Rotate Left Through Carry 
+0000148F: 9005 LPM R0,Z+ Load program memory and postincrement 
+00001490: 91F4 LPM R31,Z Load program memory 
+00001491: 2DE0 MOV R30,R0 Copy register 
+00001492: 9409 IJMP Indirect jump to (Z) 
2003: stack_push(arg0.z.bh); pc_inc = 2; 
+00001493: 2D85 MOV R24,R5 Copy register 
+00001494: 2799 CLR R25 Clear Register 
+00001495: FD87 SBRC R24,7 Skip if bit in register cleared 
+00001496: 9590 LAT R25 Load and Toggle 
+00001497: C338 RJMP PC+0x0339 Relative jump 

我presume的code的情况下:NOP是越来越远了优化的编译器。

I presume the code in case: NOP is getting optimized away by the compiler.

但我刚走如何理解code是案件建立查找表?

But I am having just understanding how the code is setting up the lookup table for the cases??

任何帮助将是巨大的,谢谢。

Any help would be great, thanks.

推荐答案

有只有一个情况下,你的榜样来检查,所以它只是检查是否 INSTR 等于 OP_BIPUSH 。如果是的话,直接跳到做休息,否则从函数调用返回。

There is only one case to check in your example, so it just checks if instr is equal to OP_BIPUSH. If it is then, skip ahead to do the rest, otherwise return from the function call.

在通话开始时,寄存器Y(这实际上是两个通用寄存器,我忘了)指向堆栈的顶部。参数 INSTR 是9点上下摞,被加载到R24。 R25得到0,所以对包含的值 INSTR

At the start of the call, the Y register (which is really two general purpose registers, I forget which) points to the top of the stack. The parameter instr is 9 spots down the stack, and gets loaded into r24. r25 gets 0, so the pair contains the value of instr.

我们只需要测试违心的事情,所以减去2,并比较 0xBD 。 (R1是零寄存器,它总是包含0)。

We only need to test against one thing, so subtract 2 and compare to 0xBD. (r1 is the zero register. It always contains 0.)

如果结果相等,则跳过下一条指令,并继续通过他们的休息。如果它们不相等,则执行下一指令,该指令从一个跳转函数调用返回

If the results are equal, then skip over the next instruction and continue through the rest of them. If they are not equal, then execute the next instruction, which returns from the function call with a jump.

这篇关于大会code使用AVR-GCC switch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆