Invalid program counter value: 0

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

Go: running try.s

Error: Invalid program counter value: 0

Go: execution ended with errors.

I am getting this error regardless of the code I am using, just wondering if this is a bug in the MARS simulator or if this is something I am missing.

+2


a source to share


3 answers


You probably ended your program with jr $ra

(return to the calling program). However, the code executed by MARS does not have a caller — it is executed at startup and has no function to return, so the content $ra

is zero.

The correct way to terminate a MARS program is to use the exit syscall:



    li $v0, 10
    syscall

      

+5


a source


I am new to MIPS and I had this problem. This is what I had:

    .data

    .text

swap:
    # do stuff
    jr  $ra

main:
    # do stuff
    jal swap
    li  $v0,10
    syscall

      

I fixed it by changing it to this:



    .data

    .text
main:
    # do stuff
    jal swap
    li  $v0,10
    syscall

swap:
    # do stuff
    jr  $ra

      

Please note that I went to the main page to be up to the exchange. I mistakenly assumed that the primary is the reserved shortcut. And that it will automatically jump straight to the main point automatically. But apparently it doesn't, because it hit the jr $ ra command before I had to call jal swap mostly.

Anyway, I hope this helps.

+5


a source


I know this question is old, but for anyone who was like me and desperately trying to find an answer: try the above syscall task instead of returning and try putting your main function in front of all other shortcuts. In addition, in the "Settings" menu there is "Initialize program counter to global", "if defined"; make sure this box is checked. I don't know if this would allow you to include your main label after the other shortcuts as I haven't tried it yet. What I described is what I did to get it to work and nothing else. Good luck!

+3


a source







All Articles