Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays MIPS将字符放入字符串中的位置就是删除字符串的堆地址_Arrays_Assembly_Heap_Mips_Indexoutofboundsexception - Fatal编程技术网

Arrays MIPS将字符放入字符串中的位置就是删除字符串的堆地址

Arrays MIPS将字符放入字符串中的位置就是删除字符串的堆地址,arrays,assembly,heap,mips,indexoutofboundsexception,Arrays,Assembly,Heap,Mips,Indexoutofboundsexception,所以基本上我必须插入字符数组中的字符来替换堆中存储的以空结尾的字。但是,当将字符放回时,它们会很好地添加到堆地址,但在循环的下一次迭代中检查时,前面的地址超出了边界。我不知道为什么会发生这种情况,非常感谢您的帮助 chars_to_word: # get characters from array and turn into word li $t0, 0 # counter for loop l

所以基本上我必须插入字符数组中的字符来替换堆中存储的以空结尾的字。但是,当将字符放回时,它们会很好地添加到堆地址,但在循环的下一次迭代中检查时,前面的地址超出了边界。我不知道为什么会发生这种情况,非常感谢您的帮助

chars_to_word:                      # get characters from array and turn into word
    li $t0, 0                       # counter for loop
    la $s4, ($s5)                   # go to start of char array
    sub $s3, $s3, $t9               # go to previous address of heap (due to earlier increment)  
ctw_loop:
    beq $s0, $t0, print_string      # branch when end of char array
    la $t1, ($s3)                   # $t1 = word[i]
    lb $t3, ($s4)                   # load char from array to put into string
    sb $t3, ($t1)                   # put char into heap at index
    addi $t0, $t0, 1
    addi $s3, $s3, 1
    add $s4, $s4, $t9
    j ctw_loop
print_string:
    sub $s3, $s3, $t9
    lw $a0, ($s3)
    li $v0, 4
    syscall
    j exit
为了澄清,$s4是字符数组的地址,$s5是字符数组的保留起始地址,$s3是字符串堆的位置,$t9是堆和数组的每个部分的公共大小

当尝试返回字符串堆的开始位置进行打印时,print_string中会出现错误,当我认为它应该正好位于插入字符的开始位置时,这是一个越界异常


提前谢谢,谢谢你的帮助

print_string
中,您正在执行
lw$a0,($s3)
,该操作从地址
$s3
加载单词(实际数据,即四个字符),并将其作为地址传递给字符串到
syscall
,显然失败了(在跳过
syscall
之前,您应该在调试器中看到,
a0
不包含字符串地址,但包含其他内容;字符串的四个字符不太可能形成类似于堆区域内存地址的值)


也许您确实希望
la$a0,($s3)
s3
复制到
a0
,但如果您不需要更新
s3
本身,您可以提前执行一条指令:
sub$a0,$s3,$t9#a0=字符串地址
,非常感谢!