^

AR# 18561 11.1 EDK - How do I include inline assembly within my C source files?

Keywords: EDK, inline, assembly, source, code, MicroBlaze

I am often interested in placing inline assembly commands within my C source files. Does the MicroBlaze GNU compiler recognize this? What is the format for inserting this source?

The GNU compiler (mb-gcc) was built specifically for MicroBlaze and supports many of the GNU features. Refer to the GNU source manual for applicable source support features.

Below are several examples of placing simple inline assembly commands with the main source code:

int main()
{
while(1)
for (i=128;i>0;i--){
microblaze_nbwrite_datafsl(i, 0);
j++; //below is the equivalent inline assembly commands

asm("lwi r3, r0, 292"); // load word immediate
asm("addik r3, r3, 1"); // immediate add w/ keep carry
asm("swi r3, r0, 292"); // store word immediate
}
}

Other examples include:

int a,b,c = 0;
asm ("add %0,%1,%2": "=r" (a): "r" (b), "r" (c)) ;

This example passes the variable values "b" and "c" to the "add" instruction and returns the result into "a."


AR# 18561
Date Created 09/03/2007
Last Updated 04/25/2009
Status Active
Type