Home > Support > Knowledge Base > Knowledge Base Article

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

Refer inclusion of assembly in gnu C code.

Sample Code :-
{please note that in the below code snippet, double qoutes are replaced with single quotes (') for search engine optimization}
#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');
}
Contact a Digi expert and get started today! CONTACT US

Desktop Site