创建数组 mips 时出错

发布于 2024-11-27 08:37:54 字数 1103 浏览 2 评论 0原文

我喜欢通过系统调用创建带有 mips 的数组,但出现错误 Error in D:\mips\create array line 20: Ru​​ntime 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-12-04 08:37:54

据此: 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文