Stack segment and stack pointer in 8086

I am a little confused with the stack (ss) and stack (sp) registers. when the stack is empty, is sp equal to ss? I read that when we push a word (2 bytes) onto the stack, sp is decremented by 2, if the first statement is true (sp = ss), then I can say that if the stack is not empty, the value of the stack pointer is always less than or equal to the value of the segment stack, this is true. what happens if we change the sp value to be greater than ss? that is: mov ss, 200h mov sp, 400h mov ax, 1010h push ax

please correct any mistakes thanx in advance

+3


source to share


2 answers


No, ss

- segment register like others like cs

or ds

. They take part in the formation of the physical address according to the usual real mode rules like address = 16 * segment + offset

where the offset in the case of the stack comes from sp

. So the last item pushed onto the stack has an address 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 is irrelevant ss

compared to sp

.



+4


source


The stack segment register (ss) and the stack pointer register (sp) are used to create different parts of the address on the stack:

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

      

The address to use ss * 16 + sp

. The segment register selects a 64KB segment of the total 1024KB memory space, and the stack pointer is the offset within that segment.



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. 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 to 0000h as the stack grows.

+2


source







All Articles