Mars MIPS - adress is out of range

0

I am new to Mips & full disclosure this is regarding an assignment. The program so far has to create a 4x4 matrix from user input with integer from 1 to 16, 16 inputs in total & cannot have double integer. I have an error at line 78, "address out of range 0x00000000" & I do not understand why my adresse is out of range. I have allocated the array to the heap adresse, & I have a temporary array to check if I have integers in doubles. The Programm is being run on MARS.

.data

    prompt:
        .asciiz "Entrez les nombres 1 à 16 dans l'ordre que vous voulez."
    msg: 
        .asciiz "Le nombre entré n'est pas valide. Entrez une valeur de 1 à 16."
    msg2: 
        .asciiz "La donnée est déjè entrée! Entrez une autre valeur de 1 à 16."
    msg3: 
        .asciiz "je suis la"


.text
main:
    li $v0, 4                   # print welcome message
    la $a0, prompt 
    syscall
    
    la $a0, 0x10040000           # array base adresse
    addi $a1, $0, 4              # nbLignes
    addi $a2, $0, 4              # nbCols
     
    jal creerMat
    add $a0, $v0, $0             
    li   $v0,10                  #terminer le programme
    syscall


creerMat:
    # $s0 = x
    # $s1 = tab = = array base adresse
    # $s2 = temp
    # $s3 = i
    # $s4 = matrix size

    la $s1, 0x10040000          # tab = new int[]
    la $s2, 64($s1)             # temp = new int[], 64 because temp.length = 16
    addi $s3, $0, 0             # i = 0
    mul $t0, $a1, $a2  
    move $s4, $t0               # matrix size = lignes * colonnes

    read :                      # read input
        li $v0, 5 
        syscall
        move $s0, $v0           # x = input  
    
    
    while : beq $s4, $s3, return

        add $t0, $0, 0           # count = 0
        add $t1, $0, 0           # a = 0
        add $t2, $0, 17          # b = 0
        sle $t0, $s0, $t1        # (input < 0) ? count = 1 : count = 0
        sgt $t0, $s0, $t2        # (input > 17) ? count = 1 : count = 0
        bnez $t0, msgError       # if count == 1 print error msg

        sll $t0, $s0, 2          # input * 4
        add $t0, $t0, 64         # t0 = byte offset
        add $t0, $t0, $s1        # adress of temp[input]
        
        lw $t1, 0($t0)           # t1 = temp[input]
        addi $t0, $0, 1          # t0 = 1
        
        bne $t1, $t0, L1         # if (temp[input] == 1)
        j msgError2
        
        L1 : 
            addi $t0, $0, 1      # t0 = 1

            sll $t1, $s0, 2      # input * 4
            add $t1, $t1, 64     # t0 = byte offset
            add $t1, $t1, $s1    # adress of temp[input]
            lw $t2, 0($t1)       # t2 = temp[input] 
            sw $t0, 0($t2)       # temp[input] = 1

            sll $t3, $s1, 2      # t3 = i = i * 4
            add $t3, $t3, $s1    # adress de tab
            lw $t4, 0($t3)       # t4 = tab[i]
            sw $s0, 0($t3)       # tab[i] = input
            addi $s3, $s3, 1     # i = i + 1

    j while

    
    return :    li $v0, 4
                la $a0, msg3
                syscall          #store $ra on stack ?
    
    
#affiche message d'erreur   
msgError :
    li $v0, 4
    la $a0, msg
    syscall                       #store $ra on stack ?
    j read

msgError2 :
    li $v0, 4
    la $a0, msg2
    syscall                       #store $ra on stack ?
    j read

mips
asked on Stack Overflow Nov 27, 2020 by user12136904

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0