简体   繁体   English

MIPS中的数组字符串-循环问题

[英]Array strings in MIPS - an issue with a loop

I am writing a code to display an array containing a number of Strings. 我正在编写代码以显示包含多个字符串的数组。 Therefore I used a loop. 因此,我使用了一个循环。 However my counter doesn't work properly and I receive an error message and the first element (string) of an array. 但是,我的计数器无法正常工作,并且我收到错误消息和数组的第一个元素(字符串)。 Could anybody help me, please? 有人可以帮我吗?

'# $s0=count, $s1=total, $s3=data $s7=index

.data

Mssg1: .asciiz "Hello\\n" 消息1:.asciiz“您好\\ n”

Line1: .asciiz "aab\\n" 第1行:.asciiz“ aab \\ n”

Line2: .asciiz "ggdhj\\n" 第2行:.asciiz“ ggdhj \\ n”

Line3: .asciiz "uio\\n" 第3行:.asciiz“ uio \\ n”

array: .word Line1, Line2, Line3 数组:.word Line1,Line2,Line3

.globl main
.text

main: li $s1, 0 # total=0 li $s0, 3 # count=3 la $s7, array # index main:li $ s1,0#total = 0 li $ s0,3#count = 3 la $ s7,数组#索引

li $v0, 4       # print_str "Hello"
la $a0, Mssg1       
syscall

l1: lw $s3, 0($s7) # data=sum[index] l1:lw $ s3,0($ s7)#data = sum [index]

add $s1, $s1, $s3   # total=total+data

addi $s7, $s7, 4    # increment
addi $s0, $s0, -1   # decrement

bne $s0, $0, l1     # if not equal 0 go back onto the loop 


add $t0, $0, $s0    # t0=s0

li $v0, 4
move $a0, $t0
lw $a0, array       # print_str 
syscall'

$ t1的值不会在循环中更改,因此$ t7增加,您会得到不存在的数组索引:

lw $t2,0($t7)    # data=array[index]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM