Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started