rovoto
rovoto

Reputation: 1

Mips error. Instruction references undefined symbol at 0x00400024 [0x00400024] 0x3c010000 lui $1, 0 [word] ; 8: la $t0, word

    #include <stdio.h>

int main() {
    int i,  min, min2 = 0;
  int arr[ 10 ] = {7,93,37,43,53,79,57,82,2,85};

    min = min2 = arr[ 0 ];

    for( i = 0; i < 10; i++ ) {
        if( min2 > arr[ i ] ) {
            if( min > arr[ i ] ) {           
                min2 = min;
                min = arr[ i ];
            }
            else {                            
                min2 = arr[ i ];
            }   
        }
        
    }

    printf( " %d", min2 );
  return 0;
}

This code is my C code.

    .data
    digit: .word 7, 93, 37, 43, 53, 79, 57, 82  
    str:.asciiz"Second smallest number is"  

.text

main:
    la $t0, word
    lw $s0, 0($t0) #Sets Min1 to first value in array
        move $s1, $s0  #Sets Min2 to first value in array
    addi $t1, $0, 0 #Sets the counter to 0
     li $t1, 0     #Index for the array
    addi $s2, $s2, 10
    
loop: 
     bge $t0, 9 EndLoop
     bgt $t1, $s1, Else 
     bgt $t1, $s0, Else2
     move $s2, $s1
     move $s1, $t1   
     addi $t1, $t1, 4 #Increases the index for the array
     addi $t0, $t0, 1 #Increments the counter

Else2:
     move $s2, $t1
     addi $t1, $t1, 4 #Increases the index for the array
     addi $t0, $t0, 1 #Increments the counter
     j loop

Else: 
     j loop

EndLoop:
     li $v0, 1
     la $a0, str
     syscall
     j EndLoop2

EndLoop2:
    li $v0, 1
    addi $a0, $s1, 0
    .end

This is my Mips code.

But when I run it, I get the error. I am new to QTSpim and assembly so I would appreciate some help if possible. Thank you!

Error code:Instruction references undefined symbol at 0x00400024 [0x00400024] 0x3c010000 lui $1, 0 [word] ; 8: la $t0, word

Upvotes: 0

Views: 637

Answers (1)

Erik Eidt
Erik Eidt

Reputation: 26646

word is an undefined label, but rather than complaining at assemble-time, it tags those instructions as bad with some error, and delivers that error at runtime instead if you try to execute such instructions.

This is not very friendly behavior on the part of QtSPIM.

And further, an actual processor would not be able to issue such an error at runtime, but rather would give you a null address or something else instead, and let your program crash trying to use that null address.

Upvotes: 1

Related Questions