Custom instruction assembly software interface, Custom instruction assembly software interface –3, R to – Altera Nios II Custom User Manual

Page 19: Custom instruction

Advertising
background image

Chapter 2: Software Interface

2–3

Custom Instruction Assembly Software Interface

January 2011

Altera Corporation

Nios II Custom Instruction User Guide

Example 2–4

shows user-defined custom instruction macros used in an application.

On lines 2 through 6, the user-defined macros are declared and mapped to the
appropriate built-in functions. The macro

UDEF_MACRO1

takes a float as an input

parameter and does not return anything. The macro

UDEF_MACRO2

takes a pointer as

an input parameter and returns a float. Lines 14 and 15 show code that uses the two
user-defined macros.

Custom Instruction Assembly Software Interface

The Nios II custom instructions are also accessible in assembly code. This section
describes the assembly interface.

Custom instructions are R-type instructions, containing:

A 6-bit opcode

Three 5-bit register index fields

Three 1-bit fields for the

readra

,

readrb

, and

writerc

signals

An 8-bit

N

field, used for the custom instruction index (opcode extension), and

optionally including a function select subfield

Example 2–4. Custom Instruction Macro Usage Example

1. /* define void udef_macro1(float data); */
2. #define UDEF_MACRO1_N 0x00
3. #define UDEF_MACRO1(A) __builtin_custom_nf(UDEF_MACRO1_N, (A));
4. /* define float udef_macro2(void *data); */
5. #define UDEF_MACRO2_N 0x01
6. #define UDEF_MACRO2(B) __builtin_custom_fnp(UDEF_MACRO2_N, (B));
7.
8. int main (void)
9. {
10.

float a = 1.789;

11.

float b = 0.0;

12.

float *pt_a = &a;

13.
14.

UDEF_MACRO1(a);

15.

b = UDEF_MACRO2((void *)pt_a);

16.

return 0;

17. }

Advertising