Domanda

I am just started learning exception handler of MIPS instruction.

I need to make my program to have Arithmetic overflow exception so that i can test my exception handler.

I have two array A and B. Array A has hex number and Array B has integers.

How to make overflow by adding hex number and integer ?

The addition of which hex number and integer can cause overflow?

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top