r/programming • • Mar 26 '20

10 Most(ly dead) Influential Programming Languages • Hillel Wayne

https://www.hillelwayne.com/post/influential-dead-languages/
409 Upvotes

178 comments sorted by

View all comments

Show parent comments

4

u/inkydye Mar 26 '20

Oh, stackless CPUs were totally a thing... and still are! They just don't have built-in stack ops for architectural reasons, but you can make your own in software, and their instruction sets tend to support doing this efficiently. (E.g. they can copy the instruction pointer to/from another register or an indexed memory address.)

This is done so consistently that they'll often recommend that specific general-purpose registers be "reserved" by convention for use as stack pointers.


On the other hand, as u/dnew mentioned, the 6502 does have a hardware stack, but it's really only useful for return addresses and (sorely needed) temporary stashing of register states. Its small size and limited operations you can do with it make it inconvenient for parameter passing or local variables.

But having a hardware stack doesn't stop you from implementing a different stack in software, like those stackless machines do. You see where this is heading? :)

Because, on the gripping hand, it's only natural and efficient for Forth to keep the data and return stacks separate anyway.


The 6502 gives special treatment to the first 256 bytes of memory ("the zero page") - they can be accessed with shorter and faster instructions, and they have some nifty indexed-addressing modes. This primarily lets that region be used as a sort of extended registers (including as 16-bit pointers with short offsets), but secondarily happens to work out really nice as a 16-bit data stack, while you let the CPU's hardware stack handle the return addresses that it's good with.

You could set up auxiliary 8-bit or 32-bit or floating-point software stacks anywhere in memory. What makes the zero page special is that it natively supports 16-bit pointers into the whole memory.

If you dedicate one specific index register (the X) to holding the top-of-stack index all the time, you get to use these two built-in, efficient addressing modes that literally translate to "data at top of stack" and "data in memory addressed by top-of-stack". (Also with no penalty at second-from-top, third-from-top etc.)

2

u/cdreid Mar 26 '20

When you think youre an expery in a specific area and two programmers come along and sit you down for a class :) This is one reason i love this sub tx man