In my textbook, there are these lines of code:
addu $t0, $t1, $t2
nor $t3, $t1, $zero
sltu $t3, $t3, $t2
bne $t3, $zero, Overflow
I understand the addu function, but when I get to the nor function and everything afterward, I don't understand what it does. The textbook just says t3 = the 2's complement of t1 - 1 for the 2nd line, but I don't understand how that works in binary. Would it just switch out all 0's for 1's and vice versa and then interpret that as 2's complement, resulting in a negative number? The book's explanation doesn't make sense to me.
Yes nor
-ing a value with $zero
simply inverts all the bits. For example binary 101011
nor-ed with 0 results in binary 010100
. This is also a way the assembler psuedo-op not
can be implemented.