简体   繁体   English

8086中的堆栈段和堆栈指针

[英]stack segment and stack pointer in 8086

I'm a little bit confused with stack segment (ss) and stack pointer (sp) registers . 我对堆栈段(ss)和堆栈指针(sp)寄存器有点困惑。 when the stack is empty, is the sp value equal to the ss value ? 当堆栈为空时,sp值是否等于ss值? I read that when we push a word (2bytes) to the stack the sp is decremented by 2, if the first statement is true (sp=ss) then i can say if the stack is not empty the stack pointer's value is always smaller or equal to the value of the stack segment is this true ??. 我读到当我们将一个字(2字节)推入堆栈时,sp递减2,如果第一个语句为真(sp = ss),那么我可以说如果堆栈不为空,则堆栈指针的值总是更小或者等于堆栈段的值是真的??。 what happens if we affect a value to sp so that it is bigger than ss ?? 如果我们影响sp的值,使它大于ss ??会发生什么? ie: mov ss,200h mov sp,400h mov ax,1010h push ax 即:mov ss,200h mov sp,400h mov ax,1010h push ax

please correct any mistakes, thanx in advance 请提前纠正任何错误

No, ss is a segment register like the others such as cs or ds . 不, ss是像其他的段寄存器,例如csds They take part in forming the physical address as per the usual real mode rules as address = 16 * segment + offset , where offset in case of the stack comes from sp . 它们参与按照通常的实模式规则形成物理地址,如address = 16 * segment + offset ,其中在堆栈的情况下偏移来自sp As such, last item pushed on the stack has address 16 * ss + sp . 因此,在堆栈上推送的最后一项具有地址16 * ss + sp You don't know when the stack is empty unless you have a priori knowledge of the end of the stack, and the numerical value of ss compared to sp has no significance at all. 除非您对堆栈结束有先验知识,否则您不知道堆栈何时为空,并且与sp相比较的ss的数值根本没有意义。

The stack segment (ss) register and the stack pointer (sp) register are used to create different parts of the address to the stack: 堆栈段(ss)寄存器和堆栈指针(sp)寄存器用于为堆栈创建地址的不同部分:

ss  aaaaaaaaaaaaaaaa----
sp  ----aaaaaaaaaaaaaaaa

The address used is ss * 16 + sp . 使用的地址是ss * 16 + sp The segment register selects a 64 kB segment of the whole 1024 kB memory space, and the stack pointer is an offset within that segment. 段寄存器选择整个1024 kB存储空间的64 kB段,堆栈指针是该段内的偏移量。

When the stack is empty, the stack pointer points to the top of the space allocated for the stack. 当堆栈为空时,堆栈指针指向为堆栈分配的空间的顶部。

If the ss register contains for example 0200h, then the stack segment goes from 02000h to 11fffh. 如果ss寄存器包含例如0200h,则堆栈段从02000h变为11fffh。 However, the actual stack may be smaller than the stack segment. 但是,实际堆栈可能小于堆栈段。 If the stack is for example 16 kB, then sp starts at 4000h and goes towards 0000h when the stack grows. 如果堆栈例如是16kB,那么sp从4000h开始并且在堆栈增长时朝向0000h。

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

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