0

I am trying to display "Hello World" (from an example found on internet) in Mips and see how it works, but I end up with errors.I first had the following error :"spim: (parser) Label is defined for the second time on line 6 of file C:Program Files (x86) main: # Execution begins at label "main" " ^ To fix it, I reinitialized and reloaded. Then I run Qtspim and I end up with the following error: "Instruction references undefined symbol at 0x00400028/Notepad++/test.asm [0x00400028] 0x3c010000 lui $1, 0 [Greetings] ;8:la $a0, Greetings # load address of string to be printed into $a0

Can someone please explain what causes the first and second error? I am just trying to test the code that I found online and understand how Qtspim works before I try my assignment. I am using Notepad++ on Windows 08. Your help will be very appreciated. Bellow is the code.

# Program: Hello, World!
.data               # data declaration section; specifies values to be stored
                    # in memory and labels whereby the values are accessed
Greeting: .asciiz "\nHello, World!\n"
.text               # Start of code section
main:               # Execution begins at label "main"
li $v0, 4            # system call code for printing string = 4
la $a0, Greetings    # load address of string to be printed into $a0
syscall             # call operating system to perform operation;
                    # $v0 specifies the system function called;
                    # syscall takes $v0 (and opt arguments)

                    #This illustrates the basic structure of an assembly language program.
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
T4000
  • 231
  • 1
  • 7
  • 24
  • I don't know what is the first error, but the second means there's no label called *Greetings*. I understand you meant *Greeting*. – m0skit0 Feb 25 '13 at 09:18
  • Oups!!!! I did not see that one! I fixed it, but now, I have another error: "Attempt to execute non-instruction at 0x00400030". I know it is related to memory location. But I can't figure out why I have that new error. – T4000 Feb 25 '13 at 09:22
  • If you keep changing the question, we will never end. – m0skit0 Feb 25 '13 at 16:37
  • Possible duplicate of [Getting the error: "Instruction references undefined symbol ... main" in QTSpim](https://stackoverflow.com/questions/47099284/getting-the-error-instruction-references-undefined-symbol-main-in-qtspim). Oops, that's not right. There is no `.globl`, but the problem being asked about is different spellings of another label. It's actually just a typo bug. – Peter Cordes May 02 '18 at 04:16

1 Answers1

1

You labeled the string Greeting but referred to it as Greetings in your code, which cannot be recognized.

Also, it seems that you never return from your function (e.g. jr $ra or similar) after the syscallso the execution continues on undefined data.

MByD
  • 135,866
  • 28
  • 264
  • 277
  • I am not sure if I had to add my own lines of code, but here is where I found the code i am trying to test: http://courses.cs.vt.edu/~cs2505/summer2010/Notes/pdf/T21.IntroMIPSAssembly.pdf All I did was copy, paste and run it. – T4000 Feb 25 '13 at 09:26
  • You have to return from a function (or less likely perform a `syscall` to halt) – MByD Feb 25 '13 at 09:29
  • I added jr $ra after the syscall to check. No error this time, except the program does not display "Hello World". I had it displayed one time after re-runing Qtspim, then, the error "Attempt to execute non-instruction at 0x00400030" appeared again. – T4000 Feb 25 '13 at 09:47