I created a simple, recursive factorial() function which calls a recursive multiplication function called mul_alt() whenever it evaluates n * factorial(n-1). So instead of return n * factorial(n-1) (in C notation), the factorial() function executes return mul_alt(n, factorial(n-1)), where the called function would add n + n + ... factorial(n-1) times. I made this convoluted program since my class demands so.
The program works fine for n <= 9, but when I tried n > 9, the program would return an exception at n = 10 with the following values of the coprocessor 0:
$8 (vaddr) = 0x7fbffffc
$12 (status) = 0x0000ff13
$13 (cause) = 0x00000014
$14 (epc) = 0x0040008c
From the first two bits of the status register, I learned that the exception handler returned an ADDRL exception which means loading from an illegal address. And the epc register shows the address of the instruction which caused the error, which is
0x0040008c: sw $s1, 4($sp)
and the value of my $sp register is 0x7fbffff8. So 0x7fbffff8 + 0x4 = 0x7fbffffc (which is the value stored in vaddr) is where store instruction tried to store the contents of $s1. I have a few questions regarding this situation:
- Why did I get an
ADDRLexception though I actually used a store instruction -- not load? 0x7fbffffcis divisible by 4, so why am I not allowed to store word-sized data in there?
I hope I have stated my point clear. Thank you in advance.