mips中的数组和计数器
我很难让这个数组正常工作,假设从输入中读取10个字符,并在读取后立即打印它们,然后向后打印数组。任何帮助都将不胜感激。一个错误很明显:mips中的数组和计数器,mips,Mips,我很难让这个数组正常工作,假设从输入中读取10个字符,并在读取后立即打印它们,然后向后打印数组。任何帮助都将不胜感激。一个错误很明显: 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
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
格式不正确。MIPS不允许将寄存器用作偏移量。MIPS也不允许移动操作的目标寄存器上有偏移量
代码应替换为以下内容:
move $t8($t9), $v0
移动操作是一条伪指令,它接受一个寄存器并将其中包含的值放入另一个目标寄存器。相反,使用store word(sw)指令将寄存器的内容存储在提供的内存位置。您必须更改其余代码才能使用上面的代码,但这应该足以让您朝着正确的方向开始。感谢您的回复,我将重做代码,看看会发生什么。
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