pointers - Dilemma related to function call's increment of SP -
in case of push during function call, why stack pointer moves smaller value subtracting 4 times number of registers pushed on stack?
i got while reading understanding stack
in same page, mentioned memory layout of stack :-
it's useful think of following aspects of stack.
stack bottom largest valid address of stack. when stack initialized, stack pointer points stack bottom.
stack limit smallest valid address of stack. if stack pointer gets smaller this, there's stack overflow (this should not confused overflow math operations).
other sections of memory used program , heap (the section of memory used dynamic memory allocation).
and, talking push operation, subtracting 4 times number of registers pushed on stack needed because in mips architecture, addresses of sequential words differ 4. and, registers 32 bits(4 bytes) mips instruction set architecture (isa) , ii isa.
for our stack of 4-byte (full word) data, adding item means subtracting 4 $sp , storing item in address.
here looks in code. value push on stack in register $t0:
# push item in $t0: subu $sp,$sp,4 # point place new item, sw $t0,($sp) # store contents of $t0 new top. and, so, can push 1 or more registers, setting stack pointer smaller value (usually subtracting 4 times number of registers pushed on stack) , copying registers stack.
Comments
Post a Comment