简体   繁体   English

为什么我们在汇编中添加一个值来初始化堆栈指针(R7)?

[英]Why we add a value to initialize the stack pointer (R7) in assembly?

I'm currently new into assembly.我目前是组装的新手。 I know that we first need to allocate the dimension of the stack (in the example below is 1000).我知道我们首先需要分配栈的维度(在下面的例子中是1000)。 However I struggle to understand why we should add a value (in this case #999) to initialize the stack pointer.但是我很难理解为什么我们应该添加一个值(在本例中为 #999)来初始化堆栈指针。 Here's the pseudo-assembly:这是伪程序集:

STACK: .RES 1000

MOV #STACK, SP
ADD #999, SP 

To allocate space on the stack, the stack pointer is decremented (ie the stack grows down).为了在堆栈上分配空间,堆栈指针递减(即堆栈向下增长)。 Thus, in order to use the buffer STACK for the stack, the stack pointer has to initially point to the end of STACK so decrementing the stack pointer makes it point to new parts of STACK .因此,为了将缓冲区STACK用于堆栈,堆栈指针必须最初指向STACK的末尾,因此递减堆栈指针使其指向STACK新部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM