0

私は短くなります。

ユーザーから15文字の文字列を取り込むMIPSでプログラムを作成しています。文字列をスタックに保存できません。2D マトリックス [20][15] を使用していることに注意してください。ここで、20 は文字列で、各文字列は 15 文字です。

私を案内してください。私は過去10時間にわたってこれを試してきました。

Loop:
bgt $t2,20,XYZ

li $v0,8        #take in input
la $a0, buffer  #load byte space into address
li $a1, 15      # allot the byte space for string
syscall

move $t3,$a0    #save string to t0


#transfering the data onto stack!

#num = $t2
#$base address of Matrix = $t1
#colums of Matrix = 15

mul $s0,$t2,15      #num * colums
li $s1,4            #String have 4 bit!
mul $s0,$s0,$s1 
add $s0,$s0,$t1     #$t1 is the base address!

#storing the data onto the stack!
sw $t3,0($s0)

add $t2,$t2,1
add $s0,$s0,-15 
j Loop
4

1 に答える 1

0

文字列自体ではなく、文字列のアドレスをスタックに保存しています

によって設定される t3:

la $a0, buffer  #load byte space into address
move $t3,$a0    #save string to t0

保管方法:

sw $t3,0($s0)

この次の命令は、15 バイトが書き込まれたことを前提としています。

add $s0,$s0,-15 

SW $t2,0($s0) で 4 バイトだけ書き込みました。T2に基づいてS0を再計算して上書きすると、これも次のループで破棄されます。add $s0,$s0,-15 を冗長にします。

次のような文字列コピールーチンが必要です

#A0=Dest, A1=Source
copy_string:
   lbu v0,(a1)    
   addiu a1,a1,#1   
   sb v0,(a0)
   addiu a0,a0,#1
   bnez v0, copy_string
于 2015-09-18T06:48:51.300 に答える