Question: Rewrite the base exception handler that comes with SPIM (described in App A.7) to look for arithmetic overflow exception, and for an arithmetic overflow exception
Rewrite the base exception handler that comes with SPIM (described in App A.7) to look for arithmetic overflow exception, and for an arithmetic overflow exception inspect the arithmetic instruction that caused the exception through EPC; modify the contents of the dest register of this instruction as follows. If the sign of the current value in dest register Rd is 1 (remember 1 with an overflow means that the actual result was meant to be positive) then write Rd 0x7fffffff, else Rd 0x80000000. Try out your new exception handler with SPIM on a small program that forces an arithmetic overflow. [15 points]
.ktext 0x80000180
mov $k1, $at # Save $at register
sw $a0, save0 # Handler is not re-entrant and cant use
sw $a1, save1 # stack to save $a0, $a1
# Dont need to save $k0/$k1
mfc0 $k0, $13 # Move Cause into $k0 srl $a0, $k0, 2 # Extract ExcCode field andi $a0, $a0, Oxf bgtz $a0, done # Branch if ExcCode is Int (0) mov $a0, $k0 # Move Cause into $a0
mfco $a1, $14 # Move EPC into $a1
jal print_excp # Print exception error message
done: mfc0 $k0, $14 # Bump EPC
addiu $k0, $k0, 4 # Do not re-execute faulting instruction
mtc0 $k0, $14 # EPC mtc0 $0, $13 # Clear Cause register
mfc0 $k0, $12 # Fix Status register
andi $k0, Oxfffd # Clear EXL bit
ori $k0, Ox1 # Enable interrupts
mtc0 $k0, $12
lw $a0, save0 # Restore registers
lw $a1, save1
mov $at, $k1 eret # Return to EPC
.kdata
save0: .word 0
save1: .word 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
