Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

NIOS I custom instructions

Altera_Forum
Honored Contributor II
1,362 Views

In NIOS I, when using custom instructions with a prefix value the documentation says for the C/C++ code that it takes an 11bit immediate value. I've never heard of immediate values in terms of C/C++ code. 

 

Before I start can someone tell me if it's possible for me to pass a variable into that function as the prefix values (as long as it's 11 bits or under). 

 

In short I'm wondering if immediate means the same thing in this case as it does in assembly (since in assembly you can make the K reg whatever you want and call the function I'm assuming). 

 

Cheers
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
534 Views

Yes. The 11-bit immediate is just the K register, which you set with a pfx in the assembly. I'm not sure how you would deal with that in C, and the only use for it I can think of is for some kind of 'mode' flag that makes the custom instruction hardware behave differently depending on its value. For passing arguments to your instruction (even if the arguments are compile-time constants) you're probably just better off using normal registers as you would with any other instruction. I think it is possible though, you could just have your C wrapper for the custom instruction do a PFX first with the argument you want to pass. There might even be a less hacky way of doing it if Altera has provided a suitable macro (SET_PFX_AND_DO_CUSTOM_n or something).

0 Kudos
Altera_Forum
Honored Contributor II
534 Views

You can't use the 11 bit K register to pass an argument to a function: the K register is cleared after all instructions (except the PFX and PFXIO instructions used to set it), and the PFX opcode is not allowed in the branch delay slot. Thus, the K register will always be cleared by the CALL instruction invoking your routine. 

 

Besides, using the PFX op-code restricts you to compile-time constant values (unless you want to resort to self modifying code), while using a normal register allows the value to be set a run time. 

 

In assembly speak, the term "immediate value" refers to a constant that is included as part of the op-code itself.
0 Kudos
Altera_Forum
Honored Contributor II
534 Views

Ya it won't even compile it (and there's no way I'm doing this code in ASM). 

 

Guess I'll put the hardware on the Custom hardware interface. 

 

Cheers
0 Kudos
Reply