0
.text
.globl main

main:
        lw      $a0 4($a1)      # Put the filename pointer into $a0
        li      $a1 0           # Read Only
        li      $a2 0           # No Mode Specified
        li      $v0 13          # Open File
        syscall
        bltz    $v0 main_err    # Negative means open failed
        li      $v0, 10
        syscall

I have stripped out all code, and .data values that are not relevant to this question. When I run this code, I use the command "spim programName testFile". I continue to get the following error:

The following symbols are undefined:
main

Instruction references undefined symbol at 0x00400014
[0x00400014]    0x0c000000  jal 0x00000000 [main]           ; 188: jal main

I have no idea what could be going wrong.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
m.grewal
  • 23
  • 3
  • 1
    Do you have to rebuild the "programName" binary from source, or do you run `spim foo.s testFile` on the asm source? I haven't used SPIM, but I wonder if you're still re-running an old executable. According to the other hits for this error message, this `.globl main; main:` should work. – Peter Cordes Apr 18 '20 at 04:28
  • Hi, Peter! Thanks for the response. I'm new to QTSpim, so I realized I wasn't using the right commands. Now, I load, run and reinitialize if need be. (Also, I would like to mark this as resolved! Thank you for your response! :) – m.grewal Apr 18 '20 at 05:00
  • Mistakes like that tend to be hard for future readers to benefit from, so I'm voting to close this as "typo or equivalent". If someone's searching based on some problem that won't go away even when they change the source, it could be anything. (Although at least with this one, simply removing an offending line isn't an option unless you uncheck SPIM's user-space exception-handler stuff, so boiling it down to an [mcve] like you did can still leave doubt you've done it correctly.) If you want to take the time, feel free to post an answer describing exactly what you do in SPIM. – Peter Cordes Apr 18 '20 at 05:08
  • There's a similar question [here](https://stackoverflow.com/questions/31393822/why-is-qtspim-telling-me-label-is-defined-for-the-second-time/31394557) (same root cause, but different symptoms, so not a clear-cut duplicate). – Michael Apr 18 '20 at 12:57

0 Answers0