AR# 18561


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


I would like to place 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()  


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
日期 03/05/2015
状态 Active
Type 综合文章
Tools More Less
People Also Viewed