函数调用自增SP的困境
Dilemma related to function call's increment of SP
In case of push during function call, why the stack pointer moves to a
smaller value by subtracting 4 times the number of registers to be
pushed on the stack?
我在阅读时得到了这个Understanding the stack
在同一页中,清楚地提到了堆栈的内存布局:-
It's useful to think of the following aspects of a stack.
stack bottom The largest valid address of a stack. When a stack is initialized, the stack pointer points to the stack bottom.
stack limit The smallest valid address of a stack. If the stack pointer gets smaller than this, then there's a stack overflow (this
should not be confused with overflow from math operations).
Other sections of memory are used for the program and for the heap
(the section of memory used for dynamic memory allocation).
而且,说到PUSH操作,需要减去4倍压入堆栈的寄存器数量,因为在MIPS架构中,顺序字的地址相差4 . 而且,对于 MIPS I 指令集架构 (ISA) 和 II ISA,寄存器是 32 位(4 字节)。
对于我们的 4 字节(全字)数据堆栈,添加一项意味着从 $sp
中减去四并将该项目存储在该地址中。
代码如下。假设要压入堆栈的值在寄存器 $t0
:
中
# PUSH the item in $t0:
subu $sp,$sp,4 # point to the place for the new item,
sw $t0,($sp) # store the contents of $t0 as the new top.
因此,您可以压入一个或多个寄存器,方法是将堆栈指针设置为较小的值(通常减去要压入堆栈的寄存器数量的 4 倍)并将寄存器复制到堆栈.
In case of push during function call, why the stack pointer moves to a smaller value by subtracting 4 times the number of registers to be pushed on the stack?
我在阅读时得到了这个Understanding the stack
在同一页中,清楚地提到了堆栈的内存布局:-
It's useful to think of the following aspects of a stack.
stack bottom The largest valid address of a stack. When a stack is initialized, the stack pointer points to the stack bottom.
stack limit The smallest valid address of a stack. If the stack pointer gets smaller than this, then there's a stack overflow (this should not be confused with overflow from math operations).
Other sections of memory are used for the program and for the heap (the section of memory used for dynamic memory allocation).
而且,说到PUSH操作,需要减去4倍压入堆栈的寄存器数量,因为在MIPS架构中,顺序字的地址相差4 . 而且,对于 MIPS I 指令集架构 (ISA) 和 II ISA,寄存器是 32 位(4 字节)。
对于我们的 4 字节(全字)数据堆栈,添加一项意味着从 $sp
中减去四并将该项目存储在该地址中。
代码如下。假设要压入堆栈的值在寄存器 $t0
:
# PUSH the item in $t0:
subu $sp,$sp,4 # point to the place for the new item,
sw $t0,($sp) # store the contents of $t0 as the new top.
因此,您可以压入一个或多个寄存器,方法是将堆栈指针设置为较小的值(通常减去要压入堆栈的寄存器数量的 4 倍)并将寄存器复制到堆栈.