### A good answer might be:

No. Recall that a stack has a "last-in, first-out" organization. Unneeded memory is always returned from the top of the stack.

# SPIM Dynamic Memory

A stack is an easyly managed structure. Only a few memory addresses are needed to keep track of it. (Some of these addresses are in the stack pointer and in the frame pointer registers.) As a program executes the stack grows up and down and up and down as subroutines are called and exited. The heap is more like a book shelf. Books are constantly being taken off the shelf from various locations, leaving gaps, and then later returned, filling the gaps.

Here is how a SPIM program requests a block of memory from SPIM's heap:

    li      $a0,xxx   # $a0 contains the number of bytes you need.
                      # This must be a multiple of four.
    li      $v0,9     # code 9 == allocate memory
    syscall           # Invoke the trap handler.
                      # $v0 <-- the address of the first byte
                      # of the dynamically allocated block

You don't know in advance what range of addresses you will get back for the allocate memory request. The trap handler returns the first address of a contiguous block of ($a0) number of bytes. (This is similar to a call to `malloc()` in "C".)

### QUESTION 4:

In a full operating system, is there a service for deallocating memory, for returning a previously allocated block to the system?