MIPS Leap: Problem with test faiure message

Hi all,

I started playing with the MIPS track. In the “Leap” practice I face a strange error message in the test runner:

failed for test input: 1. expected 0 to be 1818845542

My code looks like this:

.globl is_leap_year

is_leap_year:
        li    $v0, 0
        li    $s0, 400
        div   $a0, $s0
        mfhi  $t0
        slti  $v0, $t0, 1
        beq   $v0, 1, end 

        li    $v0, 0
        li    $s0, 100
        div   $a0, $s0
        mfhi  $t0
        beq   $t0, 0, divby100

        li    $v0, 0
        li    $s0, 4
        div   $a0, $s0
        mfhi  $t0
        slti  $v0, $t0, 1
        beq   $v0, 1, end

divby100:
        li    $v0, 0

end:
        jr    $ra

Is my code messing up the test code?
I tried checking the test code, but did not find a spot where the “1” as input comes in.

Any advice?

thx

flory

The registers $s0$s7 are callee-saved, meaning that if a function writes to them, it should first save the original value, e.g. on the stack, then freely use the register, then restore the original value before returning.

Your code is overwriting $s0 and leaving the test runner confused.

My suggestion would be to use $t1 instead of $s0.

1 Like

Hi keiraville,

thanks for your reply. Yes, using $t1 instead of $s0 fixed it.
Looks like there’s a lot to learn.
I wasn’t aware of that cerain registers have “limitations”.

Now the code passes and I can try to improve it.

thx again

flory