簡體   English   中英

MIPS中的數組字符串-循環問題

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

我正在編寫代碼以顯示包含多個字符串的數組。 因此,我使用了一個循環。 但是,我的計數器無法正常工作,並且我收到錯誤消息和數組的第一個元素(字符串)。 有人可以幫我嗎?

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

.data

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

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

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

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

數組:.word Line1,Line2,Line3

.globl main
.text

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]

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