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");
}
Last updated:
Jan 01, 2024