Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

NIOS I custom instructions

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

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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).

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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