×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Debug and the stack - Newbi question.
2

Debug and the stack - Newbi question.

Debug and the stack - Newbi question.

(OP)
I'm writing some practice programs for 16 bit NASM and begin
my housekeeping as follows:

                  ...

     mov ax,initdata ;move segment address of initalized
     mov ds,ax       ;data through ax to ds.
     mov ax,stackseg ;move segment address of stack through
     mov ss,ax       ;ax to ss.
     mov sp,stackptr ;put the offset of the byte after the
                     ;reserved bytes into sp.
                   ...

This real mode, segmented model program assembles, links and
runs.

When I load my program into DEBUG and immediately look at
the status of the regesters I find that the stack segment
and the stack pointer have already been correctly loaded,
i.e., before a single instruction has been executed.  I've
varied the number of bytes reserved for the stack and it's
always correct, right there in sp.
AND, when I trace through the program my instruction
     mov sp,stackptr
is not there.  

What's going on here?

RE: Debug and the stack - Newbi question.

By any chance, did you get an STI (or is that a CLI... always confuse those two) instruction instead of mov sp,stackptr?  Or did it completely totally disappear when you unassemble using 'u'?  If so that would be a problem with NASM or your linker...

What processor directive did you use?  The 8086/8088 had a small chance to crash if you happen to interrupt it while it was changing the stack pointer.  Most modern assemblers get around this by first disabling, then re-enabling the interrupts.

sti
mov sp,stackptr
cli

Anyway, the phenomenon you saw wherein SS:SP was initialized before you even start the program is not really strange.  DOS initializes SS:SP for your program if you define a segment with STACK combine type.  This is because Link automatically combines all STACK segments into a single segment, then stores the total length and the offset of the segment in the file into a section of the MZ header labelled 'Initial SS:SP.'  In fact it is due to this that Link will warn you that you have no stack segment defined, if it can't find one it will load 0:0 in initial SS:SP and DOS will load that (adding the offset of your program in memory to the SS) before passing control to the program.

My suggestion is, just define your stack segment with a STACK combine type and let DOS worry about it.

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

RE: Debug and the stack - Newbi question.

Hi,
 The EXE file structure of DOS has fields reserved
for StackPointer. So, ur initial SP would already
be loaded by the EXE file loader. Moreover the loader
loads the Segment register with value of ur PSP.
(Program segment prefix ). hence the observation

Sarnath


Do not rejoice that ur code works.
it might be a special case of an error

RE: Debug and the stack - Newbi question.

(OP)
Thanks!

BagelBob

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close