Author Topic: about register SS:SP  (Read 1405 times)

n0noper

  • Regular Member
  • *
  • Posts: 5
about register SS:SP
« on: October 20, 2015, 01:20:47 AM »
...
stack segment
dw 8 dup (0)
stack ends
...
mov ax, stack
mov ss, ax
mov sp, 10
;----------------------
look the SS:0000
from SS:SP to SS:0000, the result not the 0, analyze and get that: some register saved.
Why and What? which register was saved??? why??

THANKS!!!!!!!!

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: about register SS:SP
« Reply #1 on: October 20, 2015, 02:35:16 AM »
if you are creating a 16-bit EXE, you don't have to set the stack segment and stack pointer
the initial SS:SP values are stored in the EXE header
the initial SS will point to the stack segment
and SP will point to the last word in that segment
if you have 512 bytes of stack space, SP will be 01FEh (512 - 2, in hex)

and, 8 words of stack space isn't enough   :P
i wouldn't even think of using less that 512 bytes stack space in 16-bit code
because it is a single-task, single-user operating system,
INT's and whatever else goes on in the background use the same stack

finally, to simplify your code, use the shortcuts

here's a template for small model 16-bit EXE's
Code: [Select]
        .MODEL  Small
        .STACK  4096
        .DOSSEG
        .386
        OPTION  CaseMap:None

;####################################################################################

        .DATA

s$Msg   db 'Hello World !',0Dh,0Ah,24h

;************************************************************************************

        .DATA?

;####################################################################################

        .CODE

;************************************************************************************

_main   PROC    FAR

        mov     dx,@data
        mov     ds,dx

        mov     dx,offset s$Msg
        mov     ah,9
        int     21h

        mov     ax,4C00h
        int     21h

_main   ENDP

;####################################################################################

        END     _main

n0noper

  • Regular Member
  • *
  • Posts: 5
Re: about register SS:SP
« Reply #2 on: October 21, 2015, 12:55:26 AM »
Thank you very much!!!
thanks for your help!   :t :t :t :t

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: about register SS:SP
« Reply #3 on: October 22, 2015, 04:45:31 PM »
INT's and whatever else goes on in the background use the same stack.

Doesn't DOS, by default, switch stacks to service hardware interrupts?
Well Microsoft, here’s another nice mess you’ve gotten us into.

FORTRANS

  • Member
  • ****
  • Posts: 945
Re: about register SS:SP
« Reply #4 on: October 23, 2015, 12:23:06 AM »
Hi,

   The "MS-DOS Programmer's Reference" says that the DOS handler
switches stacks for a large number of interrupts.  In an explanation
it says the list mentioned was to support hardware interrupts.
Later on, it says:  "Stack-switching handlers are enabled only if the
stacks command in the CONFIG.SYS file specifies eight or more
stacks."  IIRC, DOS maintains at least three internal stacks for its
own usage.

Regards,

Steve N.