Home > Support > Knowledge Base
Knowledge Base
 
Reset Search
Search
 

 

Knowledge

How do I write assembly code in .C file of a NET+OS application project ?

« Go Back

Information

 
Problem Resolution

Refer inclusion of assembly in gnu C code.

Sample Code :-

#include <stdio.h>
#include <stdlib.h>

void assembly_delay();

#define LOOP_MAX (25)
int main (void)
{
int loopIdx = 0;
printf ("Hello World!\n");

// continually call a routine that will execute one instruction 4 times in one asm call
for (loopIdx = 0; loopIdx < LOOP_MAX; loopIdx++)
{
assembly_delay();
}

// now execute the same assembly directly
asm volatile("mov r0, r0\n\t");
asm volatile("mov r0, r0\n\t");
asm volatile("mov r0, r0\n\t");
asm volatile("mov r0, r0\n\t");

// now do it in one call
asm volatile(
"mov r0, r0\n\t"
"mov r0, r0\n\t"
"mov r0, r0\n\t"
"mov r0, r0\n\t"
);

printf("Test done\n");
return 0;
}

void assembly_delay()
{
asm volatile("mov r0, r0\n\t"
"mov r0, r0\n\t"
"mov r0, r0\n\t"
"mov r0, r0\n\t");
}

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255