ImageCraft Compiler Optimizing Out Inline asm Code Following a Return Statement – KBA90110
Anonymous
Not applicable
Aug 27, 2014
08:01 AM
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Aug 27, 2014
08:01 AM
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:
- 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");
} - 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"); - 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.
Labels
- Tags:
- psoca 1
Rate this article:
Contributors
-
This widget could not be displayed.Anonymous