I was wondering about the use of stack point in Mips. My professor has told us than when we want to "create" space for a word in MIPS that we are going to need for instance in a recursive function we do it by : addi $sp, $sp, -4
which generally makes sense.
But we have also , said that when we want to free - up this space we move the stack pointer back to it's initial address by addi $sp, $sp, 4
. When , we type this instuction what really happens to the this memory adress? Ok. I get it. The stack pointer , will no longer poitning out this value but 4 bytes , down ("deeper") in memory. But why does this means that , the space in memory is now free?
I hope I made , clear my question.
To make sure let, me give you an example:
li $a0, 6
addi $sp, $sp, -4
sw $a0, 0($sp) # let's suppose [a0] = 5 , now we loaded this value in memory adress 0($sp)
la $t1, 0($sp) # load the current adress of sp in t1
.....
.....
lw $a0, 0($sp) # why do we need this instruction?
addi $sp , $sp, 4
lw $t2, 0($t1) # i'm curious to see what's here
I tried, to print the result in $t2
, and it printed 6 , so we don't literally free - up memory?