Forum Discussion
Altera_Forum
Honored Contributor
20 years agoInline assembly code / Nios II Project
All:
I am trying to write a simple program as part of an Altera Nios II application in which I want to embed a few lines of assembly code Can anyone provide me with an example of how this is done? I have tried a number of ways of using the asm / volatile keywords as normally used but cannot get the program to compile without errors. If this is actually supported, a simple example will suffice. Thanks Nick2 Replies
- Altera_Forum
Honored Contributor
Hi Nick,
> If this is actually supported It is. > a simple example will suffice. Here are a few: write a byte to i/o (bypass cache)
read/write the control register#define readb(addr) ( { unsigned char val; asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;} )
Regards, --Scott#define CTL_STATUS 0 /* Processor status reg */# define CTL_ESTATUS 1 /* Exception status reg */# define CTL_BSTATUS 2 /* Break status reg */# define CTL_IENABLE 3 /* Interrut enable reg */# define CTL_IPENDING 4 /* Interrut pending reg */ # define _str_(x)# x # define rdctl(reg) ( {unsigned int val; asm volatile( "rdctl %0, ctl" _str_(reg) : "=r" (val) ); val;} ) # define wrctl(reg,val) asm volatile( "wrctl ctl" _str_(reg) ",%0": : "r" (val)) /* E.g.: foo = rdctl(CTL_IENABLE); * wrctl(CTL_IENABLE, foo | 1); */ - Altera_Forum
Honored Contributor
Hi Scott:
Thanks for the reply! I wound up going through some Linux kernel driver files and taking some examples from there. Actually though, the ones you provided are best for me since I am working with the rdctl and wrctl commands. Thanks Again! Nick