| |

VerySource

 Forgot password?
 Register
Search
View: 58|Reply: 23

Questions about the stack segment SS register.

[Copy link]

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

Post time: 2020-2-6 14:30:01
| Show all posts |Read mode
SS is called the stack segment register, which is used to store the base value of the stack segment. Does the stack segment base address refer to the bottom of the stack (high address) or the top of the stack (low address)?
Reply

Use magic Report

0

Threads

22

Posts

16

Credits

Newbie

Rank: 1

Credits
16

 China

Post time: 2020-3-29 17:45:01
| Show all posts
Generally point to high addresses, unless you want to implement some special functions
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-4-2 16:30:02
| Show all posts
In "Do-it-yourself Operating System", there is the following program:

% include "pm.inc"; constants, macros, and some descriptions

              ORG 0100H
              JMP LABEL_BEGIN

[SECTION .gdt]
; GDT
LABEL_GDT: Descriptor 0, 0, 0 LABEL_DESC_CODE32: Descriptor 0, SegCode32Len-1, DA_C + DA_32
LABEL_DESC_VIDEO: Descriptor 0B8000h, 0ffffh, DA_DRW
; GDT ends

      GDTLEN EQU $-LABEL_GDT; GDT length
      GDTPTR DW GDTLEN-1; GDT limit
              DD 0; GDT base address

; GDT selector
          SELECTORCODE32 EQU LABEL_DESC_CODE32-LABEL_GDT
           SELECTORVIDEO EQU LABEL_DESC_VIDEO-LABEL_GDT
; END of [SECTION .gdt]

[SECTION .s16]
[BITS 16]
            LABEL_BEGIN:
              MOV AX, CS
              MOV DS, AX
              MOV ES, AX
              MOV SS, AX
              MOV SP, 0100H

Program execution: MOV AX, CS, CS seems to be 0. Because CS is 0 after CPU initialization, the above program does not seem to modify CS. (Unless "ORG 0100H" can initialize CS to 0100H, otherwise it is 0), "MOV SS, AX" gives the value of CS to SS, it seems that SS is also zero, but in my impression SS seems to point to the bottom of the stack (High address), but it points to a low address. "MOV SP, 0100H" is no problem, but it seems that SS and SP point to 0100H at the bottom of the stack at the beginning of the program.

Please give pointers to masters one or two!
Reply

Use magic Report

0

Threads

22

Posts

16

Credits

Newbie

Rank: 1

Credits
16

 China

Post time: 2020-4-4 23:00:02
| Show all posts
SS? Where does it have high address or low address? High address or low address is for SP. SS, as a segment register, of course can only point to the beginning of the segment
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-4-8 00:15:01
| Show all posts
The stack is divided into the bottom of the stack and the top of the stack. After the SS is shifted to the left by four bits, the base address of the stack segment is the base address of the stack segment.
Reply

Use magic Report

0

Threads

22

Posts

16

Credits

Newbie

Rank: 1

Credits
16

 China

Post time: 2020-4-9 16:45:02
| Show all posts
This, you think it's confusing. The complete address is "segment address: offset" comprehensively implemented. Do you think the segment address may point to the bottom of the stack? If possible, by what offset to mark the top of the stack?
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-4-12 11:00:01
| Show all posts
My own feeling is that the entire stack segment is a stack, so the SS is located at one end of the stack, and can be accessed to any position of the stack through the SP offset. Although it is SS: SP common addressing, when SP is 0, it becomes SS individual addressing. It is difficult to find that when SP is 0, SS does not point to any position on the stack, but only points to the beginning of the stack segment. The beginning of is neither the bottom of the stack nor the top of the stack, so where is it?
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-7-16 19:15:01
| Show all posts
I think SS shifts to the left by four bits and points to the base address of the stack segment (the top of the stack). SP is initially the size of the stack segment, so that SS:SP is positioned to the bottom of the stack (the 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-17 11:00:01
| Show all posts
ss The stack segment points to the lower stack. In most cases it points to a high address, but in some cases it points to a low address, depending on the different architecture, in other words when the ss points to a high address, the stack decreases by sp, the stack increases by sp, and the ss points to low At address, increase sp on stack and decrease sp on stack

I am a beginner, please correct me
Reply

Use magic Report

2

Threads

18

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

 Author| Post time: 2020-7-21 23:45:02
| 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?
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