2016-11-26 14 views
0

私は6つの要素の配列を作成したいと思います。forループでは、ユーザーは毎回要素の値を入力し、forループで各要素を4つ追加して出力します。MIPSコード、実行がエラーで終了しましたか?

これは「Go:実行がエラーで終了しました」というコードです。

.text 

#Show the Hello Message :D 

li $v0 , 4  #4 because it is a string , 1 if it is integer message , V0 is function register 
la $a0 , Message #add the Hello message in the reserved assembler register a0 
syscall   #execute the V0 --->4 function with a0 parameter 

#for loop to take the values 
add $t0,$zero,$zero 

For : 
    slti $t1,$t0,24 
    beq $t1,$zero,Exit 

    #Display Prompt message 
    li $v0,4 
    la $a0, Prompt 
    syscall 

    #Get the iput 
    li $v0,5 #5 for int input 
    syscall 

    #Move the input from the the function to a register 

    move $t2,$v0 

    add $s0,$zero,$t2 
    #save value to the array 
    sw $s0,MyArray($t0) 

    addi $t0,$t0,4 

    j For 

Exit:  # End for loop 

    add $t0,$zero,$zero 

    addi $t4,$zero,4 
While: 
    beq $t0,24,Exit2 

    lw $t6, MyArray($t0) 

    addi $t0,$t0, 4 

    add $t6,$t6,$t4  
    add $t6,$t6,$t4 
    add $t6,$t6,$t4 
    add $t6,$t6,$t4 


    li $v0 , 1 
    move $a0 , $t6 
    syscall 


    li $v0 , 4 
    la $a0 , Space 
    syscall 

    j While 

Exit2: 


    li $v0 , 4  #4 because it is a string , 1 if it is integer message , V0 is function register 
    la $a0 , Message2 #add the End message in the reserved assembler register a0 
    syscall   



.data #This for all the data for the program like variables in c++ 

Message : .asciiz "Hello world !\n" #Display this message on the simulator 
MyArray : .space 24 
Prompt : .asciiz "Enter the value\n " 
Message2: .asciiz "End world !\n" 
Space : .asciiz " , " 

答えて

0

ここで達成しようとしていることはわかりません。あなたのコードは基本的に配列のすべての要素に16を加えます。

エラーは、メモリのアライメント不良が原因です。 MIPS32の4バイトのメモリからワードをロードするとき、アドレスは4で割り切れる必要があります。これをmipsのデータセクションで保証するには、配列を宣言する前に.align 4を追加する必要があります。

.data #This for all the data for the program like variables in c++ 
    Message : .asciiz "Hello world !\n" #Display this message on the simulator 
    .align 4 
    MyArray : .space 24 
    Prompt : .asciiz "Enter the value\n " 
    Message2: .asciiz "End world !\n" 
    Space : .asciiz " , " 
+0

ありがとうOldSurehand。 –