invalid program counter value: 0

Krewie picture Krewie · May 13, 2010 · Viewed 25.8k times · Source

I'm currently working with assembly language under the MIPS processor. I'm currently using MARS simulator and for reasons unknown I get the following error message after every run:

Go: running try.s

Error in : invalid program counter value: 0

Go: execution terminated with errors.

I get this error message independent of the code I'm using, just wondering if this is a bug in the MARS simulator or if it's something I'm missing.

Answer

Fabian Giesen picture Fabian Giesen · Nov 14, 2010

You probably finish your program with a jr $ra (return to caller). However, the code executed by MARS doesn't have a caller - it's executed at startup and has no function to return to, so the contents of $ra are zero.

The correct way to end a program on MARS is using the "exit" syscall:

    li $v0, 10
    syscall