3

MIPS でコーム ソートを作成する課題があります。ユーザーは配列とそのサイズを入力します。ヒープ割り当てを検索すると、システムコール 9 が見つかりました。ただし、使用方法が見つかりませんでした。私はこれを書きました:

    li $v0, 4
    la $a0, message1    # prints the first message 
    syscall
    
    li $v0, 5           # reads the size for the array        
    syscall
    
    mul $t0, $v0, 4     # because array contains integer, I change them into bytes
    la $a0, $t0         # allocate the size of the array in the heap
    li $v0, 9           # now, $v0 has the address of allocated memory
    syscall
    
    move $v1, $v0       # Because systemcall uses $vo register, I move it to $v1 keep it safe.
    
create_array:    
    la $a0, message2    # prints the first message
    li $v0, 4 
    syscall

    li   $s0, 0         # $s1 is the index, and loop induction variable
    li   $s1, 5         # $s1 is the sentinel value for the loop
        
Loop1:  
    bge  $s0, $s1, End_Loop1

    li $v0, 5           # Read integer values
    syscall
    
    mul  $t3, $s0, 4    # $t3 is the offset
    add  $t4, $t3, $t0  # $t4 is the address of desired index
    sw   $v0, ($t4)     # store the value in the array
    addi $s0, $s0, 1    # increment the index        
    j    Loop1

End_Loop1:

そして、私はこのエラーを受け取ります:

la": Too few or incorrectly formatted operands. Expected: la $t1,($t2)

どのように使用できますか?これは配列を作成する正しい方法ですか?

4

2 に答える 2

1

交換

la $a0, $t0     # allocate the size of the array in the heap

move $a0, $t0

命令のla目的は、シンボルの [A] アドレスをレジスタに [L] ロードすることです。例えば:

la $a0, message1    # prints the first message 

message1のアドレスを registerにロードします$a0la実際には疑似命令であり、この場合は次のように変換されます。

lui $a0, message1/0x10000       # load the upper halfword of the address
ori $a0, $a0, message1%0x10000  # OR in the lower halfword of the address

ご想像のとおり、レジスタにはアドレスがないため、別のレジスタのアドレスをロードしようとしても意味がありません。

MIPS 疑似命令:moveもその 1 つですが、上記のmove $a0, $t0命令は のようなものに変換されますadd $a0, $0, $t0

于 2013-03-28T21:57:36.790 に答える
0

また、 $t0$v1に置き換えます。$t0 はヒープに割り当てられた合計バイトを保持するだけですが、ヒープ内の配列の開始アドレスである $v1 が必要です。次のようになります。

add  $t4, $t3, $v1      # $t4 is the address of desired index
于 2019-03-04T18:46:48.703 に答える