Adam Tamargo
Adam Tamargo

Reputation: 77

Why am I getting a duplicate main label error? Also why is there no output?

I am working on my first project in mips, trying to print the sum of all the positive numbers in an array. I am now testing my code with QtSpim and have been getting an error saying I am using the main label twice even though there is only one occurrence. There is also no output, regardless of whether or not I include the main label. Here's the code:

.data
    A: .word -89, 19, 91, -23, -31, -96, 3, 67, 17, 13, -43, -74

.text   
main:   
    addi $s0, $zero, 0 #set $s0 for sum of positive nums to 0

    la $s1, A #set $s1 to array address
    addi $t0, $s1, 48 #set $t0 to exit point

while:
    beq $s1, $t0, end

    lw $t1, A($s1)
    slt $t2, $t1, $zero
    bne $t2, $zero, else #skips addition step if A at $s1 is negative

    add $s0, $s0, $t1

    else:
    addi $s1, $s1, 4
    j while

end:
    li $v0, 1
    move $a0, $s0
    syscall

    li $v0, 10
    syscall

Sorry if this is bad formatting for mips, I have only ever worked with Java and C++.

Upvotes: 0

Views: 423

Answers (2)

Lauren
Lauren

Reputation: 1

I had this same error and discovered that if I clicked "reinitialize and load" instead of just "load", it fixed the error.

Upvotes: 0

Satchin Campbell
Satchin Campbell

Reputation: 54

there's an error on this line

 lw $t1, A($s1)

What I believe you want is

 lw $t1, 0($s1)

A positive integer must be in the offset of the lw instruction.

The main label error seems like a rabbit hole as you see no label was used more than once.

Upvotes: 0

Related Questions