Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Stack growth doesn't usually depend on the operating system itself, but on the processor it's running on. Solaris, for example, runs on x86 and SPARC. Mac OSX (as you mentioned) runs on PPC and x86. Linux runs on everything from my big honkin' System z at work to a <a href="http://web.archive.org/web/20090322124254/http://www.research.ibm.com/WearableComputing/linuxwatch/linuxwatch.html" rel="nofollow noreferrer">puny little wristwatch</a>.</p> <p>If the CPU provides any kind of choice, the ABI / calling convention used by the OS specifies which choice you need to make if you want your code to call everyone else's code.</p> <p>The processors and their direction are:</p> <ul> <li>x86: down.</li> <li>SPARC: selectable. The standard ABI uses down.</li> <li>PPC: down, I think.</li> <li>System z: in a linked list, I kid you not (but still down, at least for zLinux).</li> <li>ARM: selectable, but Thumb2 has compact encodings only for down (LDMIA = increment after, STMDB = decrement before).</li> <li>6502: down (but only 256 bytes).</li> <li>RCA 1802A: any way you want, subject to SCRT implementation.</li> <li>PDP11: down.</li> <li>8051: up.</li> </ul> <hr> <p>Showing my age on those last few, the 1802 was the chip used to control the early shuttles (sensing if the doors were open, I suspect, based on the processing power it had :-) and my second computer, the <a href="http://en.wikipedia.org/wiki/Comx-35" rel="nofollow noreferrer">COMX-35</a> (following my <a href="http://en.wikipedia.org/wiki/Zx80" rel="nofollow noreferrer">ZX80</a>).</p> <p>PDP11 details gleaned from <a href="http://en.wikipedia.org/wiki/PDP-11_architecture" rel="nofollow noreferrer">here</a>, 8051 details from <a href="http://what-when-how.com/8051-microcontroller/8051-register-banks-and-stack/" rel="nofollow noreferrer">here</a>.</p> <p>The SPARC architecture uses a sliding window register model. The architecturally visible details also include a circular buffer of register-windows that are valid and cached internally, with traps when that over/underflows. See <a href="http://icps.u-strasbg.fr/people/loechner/public_html/enseignement/SPARC/sparcstack.html" rel="nofollow noreferrer">here</a> for details. As <a href="http://www.gaisler.com/doc/sparcv8.pdf#page=53" rel="nofollow noreferrer">the SPARCv8 manual explains</a>, SAVE and RESTORE instructions are like ADD instructions plus register-window rotation. Using a positive constant instead of the usual negative would give an upward-growing stack.</p> <p>The afore-mentioned SCRT technique is another - the 1802 used some or it's sixteen 16-bit registers for SCRT (standard call and return technique). One was the program counter, you could use any register as the PC with the <code>SEP Rn</code> instruction. One was the stack pointer and two were set always to point to the SCRT code address, one for call, one for return. <em>No</em> register was treated in a special way. Keep in mind these details are from memory, they may not be totally correct.</p> <p>For example, if R3 was the PC, R4 was the SCRT call address, R5 was the SCRT return address and R2 was the "stack" (quotes as it's implemented in software), <code>SEP R4</code> would set R4 to be the PC and start running the SCRT call code.</p> <p>It would then store R3 on the R2 "stack" (I think R6 was used for temp storage), adjusting it up or down, grab the two bytes following R3, load them <em>into</em> R3, then do <code>SEP R3</code> and be running at the new address.</p> <p>To return, it would <code>SEP R5</code> which would pull the old address off the R2 stack, add two to it (to skip the address bytes of the call), load it into R3 and <code>SEP R3</code> to start running the previous code.</p> <p>Very hard to wrap your head around initially after all the 6502/6809/z80 stack-based code but still elegant in a bang-your-head-against-the-wall sort of way. Also one of the big selling features of the chip was a full suite of 16 16-bit registers, despite the fact you immediately lost 7 of those (5 for SCRT, two for DMA and interrupts from memory). Ahh, the triumph of marketing over reality :-)</p> <p>System z is actually quite similar, using its R14 and R15 registers for call/return.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload