From: Ed Beroset
Subject: Re: Directly writing to memor
At 09:08 2/5/98, you wrote:
>
> EB> I think you'll find that the bottom of the stack (e.g. ss:0)
> EB> is indeed written to.
>
>Bottom of the stack is the very first element in the stack, yes? That is,
>ss:.
No. That's the top of the stack. If you think of the analogy of a
physical stack of papers, perhaps it will be clearer which is top and which
is bottom. The top of stack is where all the activity happens in both the
computer and the physical analog. SP always points to the top of the
stack, which contains the value most recently PUSHed.
> JB>>> it also menas SP can be initialised to 0 and the first
> JB>>> push will write to bytes FFFF & FFFE
> >>
> >> Are you really sure of that?
>
> EB> He's correct as far as real mode goes.
>
>Nevertheless, initializing SP=0 useful only if one has a 64K stack, which is
>not likely.
It's also true that initializing SP=3804h is only useful if one has a stack
size of 14340 bytes. Which scenario is more likely?
>Setting SP 2 bytes above is something I never thought of, and
>would work in all situations.. unless, of course, one is working with an XT,
>in which case SP is decremented after the write.
No, that's incorrect. It works on the 8086 and 8088 just fine. While the
handling of SP *internally* is such that "push sp" works differently on
these processors than on later ones, SP *always* points to the top of the
stack. If you have an 8086 or 8088 computer around, try this:
mov ax, 1234h
push ax
mov bp,sp ; need to do this because we can't use sp directly
mov bx,[bp]
After running this code, bx will contain 1234h. This code works just as
well on the 8086 and 8088 CPUs as it does on the PentiumPro. It works
because SP *always* points to the top of the stack which contains the value
most recently written, which is the same as saying that SP is always 2
bytes higher than the location at which the next PUSH will write.
>Of course, very little software is written anymore that will run on an XT,
but >if anyone does write some, if SP is initialized to +2 for a
286+, >be careful to do a CPU check in case you do run into an 86 or 88 :)
That's bad advice. No such check is necessary, since it works either way.
Ed
-!-
---
---------------
* Origin: The Circuit! Board * Spokane * (1:346/100)
|