Software interface, Custom instruction examples, Chapter 2. software interface – Altera Nios II Custom User Manual
Page 17: Custom instruction examples –1, Chapter 2, For step-by, Chapter 2, software interface

January 2011
Altera Corporation
Nios II Custom Instruction User Guide
2. Software Interface
The Nios II custom instruction software interface abstracts logic implementation
details from the application code. During the build process the Nios II software build
tools generate macros that allow easy access from application code to custom
instructions.
This chapter contains the following sections:
■
“Custom Instruction Examples” on page 2–1
■
“Built-in Functions and User-defined Macros” on page 2–2
■
“Custom Instruction Assembly Software Interface” on page 2–3
Custom Instruction Examples
shows a portion of the system.h header file that defines a macro for a
bit-swap custom instruction. This bit-swap example accepts one 32-bit input and
performs only one function.
In
,
ALT_CI_BITWSWAP_N
is defined to be
0x0,
which is the custom
instruction’s index. The
ALT_CI_BITSWAP(A)
macro is mapped to a
gcc
built-in
function that takes a single argument.
For more information about the
gcc
Instruction Built-in Functions
.
illustrates application code that uses the bit-swap custom instruction.
The code in
includes the system.h file to enable the application software
to use the custom instruction macro definition. The example code declares two
integers,
a
and
a_swap
. Integer
a
is passed as input to the bit swap custom instruction
and the results are loaded in
a_swap
.
Example 2–1. Bit Swap Macro Definition
#define ALT_CI_BITSWAP_N 0x00
#define ALT_CI_BITSWAP(A) __builtin_custom_ini(ALT_CI_BITSWAP_N,(A))
Example 2–2. Bit Swap Instruction Usage
#include "system.h"
int main (void)
{
int a = 0x12345678;
int a_swap = 0;
a_swap = ALT_CI_BITSWAP(a);
return 0;
}