1
votes

what i should do for the problem is, i need to store those value, and print out a matrix, user is asking to input the number of rows, columns, and the value of elements , right now i don't even know if i did the print/store part right, i tried to print a single string which is input, but it doesn't work

    .text
    .globl main

main:
addi $v0, $0, 4   
la   $a0, str1 
syscall             #printing str1 
addi $v0, $0, 5   
syscall 
la $t1, M1_1
sw $v0, 0($t1)      #reading and storing the number of rows 

addi $v0, $0, 4   
la   $a0, str2 
syscall             #printing str2 
addi $v0, $0, 5   
syscall 
la $t2, M1_2
sw $v0, 0($t2)      #reading and storing the number of columns   

addi $v0, $0, 4   
la   $a0, str3 
syscall             #printing str3 
addi $v0, $0, 5   
syscall 
la $t3, M1_3
sw $v0, 0($t3)      #reading and storing the value of element   


    .data


str1:.asciiz "\“Please enter the number of rows in the matrix\n"
str2:.asciiz "\“Please enter the number of columns\n"
str3:.asciiz "\“Please enter the elements of the matrix\n"
.align 2
M1:.space 256 
M1_1:.space 4
M1_2:.space 4
M1_3:.space 4
M2:.space 256 
M2_2:.space 4
1
Have you got any debugger or emulator to try your code out?Alexey Frunze

1 Answers

2
votes

After stepping through your code in SPIM, the line sw $v0, 0($t1) seems to be an issue. Rather than using sw to move the input into register $t0, I would recommend using the move command. In the code sample below, I modified your code to demonstrate how you can save the value you received as input into the register $t0:

    .text
    .globl main

main:
    sub         $sp , $sp , 4           # push stack
    sw          $ra , 0 ( $sp )     # save return address

    addi        $v0 , $0 , 4   
    la          $a0 , str1 
    syscall     #printing str1

    addi        $v0 , $0 , 5   
    syscall     #get input

    move        $t0 , $v0               # save input in $t0
    move        $a0 , $v0
    addi        $v0 , $0 , 1
    syscall     #print first input

    ...

For more information on how to use each MIPS instruction, view this page.