| |

VerySource

 Forgot password?
 Register
Search
Author: qqion1988

Questions about the stack segment SS register.

[Copy link]

0

Threads

54

Posts

35

Credits

Newbie

Rank: 1

Credits
35

 China

Post time: 2020-7-22 13:30:01
| Show all posts
As far as I know, in real mode, SS:SP addresses the stack segment together. As a result, the addressing range is SS*16+0~SS*16+SP, and SS*16 is the base address of the stack segment. Assuming that the CPU is an 80X86 series, this CPU uses the high address of the stack segment as the bottom of the stack, that is to say, SS*16 should be the top (low address) of the stack. When the stack is empty, SP points to the bottom of the stack, that is SP should point to the end of the stack segment. I wonder if my reasoning is correct?

************************************************** *****************************
No, in the 80x86 series, SS*16D should be the high address, and SP only points to the offset within the segment. Only SS:SP can describe the bottom or top of the stack.
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-7-27 08:45:01
| Show all posts
First of all, SS*16D represents the base address of the stack segment, no doubt. If this base address is the high address of the stack segment, this high address is also the bottom of the stack (high address). In this way, SS*16D represents the bottom of the stack, and SP points to the top of the stack. When the stack is empty, the bottom of the stack = the top of the stack, and SP-> the top of the stack. At this time, it can only be 0 to ensure "top of the stack = bottom of the stack", that is, SS*16D=SS*16D+SP. What about SP if you push an element into the stack? Increase or decrease? Neither fit. If the SP increases, the stack will develop toward higher addresses; if SP decreases, there will be a problem. SP is already 0. Is it impossible to reduce it to a plural number? If SP is initialized to the stack size, SS:SP is positioned to the bottom of the stack, because SP is equal to the size of the stack during initialization, which is not 0. Obviously SS:SP is greater than SS:0000, then SS only points to the bottom of the stack at the lower address of the stack. Up.
Reply

Use magic Report

0

Threads

54

Posts

35

Credits

Newbie

Rank: 1

Credits
35

 China

Post time: 2020-7-27 10:00:01
| Show all posts
First of all, SS*16D represents the base address of the stack segment, no doubt. If this base address is the high address of the stack segment, this high address is also the bottom of the stack (high address). In this way, SS*16D represents the bottom of the stack, and SP points to the top of the stack. When the stack is empty, the bottom of the stack = the top of the stack, SP-> the top of the stack, at this time, it can only be 0 to ensure "top of the stack = bottom of the stack", that is, SS*16D=SS*16D+SP. What about SP if you push an element into the stack? Increase or decrease? Neither fit. If the SP increases, the stack will develop toward higher addresses; if SP decreases, there will be a problem. SP is already 0. Is it impossible to reduce it to a plural number? If SP is initialized to the stack size, SS:SP is positioned to the bottom of the stack, because SP is equal to the size of the stack during initialization, which is not 0. Obviously SS:SP is greater than SS:0000, then SS only points to the low address stack bottom of the stack segment Up.

************************************************** **************************

When initializing a stack, how can sp be 0? Think about the code below, and look at the picture

mov ax, stack
mov ss, ax
mov sp, 10h

After executing the above code, the result is like this

0x0000| |
0x0001| |
0x0002| |
0x0003| |
0x0004| |
0x0005| |
0x0006| |
0x0007| |
0x0008| |
0x0009| |
0x000A| |
0x000B| |
0x000C| |
0x000D| |
0x000E| |
0x000F|______|<-------- ss
0x0010 <-------- sp
Reply

Use magic Report

0

Threads

54

Posts

35

Credits

Newbie

Rank: 1

Credits
35

 China

Post time: 2020-7-27 11:00:01
| Show all posts
That is to say, sp is set according to the size of the stack
Reply

Use magic Report

0

Threads

54

Posts

35

Credits

Newbie

Rank: 1

Credits
35

 China

Post time: 2020-7-27 11:30:01
| Show all posts
The picture above is wrong

0x0000| |
0x0001| |
0x0002| |
0x0003| |
0x0004| |
0x0005| |
0x0006| |
0x0007| |
0x0008| |
0x0009| |
0x000A| |
0x000B| |
0x000C| |
0x000D| |
0x000E| |
0x000F|______|<-------- ss
0x0010 <-------- ss:sp (sp = 10h)
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-7-27 16:45:01
| Show all posts
0x000F|______|<-------- ss
0x0010 <-------- ss:sp (sp = 10h)
According to the second line above, the value of SS is 0.
According to the first line above, it is concluded that SS is not zero, so that the outer SS is wrong. After SS is shifted to the left by 4 bits, it should be a multiple of 16, but SS points to 0x000F.
Reply

Use magic Report

0

Threads

54

Posts

35

Credits

Newbie

Rank: 1

Credits
35

 United States

Post time: 2020-7-27 20:00:01
| Show all posts
0x00000| |
0x00010| |
0x00020| |
0x00030| |
0x00040| |
0x00050| |
0x00060| |
0x00070| |
0x00080| |
0x00090| |
0x000A0| |
0x000B0| |
0x000C0| |
0x000D0| |
0x000E0| |
0x000F0|______|<-------- ss = 0x000f
0x00100 <-------- ss:sp (sp = 0010h)

This time I'm counting
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-7-28 00:30:01
| Show all posts
>0x000F0|______|<-------- ss = 0x000f
>0x00100 <-------- ss:sp (sp = 0010h)

It seems that the range of the stack is: 0x000F0~0x00100, SS*16D represents the top of the stack (low address of the stack segment), SS*16D+SP addresses the entire stack space, during initialization, SP is equal to the size of the stack, and SS:SP points to the top of the stack ( High address of the stack segment).
Reply

Use magic Report

0

Threads

54

Posts

35

Credits

Newbie

Rank: 1

Credits
35

 China

Post time: 2020-7-28 07:15:01
| Show all posts
SS*16D represents the top of the stack (low address of the stack segment),

Should be the high address of the stack

The range of the stack is 0x000f:0000-0x000f:0010 20-bit physical address is equal to 0x000F0 + 0x0010 = 0x00100
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-7-28 11:45:01
| Show all posts
>0x00100 <-------- ss:sp (sp = 0010h)

SP is initialized to the size of the stack: 0010h, and the size of the stack should be the range of the stack.

>The range of the stack is 0x000f:0000 ~ 0x000f:0010, the 20-bit physical address is equal to 0x000F0 + 0x0010 = 0x0100

The above range should be: 0x000f:0000-0x000f:0010 calculated as 20-bit physical address 0x000F0+0000~0x000F0 + 0x0010, that is: 0x000F0~ 0x00100, the stack size is 0x00100-0x000F0 =0x0010.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list