2013-04-25 69 views
0

我應該爲這個問題做些什麼,我需要存儲這些值,並打印出矩陣,用戶要求輸入行數,列數和值元素,現在,我甚至不知道如果我沒有打印/存儲部分的權利,我想打印一個字符串,它是輸入,但它不工作MIPS如何存儲用戶輸入並將其打印出來

.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 
+2

你有任何調試器或模擬器來嘗試你的代碼嗎? – 2013-04-25 04:41:30

回答

2

單步執行代碼之後在SPIM中,行sw $v0, 0($t1)似乎是一個問題。而不是使用sw將輸入移動到寄存器$t0,我會建議使用move命令。在下面的代碼示例中,我修改了代碼,演示如何可以節省你的輸入接收的值到寄存器$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 

    ... 

有關如何使用每個MIPS指令,view this page更多信息。

相關問題