Stack register

A stack register is a computer central processor register whose purpose is to keep track of a call stack. On an accumulator-based architecture machine, this may be a dedicated register. On a machine with multiple general-purpose registers, it may be a register that is reserved by convention, such as on the IBM System/360 through z/Architecture architecture and RISC architectures, or it may be a register that procedure call and return instructions are hardwired to use, such as on the PDP-11, VAX, and Intel x86 architectures. Some designs such as the Data General Eclipse had no dedicated register, but used a reserved hardware memory address for this function.

Machines before the late 1960s—such as the PDP-8 and HP 2100—did not have compilers which supported recursion. Their subroutine instructions typically would save the current location in the jump address, and then set the program counter to the next address.[1] While this is simpler than maintaining a stack, since there is only one return location per subroutine code section, there cannot be recursion without considerable effort on the part of the programmer.

A stack machine has 2 or more stack registers — one of them keeps track of a call stack, the other(s) keep track of other stack(s).

Stack registers in x86

In 8086, the main stack register is called "stack pointer" (SP). The stack segment register (SS) is usually used to store information about the memory segment that stores the call stack of currently executed program. SP points to current stack top. By default, the stack grows downward in memory, so newer values are placed at lower memory addresses. To save a value to the stack, the PUSH instruction is used. To retrieve a value from the stack, the POP instruction is used.

Example: Assuming that SS = 1000h and SP = 0xF820. This means that current stack top is the physical address 0x1F820 (this is due to memory segmentation in 8086). The next two machine instructions of the program are:

PUSH AX
PUSH BX
  • These first instruction shall push the value stored in AX (16-bit register) to the stack. This is done by subtracting a value of 2 (2 bytes) from SP.
  • The new value of SP becomes 0xF81E. The CPU then copies the value of AX to the memory word whose physical address is 0x1F81E.
  • When "PUSH BX" is executed, SP is set to 0xF81C and BX is copied to 0x1F81C.[2]

This illustrates how PUSH works. Usually, the running program pushes registers to the stack to make use of the registers for other purposes, like to call a routine that may change the current values of registers. To restore the values stored at the stack, the program shall contain machine instructions like this:

POP BX
POP AX
  • POP BX copies the word at 0x1F81C (which is the old value of BX) to BX, then increases SP by 2. SP now is 0xF81E.
  • POP AX copies the word at 0x1F81E to AX, then sets SP to 0xF820.[nb 1][nb 2]

Stack engine

Simpler processors store the stack pointer in a regular hardware register and use the arithmetic logic unit (ALU) to manipulate its value. Typically push and pop are translated into multiple micro-ops, to separately add/subtract the stack pointer, and perform the load/store in memory.[3]

Newer processors contain a dedicated stack engine to optimize stack operations. Pentium M was the first x86 processor to introduce a stack engine. In its implementation, the stack pointer is split among two registers: ESPO, which is a 32-bit register, and ESPd, an 8-bit delta value that is updated directly by stack operations. PUSH, POP, CALL and RET opcodes operate directly with the ESPd register. If ESPd is near overflow or the ESP register is referenced from other instructions (when ESPd ≠ 0), a synchronisation micro-op is inserted that updates the ESPO using the ALU and resets ESPd to 0. This design has remained largely unmodified in later Intel processors, although ESPO has been expanded to 64 bits.[4]

A stack engine similar to Intel's was also adopted in the AMD K8 microarchitecture. In Bulldozer, the need for synchronization micro-ops was removed, but the internal design of the stack engine is not known.[4]

Notes

  1. ^ The program above pops BX first because it was pushed last.
  2. ^ In 8086, PUSH & POP instructions can only work with 16-bit elements.

References

  1. ^ Salomon, David (February 1993) [1992]. Written at California State University, Northridge, California, USA. Chivers, Ian D. (ed.). Assemblers and Loaders (PDF). Ellis Horwood Series In Computers And Their Applications (1 ed.). Chicester, West Sussex, UK: Ellis Horwood Limited / Simon & Schuster International Group. ISBN 0-13-052564-2. Archived (PDF) from the original on 2020-03-23. Retrieved 2008-10-01. Most computers save the return address in either the stack, in one of the registers, or in the first word of the procedure (in which case the first executable instruction of the procedure should be stored in the second word). If the latter method is used, a return from the procedure is a jump to the memory location whose address is contained in the first word of the procedure. (xiv+294+4 pages)
  2. ^ Howard, Brian. "Assembly Tutorial - Instructions". Computer Science Department, DePauw University. Retrieved 2013-07-19.
  3. ^ Stokes, Jon "Hannibal" (2004-02-25). "A Look at Centrino's Core: The Pentium M". archive.arstechnica.com. p. 5.
  4. ^ a b Fog, Agner. "The microarchitecture of Intel, AMD and VIA CPUs" (PDF). Technical University of Denmark.

Read other articles:

Part of a series onFreemasonry Overview Grand Lodge Masonic lodge Masonic lodge officers Grand Master Prince Hall Freemasonry Regular Masonic jurisdiction Anglo-American Freemasonry Continental Freemasonry History History of Freemasonry Liberté chérie Masonic manuscripts Masonic bodies Masonic Masonic bodies York Rite Order of Mark Master Masons Holy Royal Arch Royal Arch Masonry Cryptic Masonry Knights Templar Red Cross of Constantine Scottish Rite Knight Kadosh Societas Rosicruciana Order...

United States historic placeSpace Environment Simulation LaboratoryU.S. National Register of Historic PlacesU.S. National Historic Landmark The 2TV-1 Apollo spacecraft in Chamber A 1968Show map of TexasShow map of the United StatesLocationLyndon B. Johnson Space Center, Houston, TexasCoordinates29°33′38″N 95°5′17″W / 29.56056°N 95.08806°W / 29.56056; -95.08806Arealess than one acreBuilt1965 (1965)NRHP reference No.85002810Significant datesAdd...

Cet article est une ébauche concernant les Forces armées canadiennes. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Pour les articles homonymes, voir Esquimalt (homonymie). BFC Esquimalt Navires amarrés aux quais de la BFC Esquimalt en 2005 Pays Canada Période 1860 – Toujours active Type Base des Forces canadiennes Rôle Base navale Allégeance Forces canadiennes Branche Marine royale canadienne Fait part...

2011 video game For the game engine, see Rockstar Advanced Game Engine. 2011 video gameRageDeveloper(s)id Software[a]Publisher(s)Bethesda SoftworksDirector(s)Tim WillitsProducer(s)Hunter HynemanJason KimMatthew NelsonProgrammer(s)Robert DuffyJan Paul van WaverenWriter(s)Matthew J. CostelloComposer(s)Rod AbernethyEngineid Tech 5Platform(s)Microsoft WindowsPlayStation 3Xbox 360OS XReleaseWindows, PlayStation 3, Xbox 360NA: October 4, 2011AU: October 6, 2011EU: October 7, 2011OS XWW: Feb...

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Kukka Katuku Cheppu Debba – news · newspapers · books · scholar · JSTOR (September 2022) (Learn how and when to remove this template message) 1979 Indian filmKukka Katuku Cheppu DebbaTheatrical posterDirected byEranki SharmaWritten byC. PurushothamProduced byCh...

Bulbophyllum fletcherianum Klasifikasi ilmiah Kerajaan: Plantae (tanpa takson): Angiospermae (tanpa takson): Monocots Ordo: Asparagales Famili: Orchidaceae Genus: Bulbophyllum Spesies: Bulbophyllum fletcherianum Nama binomial Bulbophyllum fletcherianumRolfe 1911 Bulbophyllum fletcherianum adalah spesies tumbuhan yang tergolong ke dalam famili Orchidaceae. Spesies ini juga merupakan bagian dari ordo Asparagales. Spesies Bulbophyllum fletcherianum sendiri merupakan bagian dari genus Bulbophyllu...

بطولة العالم للشطرنج 1929معلومات عامةالرياضة شطرنج البطولة بطولة العالم للشطرنج النسخة 13 الفترة 1929 البداية 12 نوفمبر 1929 المكان فيسبادن عدد الجولات 25 الموسمالبطل ألكسندر أليخين المواسمبطولة العالم للشطرنج 1927 بطولة العالم للشطرنج 1934 تعديل - تعديل مصدري - تعديل ويكي بيانات أل�...

For other uses, see Scroll (disambiguation). Roll of papyrus, parchment, or paper containing writing The Joshua Roll, Vatican Library. An illuminated scroll, probably of the 10th century, created in the Byzantine empire. Scroll of the Book of Esther, Seville, Spain Ingredients used in making ink for Hebrew scrolls today A scroll (from the Old French escroe or escroue), also known as a roll, is a roll of papyrus, parchment, or paper containing writing.[1] Structure Volumen and Rotulus,...

Authoritarian environmentalist ideology This article is about Ecofascism. It is not to be confused with Eco-nationalism, a synthesis of nationalism and green politics praticised by a spectrum of groups including Indigenous peoples. You can help expand this article with text translated from the corresponding article in French and German. (June 2023) Click [show] for important translation instructions. View a machine-translated version of the French article. Machine translation, like DeepL...

