Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26655

What is the difference between ADD rA, rB, r0 and ADDI rA, rB, 0?

I heard these are very different but why are the results different?

ADD rA, rB, r0

is instruction typ R with r0 that contains 0 so 0 is added to rB and placed in rA that will contain rB+0, right?

ADDI rA, rB, 0

this is an instruction typ I but it does the same the first one or won't it?

Upvotes: 1

Views: 2340

Answers (1)

old_timer
old_timer

Reputation: 71506

You would have to look at the implementation of the specific processor. If the processor knows on a read of r0 that it can shortcut and make it a zero, then it can be faster than going to the register file to fetch the value for r0. And that would come into play if there were a lot of register file activity forcing a stall, only adding clocks if there were register file interference over multiple instructions. Basically, I doubt there is a difference from that perspective.

As far as functionality the two instructions are equivalent as r0 always reads as zero so the result of both operations is.

ra = rb + 0.

both ADD and ADDI signal overflow, but adding zero to rb you cant get an overflow so it doesnt matter if you use ADD/ADDU or ADDI/ADDIU

Upvotes: 2

Related Questions