avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Wrong CALL subroutine in a switch statement


From: Markus Wyss
Subject: [avr-gcc-list] Wrong CALL subroutine in a switch statement
Date: Mon, 30 Aug 2004 10:41:19 +0200

Hi avr-gcc-List

Two questions:

1.) I do have a switch construct in my actual code sequence.
As you can see the function Get_Display_Color(), placed
at +000007D4, is called three times. See C-Code below.

Twice, the function is called correctly at:
+0000077C:   940E07D4    CALL    0x000007D4       Call subroutine
+00000781:   940E07D4    CALL    0x000007D4       Call subroutine

but not at:
+00000777:   940E0000    CALL    0x00000000       Call subroutine


compiled with gcc 3.3.1.

I had a similar behavior one time ago, and I used 'if' statements
instead 'switch'. It worked fine then.
What am I doing wrong here?




2.) Here a question related to the avr-gcc-list: How do I have to change
my personal list options, that I answer to the thread in the list, and not
to the sender of a post?


Thanks for an advice

Markus Wyss




C-Code:

  switch(LED_Status)
  {
    case  LED_Off:
            {
              Display_Clear();
            } break;
    case  LED_Green:
            {
              Display_Green();
            } break;
    case  LED_Red:
            {
              Display_Red();
            } break;
    case  LED_Orange:
            {
              Display_Orange();
            } break;
    case  LED_Green_Blinking:
            {
              if (Get_Display_Color() == LED_Green) Display_Clear();
              else Display_Green();
            } break;
    case  LED_Red_Blinking:
            {
              if (Get_Display_Color() == LED_Red) Display_Clear();
              else Display_Red();
            } break;
    case  LED_Red_Green_Blinking:
            {
              if (Get_Display_Color() == LED_Green) Display_Red();
              else Display_Green();
            } break;
    default:
            {
              Display_Clear();
            } break;
  }


Compiled with avr-gcc 3.3.1:

39:         switch(LED_Status)
+0000075C:   91800060    LDS     R24,0x0060       Load direct from data space
+0000075E:   2799        CLR     R25              Exclusive OR
+0000075F:   3083        CPI     R24,0x03         Compare with immediate
+00000760:   0591        CPC     R25,R1           Compare with carry
+00000761:   F091        BREQ    +0x12            Branch if status flag set
+00000762:   3084        CPI     R24,0x04         Compare with immediate
+00000763:   0591        CPC     R25,R1           Compare with carry
+00000764:   F434        BRGE    +0x06            Branch if status flag cleared
+00000765:   3081        CPI     R24,0x01         Compare with immediate
+00000766:   0591        CPC     R25,R1           Compare with carry
+00000767:   F101        BREQ    +0x20            Branch if status flag set
+00000768:   9702        SBIW    R24,0x02         Subtract immediate from word
+00000769:   F4DC        BRGE    +0x1B            Branch if status flag cleared
+0000076A:   C020        RJMP    +0x0020          Relative jump
+0000076B:   3085        CPI     R24,0x05         Compare with immediate
+0000076C:   0591        CPC     R25,R1           Compare with carry
+0000076D:   F071        BREQ    +0x0E            Branch if status flag set
+0000076E:   3085        CPI     R24,0x05         Compare with immediate
+0000076F:   0591        CPC     R25,R1           Compare with carry
+00000770:   F034        BRLT    +0x06            Branch if status flag set
+00000771:   9706        SBIW    R24,0x06         Subtract immediate from word
+00000772:   F071        BREQ    +0x0E            Branch if status flag set
+00000773:   C017        RJMP    +0x0017          Relative jump
55:                     Display_Orange();
+00000774:   940E07D1    CALL    0x000007D1       Call subroutine
56:                   } break;
+00000776:   C016        RJMP    +0x0016          Relative jump
59:                     if (Get_Display_Color() == LED_Green) Display_Clear();
+00000777:   940E0000    CALL    0x00000000       Call subroutine
+00000779:   3081        CPI     R24,0x01         Compare with immediate
+0000077A:   F081        BREQ    +0x10            Branch if status flag set
+0000077B:   C00C        RJMP    +0x000C          Relative jump
64:                     if (Get_Display_Color() == LED_Red) Display_Clear();
+0000077C:   940E07D4    CALL    0x000007D4       Call subroutine
+0000077E:   3082        CPI     R24,0x02         Compare with immediate
+0000077F:   F059        BREQ    +0x0B            Branch if status flag set
+00000780:   C004        RJMP    +0x0004          Relative jump
69:                     if (Get_Display_Color() == LED_Green) Display_Red();
+00000781:   940E07D4    CALL    0x000007D4       Call subroutine
+00000783:   3081        CPI     R24,0x01         Compare with immediate
+00000784:   F419        BRNE    +0x03            Branch if status flag cleared
+00000785:   940E07C9    CALL    0x000007C9       Call subroutine
+00000787:   C005        RJMP    +0x0005          Relative jump
70:                     else Display_Green();
+00000788:   940E07CD    CALL    0x000007CD       Call subroutine
71:                   } break;
+0000078A:   C002        RJMP    +0x0002          Relative jump
74:                     Display_Clear();
+0000078B:   940E07C1    CALL    0x000007C1       Call subroutine


Here the called function Get_Display_Color():

+000007D4:   91800060    LDS     R24,0x0060       Load direct from data space
+000007D6:   2799        CLR     R25              Exclusive OR
273:      }
+000007D7:   9508        RET                      Subroutine return







reply via email to

[Prev in Thread] Current Thread [Next in Thread]