Questa voce sugli argomenti circondari della Germania e Assia è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Circondario di Limburg-WeilburgcircondarioLandkreis Limburg-Weilburg LocalizzazioneStato Germania Land Assia DistrettoGießen AmministrazioneCapoluogoLimburg an der Lahn GovernatoreManfred Michel (CDU) TerritorioCoordinatedel capoluogo50°23′N 8°04′E / 50.383333°N 8.066667°E50.383333; 8.066667 (Circondario...

Football clubBoca JuniorsFull nameClub Atlético Boca JuniorsNickname(s)Xeneizes (Genoese), Azul y Oro (Blue and Gold), La Mitad Más Uno (Half plus One)Founded1910; 113 years ago (1910) (Reserve teams)GroundCentro de Entrenamiento Boca Juniors, EzeizaCapacity1,000ChairmanJorge Amor AmealManagerSilvio Rudman[1]WebsiteClub website Home colours Away colours Third colours Boca Juniors Reserves and Academy are the reserve and youth academy teams of Boca Juniors. Boca Jun...

Spanish doctor Juan José López-Ibor Aliño (Madrid, 17 December 1941 - Madrid, 12 January 2015) was a Spanish psychiatrist. Son of Juan José López-Ibor, he graduated in Medicine from the Complutense University of Madrid in 1965 and obtained his doctorate at the same university four years later. He became in 1992 Professor of Psychiatry at the Complutense University of Madrid.[1] He directed Actas Españolas de Psiquiatría for several years. He was Secretary General of the World P...

Italian Cardinal Giulio Roma Giulio Roma (16 September 1584 – 16 September 1652) was an Italian Catholic Cardinal and Bishop of Recanati and Loreto. Roma was born 16 September 1584 in Milan, one of 16 children born to noble parents. He was educated at the University of Pavia and the University of Perugia. At a young age he became a chamberlain to Cardinal Federico Borromeo, Archbishop of Milan. Thereafter he went to Rome and had an audience with Pope Paul V, who asked him to move to Rom...

У этого термина существуют и другие значения, см. Кульминация. PS — повышенный полюс (в данном случае — южный), линия NS — горизонт наблюдателя, ZZ' — отвесная линия, QQ' — экватор. Линия AA' — суточная параллель светила. Угол φ — широта местоположения наблюд�...

Specific land area in which radio transmissions are heavily restricted 38°22′30″N 79°30′00″W / 38.375°N 79.5°W / 38.375; -79.5 The NRQZ includes portions of West Virginia, Virginia, and a small part of Maryland. The National Radio Quiet Zone (NRQZ) is a large area of land in the United States designated as a radio quiet zone, in which radio transmissions are restricted by law to facilitate scientific research and the gathering of military intelligence. Abou...

This article relies excessively on references to primary sources. Please improve this article by adding secondary or tertiary sources. Find sources: NBL TV – news · newspapers · books · scholar · JSTOR (January 2015) (Learn how and when to remove this template message) Television channel NBL TVCountryAustraliaBroadcast areaWorldwide (except New Zealand)ProgrammingLanguage(s)EnglishPicture format720p (HDTV)OwnershipOwnerNBL MediaHistoryLaunched30 August...

1979 studio album by Tommy FlanaganLonely TownStudio album by Tommy FlanaganReleased1979RecordedMarch 10, 1959GenreJazzLabelBlue NoteProducerKenneth KarpTommy Flanagan chronology The Cats(1957) Lonely Town(1979) The Tommy Flanagan Trio(1960) Professional ratingsReview scoresSourceRatingAllMusic[1] Lonely Town is an album by jazz pianist Tommy Flanagan. It is a trio recording, with bassist Joe Benjamin and drummer Elvin Jones. Background and recording The album was recorded in ...

British politician (1926–2001) The Right HonourableThe Lord OnslowOnslow in 1973Chair of the 1922 CommitteeIn office1984–1992LeaderMargaret ThatcherJohn MajorPreceded byEdward du CannSucceeded byMarcus FoxMember of the House of LordsLord TemporalLife peerage2 August 1997 – 13 March 2001Member of Parliamentfor WokingIn office15 October 1964 – 1 May 1997Preceded byHarold WatkinsonSucceeded byHumfrey Malins Personal detailsBornCranley Gordon Douglas Onslow(1926-06-08)8 ...

إدارة أعمال إدارة عمل تجاري محاسبة محاسبة إدارية محاسبة مالية تدقيق مالي شخصية معنوية Corporate group تكتل (شركة) شركة قابضة جمعية تعاونية مؤسسة تجارية شركة مساهمة شركة محدودة المسؤولية شراكة شركة خاصة Sole proprietorship مشاريع مملوكة من قبل الدولة حوكمة الشركات Annual general meeting مجلس إدارة �...

Deputy head of state in Equatorial Guinea Vice President of theRepublic of Equatorial GuineaCoat of arms of Equatorial GuineaIncumbentTeodoro Nguema Obiang Manguesince 21 May 2012AppointerPresident of Equatorial GuineaInaugural holderEdmundo Bossio [es]Formation12 October 1968 The vice president of Equatorial Guinea (Spanish: Vicepresidente de Guinea Ecuatorial) is the second highest political position obtainable in Equatorial Guinea. Following the 2011 constitutional reform...