^

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()  

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 03/05/2015
Status Active
Type General Article
Tools
  • EDK - 10.1 sp2
  • EDK - 10.1
  • EDK - 10.1 sp1
  • More
  • EDK - 10.1 sp3
  • EDK - 11.1
  • EDK - 11.2
  • EDK - 11.3
  • EDK - 11.4
  • EDK - 11.5
  • EDK - 12.1
  • EDK - 12.2
  • EDK - 12.3
  • EDK - 12.4
  • EDK - 13.1
  • EDK - 8.1i
  • EDK - 8.1i sp1
  • EDK - 8.1i sp2
  • EDK - 8.1i sp3
  • EDK - 8.2i
  • EDK - 8.2i sp1
  • EDK - 8.2i sp2
  • EDK - 8.2i sp3
  • EDK - 9.1i
  • EDK - 9.1i sp1
  • EDK - 9.1i sp2
  • EDK - 9.1i sp3
  • EDK - 9.2i
  • EDK - 9.2i sp1
  • EDK - 9.2i sp2
  • EDK - 9.2i sp3
  • EDK - 9.2i sp4
  • Less