创建数组 mips 时出错
我喜欢通过系统调用创建带有 mips 的数组,但出现错误 Error in D:\mips\create array line 20: Runtime exception at 0x00400028: request (1074003968)超出可用堆存储(系统调用 9)。
我的代码是:
.data
question1_msg: .asciiz "How much integer do you want to give?\n"
question2_msg: .asciiz "give a number?\n"
.text
question_numbers:
la $a0, question1_msg #load the question in $a0
li $v0, 4
syscall
answer_numbers:
li $v0, 5 #read the anwser of previous question
syscall
move $t0, $a0
generate_array:
sll $t0, $t0, 2 #create array
move $a0, $t0
li $v0, 9
syscall
move $t3, $v0 #put the stack pointer in a temperay register
add_numbers_array:
bge $t1, $t0, exit # if $t1 > $t0 then exit
#ask questions
la $a0, question2_msg #load the question in $a0
li $v0, 4
syscall
#read numbers
li $v0, 5
syscall
move $t2, $a0
#add number en go to the next array point
sw $t2, ($t3)
add $t3, $t3, 4
#get back to the begin of the loop
b add_numbers_array
exit :
li $v0 , 10 # let the code end
syscall
I like to make an array with mips by means of syscalls but i get the error Error in D:\mips\create array line 20: Runtime exception at 0x00400028: request (1074003968) exceeds available heap storage (syscall 9).
mine code is:
.data
question1_msg: .asciiz "How much integer do you want to give?\n"
question2_msg: .asciiz "give a number?\n"
.text
question_numbers:
la $a0, question1_msg #load the question in $a0
li $v0, 4
syscall
answer_numbers:
li $v0, 5 #read the anwser of previous question
syscall
move $t0, $a0
generate_array:
sll $t0, $t0, 2 #create array
move $a0, $t0
li $v0, 9
syscall
move $t3, $v0 #put the stack pointer in a temperay register
add_numbers_array:
bge $t1, $t0, exit # if $t1 > $t0 then exit
#ask questions
la $a0, question2_msg #load the question in $a0
li $v0, 4
syscall
#read numbers
li $v0, 5
syscall
move $t2, $a0
#add number en go to the next array point
sw $t2, ($t3)
add $t3, $t3, 4
#get back to the begin of the loop
b add_numbers_array
exit :
li $v0 , 10 # let the code end
syscall
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据此: http://www.doc.ic.ac .uk/lab/secondyear/spim/node8.html
syscall 5
返回的整数位于$v0
中,因此您将垃圾传递给下一个系统调用您尝试分配内存的地方。According to this: http://www.doc.ic.ac.uk/lab/secondyear/spim/node8.html the integer returned by
syscall 5
is in$v0
, so you are passing garbage to the next syscall where you try to allocate memory.