MIPS Dynamic Memory Allocation using sbrk

大兔子大兔子 提交于 2019-12-23 20:32:24

问题


I was trying to use sbrk for dynamic memory allocation. But, being a new comer to SPIM and MIPS, I was unable to do so. I sketched out a rough code for the same.

 .

data
    var: .word 25
.text   
    main:
        li $v0, 9
        la $v0, var
        lw $a0, var
        syscall                 # DYNAMICALLY ALLOCATING MEMORY OF SIZE 4 BYTES AT ADDRESS OF VAR
        sw $v0, var

        li $v0, 10
        syscall

回答1:


.data
    var: .word 25
.text   
    main:
        li $v0, 9
        lw $a0, var
        syscall                 # DYNAMICALLY ALLOCATING MEMORY OF SIZE 4 BYTES AT ADDRESS OF VAR
        sw $v0, var

        li $v0, 10
        syscall

Only the second statement needs to be omitted as the system is waiting to get a amount of byte that should be allocated but above I was trying to give the address of var but this is result. The sbrk service returns the address to a block of memory containing n additional bytes. This would be used for dynamic memory allocation.



来源:https://stackoverflow.com/questions/22588905/mips-dynamic-memory-allocation-using-sbrk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!