2012-05-17 54 views
0
CASE2: 
    la $t9, ARRAY  # Load base address of array into $t9 
    li $t8, 36  # Initialize loop counter to 36 

LOOP: 
    la $a0, Prompt2  # Load Prompt2 string into $a0. 
    li $v0, 4  # system call to print string Prompt2. 
    syscall 

    li $v0, 12  # read character input. 
    syscall 
    move $t8($t9), $v0 # move input character to an array element. 

    la $a0, $t8($t9) # load array element into $a0. 
    li $v0, 11  # system call to print array element. 
    syscall 
    addi $t8, $t8, -4 # decrement loop counter. 
    bgtz $t8, LOOP 

    la $a0, MSG2  # load MSG2 string into $a0. 
    li $v0, 4  # system call to print MSG2 string. 
    syscall 
LOOP2: 
    la $a0, $t8($t9) # load element of array into $a0. 
    li $v0, 11  # system call to print char. 
    addi $t8, $t8, 4 # increment $t8. 
    blt $t8, 36, LOOP2 # branch if $t8 is less than 36 
    j EXIT   # when $t8 reaches 36 jump to EXIT. 
    .data 
Prompt2:.asciiz "\nEnter a character: " 
ARRAY: .space 10  # 10 bytes of storage to hold an array of 10 characters 

我無法得到這個陣列的工作,想讀取來自輸入10個字符,並閱讀他們後立即打印出來,之後向後打印出數組。任何幫助,將不勝感激。陣列和櫃檯MIPS

回答

2

一個錯誤是顯而易見的:

move $t8($t9), $v0 

是不正確的格式。 MIPS不允許使用寄存器作爲偏移量。 MIPS也不允許在移動操作的目標寄存器上進行偏移。

代碼應該由類似取代:

addi $t8, $0, 36 # initialize the offset counter to 36 
... 
sll $t8, $t8, 2 # multiply the offset counter by 4 to account for word indexing 
add $t9, $t8, $t9 # add the current offset to $t9 
sw $v0, 0($t9) # store $v0 at the memory location held in $t9 

移動操作是一個僞指令,它有一個寄存器並把其中所包含的值到另一個目標寄存器。相反,使用存儲字(sw)指令將寄存器的內容存儲在提供的存儲單元中。您將不得不更改代碼的其餘部分以使用上面的代碼,但它應該足以讓您朝着正確的方向開始。

+0

感謝您的答覆,我會重做代碼,看看會發生什麼。 – dave5678