cancel
Showing results for 
Search instead for 
Did you mean: 

Knowledge Base Articles

ImageCraft Compiler Optimizing Out Inline asm Code Following a Return Statement – KBA90110

Anonymous
Not applicable

ImageCraft Compiler Optimizing Out Inline asm Code Following a Return Statement – KBA90110

Version: **

 

Question: The ImageCraft compiler optimizes out any inline asm code that is placed after the return statement in a function. If this inline asm code contains any label that is called from any other piece of code, then the compiler throws an error that the label is undefined. How can you work around this issue?

 

Answer:

The following code segment throws a compiler error that “Foo” is an undefined symbol.

void main(void) {         BYTE i;  // M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts  // Insert your main routine code here. while (1)  {   i = test_function();   asm ("lcall Foo");  } }  BYTE test_function(void) {  BYTE b;  n++;  b = n* 3;  return(b);  asm ("Foo: nop \n nop \n ret"); }

Workarounds:

  1.   Place a label before the inline asm code so that the compiler does not optimize the asm code away, as shown here:  

       BYTE test_function(void)
       {
       BYTE b;
       n++;
       b = n* 3;
       return(b);
       UNUSED_LABEL:
       asm ("Foo: nop \n nop \n ret");
       }

  2.   Place the inline asm code outside the function, as shown here:  

       BYTE test_function(void)
       {
       BYTE b;
       n++;
       b = n* 3;
       return(b);
       }
       asm ("Foo: nop \n nop \n ret");

  3.   Create a separate asm file where the label "Foo" is defined.

Any of the above three workarounds will result in successful build of the code.

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎Aug 27, 2014 08:01 AM
Updated by:
Anonymous
 
Contributors