Question: Write a complete program that uses the exception handler to generate multiple exceptions. The exception handler should report the address of the instruction that caused
Write a complete program that uses the exception handler to generate multiple exceptions. The exception handler should report the address of the instruction that caused the exception, the exception code, and should resume the program after handling each exception. Insert instructions that cause overflow, invalid memory addresses, trap and break instructions.
# Exception Handler starts here
ktext x
move $k $at # $k $at
la $kregs # $k address of regs
sw $k$k # save $at
sw $v$k # save $v
sw $a$k # save $a
la $amsg # $a address of msg
li $v # $v service
syscall # Print msg
mfc $a $ # $a EPC
li $v # $v service
syscall # print EPC in hexadecimal
la $amsg # $a address of msg
li $v # $v service
syscall # Print msg
mfc $a $ # $a cause
srl $a $a # shift right by bits
andi $a $a # $a exception code
li $v # $v service
syscall # Print exception code
la $amsg # $a address of msg
li $v # $v service
syscall # Print msg
la $kregs # $k address of regs
lw $at$k # restore $at
lw $v$k # restore $v
lw $a$k # restore $a
mtc $zero, $ # clear vaddr
mfc $k $ # $k EPC
addiu $k $k # Increment $k by
mtc $k $ # EPC point to next instruction
eret # exception return: PC EPC
# kernel data is stored here
kdata
msg: asciiz
Exception caused by instruction at address:
msg: asciiz
Exception Code
msg: asciiz
Ignore and continue program
regs: word : # Space for saved registers
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
