Arithmetic Overflow in mips

According to the MIPS instruction reference, the only addition operations which can produce overflow exceptions are the signed addition instructions:

ADD
ADDI

MIPS integers are 32-bit, and since you’ll be using signed integers, the maximum value is 231-1 (aka 2147483647 or hex 7FFFFFFF). Thus any addition which results in a number larger than this should throw an exception, e.g if you try to add 1 to 2147483647:

# Load 2147483647 into $s1
LUI $s0, 32767
ORI $s1, $s0, 65535

# Add 1 to $s1 and store in $s2. This should produce an overflow exception
ADDI $s2, $s1, 1

Leave a Comment