jamarcus_13
jamarcus_13

Reputation: 55

MIPS Exception Printing NOT working

MIPS Exception Handler Code NOT working: In the following code I attempt to print out the addresses of the instruction that caused the exception (register $14) and the Type of exception (register $13). I have exhausted every possible route I could think of.

The error message gives:

"lw": Too few or incorrectly formatted operands. Expected: lw $t1,-100($t2)

Thank you!

  mfc0 $k0,$14 # Coprocessor 0 register $14 has address of trapping instruction

    lw $a0, $k0 # address of string to print

    li $v0, 4 # Print String service

    syscall

    mfc0 $k0,$13 # Coprocessor 0 register $13 has type of exception

    lw $a0, $k0 # address of string to print

    li $v0, 4 # Print String service

    syscall

Upvotes: 1

Views: 609

Answers (1)

Craig Estey
Craig Estey

Reputation: 33601

Instead of:

lw <regdst>,<regsrc>

Do:

move <regdst>,<regsrc>

move is a pseudo-op that will [most likely] generate:

addu <regdst>,<regsrc>,$zero

Or, it could also be done with:

addiu <regdst>,<regsrc>,0

Side note: I've written a full exception handler before, so be sure that the first instruction is [more or less]:

move $k0,$at

And, the epilog looks like:

move $at,$k0
eret

I also then establish a stack frame just like for a normal function [saving all other registers that get changed] and pop from it at the end

The reason I mention this, is that the exception handler must save every register it will change and restore the original value on exit if it's going to return to the base code (e.g. it might trap and fix an overflow exception).

This is also [especially] true for handling breakpoints.

Upvotes: 0

Related Questions