Showing results for 
Search instead for 
Did you mean: 
Honored Contributor I

MIPS vs Nios II instruction

I am trying to make a MIPS instruction readable by Nios ii (using macros). 


The instruction moves the content of hi (or low) register to a specified register say for example $reg_A.  


For this purpose I need to know the equivalent HI/ LO register of MIPS in Nios ii so that I can use "mov" instruction to do the register movement. 


Anyone has an idea? 


Thank you
0 Kudos
3 Replies
Honored Contributor I

I presume you mean that you are trying to convert some MIPS asm source into a form that can be processed by the nios2 assembler? 


The nios2 multiply and divide instructions put their results into normal registers - so there is no equivalent of %LO and %HI. 


Also the divide instruction doesn't generate the remainder. 


One approach would be to save the operands (esp of divide) and calcuate the value when it is needed. Register r2 is usable as a temporary, as is the actual destination register. 


You might be able to save the values in memory relative to %gp. Possible alternatives are an alternate register set (usually used for interrupts) or some a custom instruction. 


Another option is to re-implement multiply, divide and the read_hi/lo inside a custom instruction in a manner that matches the mips opcodes.
Honored Contributor I

Yes I am trying to convert some MIPS instructions into a from that Nios II can process it. 


I created custom instruction for mult and multu, but the problem is that Nios II uses three operands while MIPS uses only two and as I said earlier MIPS stores the result in lo register. 

with this situation, I would have trouble writing the macro as well. 


How can I deal with this?
Honored Contributor I

I suspect the easiest way to do this is to have a additional register set, and use the 'previous' register set for additional workspace. You could designate the alternate r2 and r3 as %lo and %hi. 


Convert the multiply to write it's result into r1 (asm temp - available as a scratch register), then use wrprs to save it in the alternate set. 


Divide is a bit more tricky since the mips instruction generates the quotient and remainder. But you can still use r1 to generate both results. 


Reads of %LO and %HI are then rdprs.