0
votes

My professor gave us a worksheet on MIPS but never really gave examples so I need to assume my interpretations of the instructions are correct. I'm fairly certain that most of the questions require ADD and ADDI, but I want to double check I'm using it correctly.

"Provide a sequence that performs:

increments register $15 by 2010

I think that this is ADDI $15, $15, 2010

Would ADD work better? Would there be a way to implement that?

There is also a question asking for a sequence that "puts value 12345 in a word at memory location 65,528" that confuses me.

2

2 Answers

0
votes

addi is the canonical way to add a literal (What we call an 'immediate' value, hence the i in addi) to the value of a register.

If you're not allowed to use addi (Some schools don't), you can combine add and li. li $reg, imm loads the value of imm (A numeric literal) into the register $reg.

In terms of what works better, if there's any difference at all it'll be negligible. If anything at all, addi will be faster by one CPU cycle. The difference is no negligible that for most purposes it doesn't matter. In an academic setting, it almost definitely doesn't matter.

As for your second question: it's not very clear wording, but you're being asked to store an immediate value into a location in memory. Unless your professor really didn't talk about the instructions at all, you should have at least one instruction on your worksheet that can do something like that.

Look at sw. You'll need to do a little preprocessing, but it'll get you on your way.

0
votes

Here are some examples how to do it, not necessarily "optimal" instruction sequences;

ADDI adds an immediate value to a register, and stores the result in another register, while ADD adds two registers and stores a value in a third register.

For example, your "add 2010" task could be done either way, although simpler with ADDI since you'd need to store the value 2010 in a register first to use ADD;

ADDI $15, $15, 2010

or (for example);

ORI $1, $0, 2010         ; store the value 2010 in $1
ADD $15, $15, $1         ; add $1 with $15, store result in $15

In this case ADDI is simpler. It would make more sense to use ADD if the value you want to add won't fit in the 16 bits signed value allowed by ADDIs immediate value.

As an example for your second question, you can easily store the required values in registers;

ORI $14, $0, 12345
ORI $15, $0, 65528

...and then you can just use SW to store the word;

SW $14, 0($15)

If your professor's instruction list does not give enough information, this page is a pretty good starting point, although the MIPS instruction set is very well documented on the web if you look around a bit.