| • Science | • People | • Locations | • Timeline |
The two main operations applicable to a stack are:
Some environments that rely heavily on stacks may provide additional operations, for example:
Stacks are either visualised growing from the bottom up (like real-world stacks, see image) or growing from left to right, so that "topmost" becomes "rightmost". This means that a right rotate will move the first element to the third position, the second to the first and the third to the second. Here are two equivalent visualisations of this process:
apple banana banana ==right rotate==> cucumber cucumber apple cucumber banana apple ==right rotate==> apple cucumber bananaA stack may be represented in computers inside block of memory cells, with the bottom at a fixed location, and a variable stack pointer to the current top cell. Pushing first increases the top pointer by one, pointing it to the next cell, and then fills that with the new top value. Popping first takes the top value, and then decreases the top pointer by one. Increasing and decreasing may be exchanged to yield a stack representation that grows from high addresses to lower ones.
Many CPUs have registers that can be used as stack pointers. Some, like the x86, have special instructions that implicitly use a register dedicated to the job of being a stack pointer. Others, like the PDP-11 and the 68000 family have addressing modes that make it possible to use any of a set of registers as a stack pointer. The 80x87 series of numeric coprocessors has a set of registers that can be accessed either as a stack, or as a series of numbered registers. Some microcontrollers, like the PIC and AVR, have a fixed-depth stack that is not directly accessible.
There are also a few processors which implement a stack directly in hardware. Examples include the MuP21 processor from Computer Cowboys, and the Harris RTX line.
In application programs written in a high level language, a stack can be implemented efficiently using either arrays or linked lists.
Calculators employing reverse Polish notation use a stack structure to hold values.
A number of computer languagesAn alternate rewrite has been has been. Please refer to it for large rewrites. A programming language or computer language is a standardized communication technique for expressing instructions to a computer. It is a set of syntactic and semantic rules use are stack-oriented, meaning they define most basic operations (adding two numbers, printing a character) as taking their arguments from the stack, and placing any return values back on the stack. For example, PostScriptPostScript (PS is a page description language used primarily in the electronic and desktop publishing areas. History The concepts of the PostScript language were seeded in 1976 when John Warnock was working at Evans and Sutherland, a famous computer graph has a return stack and an operand stack, and also has a graphics state stack and a dictionary stack.
The Forth programming languageForth is a programming language and programming environment. It was initially developed by Chuck Moore at the US National Radio Astronomy Observatory ( NRAO) during the 1960s, formalized as a programming language in 1977, and standardized by ANSI in 1994. uses two stacks, one for argument passing and one for subroutine return addresses. The use of a return stack is extremely commonplace, but the somewhat unusual use of an argument stack for a human-readable programming language is the reason Forth is referred to as a stack-based language.
Many virtual machineIn general terms, a virtual machine in computer science is software that creates an environment between the computer platform and the end user in which the end user can operate software. Specifically, the term virtual machine has several distinct meaningss are also stack-oriented: p-Code machineIn computer programming, a virtual machine executing p-code, the p-Code machine or pseudo-code machine was the target of early Pascal compilers. That is, the programming language Pascal was translated not to machine code understandable directly to a proce, Java virtual machineA Java virtual machine or JVM is a virtual machine that runs Java byte code. This code is most often generated by Java compilers, although the JVM has also been targeted by compilers of other languages. The (JVM) is a crucial component of the Java platfor.
Almost all computer environments use a stack to hold information about procedure/function nesting.