我正在尝试将5个字符串加载到数组中然后将其打印出来。出于某种原因,除了我之外,它每次尝试打印元素时都会给我错误。我认为这可能与我索引的方式有关,但是当它与互联网上的各种教程进行比较时,它似乎应该是正确的。我是MIPS的新手并且仍然掌握着它,所以如果它让我感到愚蠢的话我会很容易。非常感谢。
我的代码如下:
# Data Section
.data
Input: .asciiz "Enter a series of 5 formulae:\n"
Output: .asciiz "The values are:\n"
NL: .asciiz "\n"
myArray: .space 40
insert1: .space 4 # makes space in memory (8 bytes) for a word
with address insert1
insert2: .space 4
insert3: .space 4
insert4: .space 4
insert5: .space 4
# Text Section
.text
main:
la $a0, Input # Prints out Input
li $v0, 4 # sets $v0 to 4 (print code)
syscall
la $a0, insert1
la $a1, insert1
li $v0, 8
move $s0, $a0
syscall
la $a0, insert2
la $a1, insert2
li $v0, 8
move $s1, $a0
syscall
la $a0, insert3
la $a1, insert3
li $v0, 8
move $s2, $a0
syscall
la $a0, insert4
la $a1, insert4
li $v0, 8
move $s3, $a0
syscall
la $a0, insert5
la $a1, insert5
li $v0, 8
move $s4, $a0
syscall
# Index/Offset = $t0
li $t0, 0
sw $s0, myArray($t0)
addi $t0, $t0, 4
sw $s1, myArray($t0)
addi $t0, $t0, 4
sw $s2, myArray($t0)
addi $t0, $t0, 4
sw $s3, myArray($t0)
addi $t0, $t0, 4
sw $s4, myArray($t0)
# Clear $t0 to 0
li $t0, 0
while:
beq $t0, 20, quit
lw $t1, myArray($t0)
addi $t0, $t0, 4
#prints element
li $v0, 1
move $a0, $t1
syscall
#prints new line
li $v0, 4
la $a0, NL
syscall
j while
quit:
# Exits Program
li $v0, 10
syscall