In article <5o************ *************** ***@giganews.co m>,
David T. Ashley <dt*@e3ft.comwr ote:
>The direction the stack grows is going to be architecture-dependent.
True.
>All
machines have a certain direction the stack pointer goes on a subroutine
call and instructions like PUSH, and typically a 'C' compiler will build
stack frames starting with this convention.
Not necessarily true. On some processors, the direction might just
be a matter of convention, and one OS might support different ABI
(Application Binary Interfaces) that use different conventions.
There are machines for which the "preferred" direction is controlled
by a CPU status register, alterable by the kernel.
Some machines do not have "PUSH" or "CALL" instructions with
built-in directions: they might instead just have "autoincrem ent"
and "autodecrem ent" addressing modes, and a PUSH might be
something like MOV.L 3248(R11), -(R7) where R7 as stack pointer
is just an ABI convention and where (R7)+ could be used by an ABI
instead to grow the stack in the other direction.
C compilers for such machines follow the OS ABI conventions, rather
than being forced into one direction or another according to some
hardware architecture limitation.
>The heap may also be OS-dependent. In the old days, a program had nearly
the whole machine memory to itself, and it would start the stack and heap at
opposite ends of free memory and maximize the time until they collided.
These days when OSs are more sophisticated and there is memory management
hardware in place, I doubt it is done this way.
It is still often done more or less that way, but these days you
have to worry about where the shared libraries or DLLs are going to
pop up in your address space, and have to worry about where any shared
memory segments will appear. On some systems, large heap allocations might
get turned into shared memory segment allocations (making it easy to
release the entire block back to the OS when the process free()'s it...
something that has been traditionally hard to do.)
--
Programming is what happens while you're busy making other plans.