SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
Stack and its usage in assembly language
Stacks
Usman Bin Saad FA14-BSE-4C-118
Shahid Iqbal FA14-BSE-4C-160
Haseeb Ahmad FA14-BSE-4C-129
Submitted to
Miss Arubah
Stack
• A stack is a data structure that stores data in such a way that the
last piece of data stored, is the first one retrieved i.e. Last in,
First out LIFO / First in Last out FILO
• Only access to the stack is the top element
• Anything added to the stack goes on the “top” of the stack
• Anything removed from the stack is taken from the “top” of the
stack
• Things are removed in the reverse order from that in which they
were inserted
Stack and its usage in assembly language
Basic Stack Operations
• There are three Basic Stack Operations which are discussed below
• Push
• Pop
• Stack Top
Push
• The operation to place a new item at the top of the stack
Pop
• The operation to remove the next item from the top of the stack
Stack and its usage in assembly language
Implementing a Stack
• At least three different ways to implement a stack
• array
• vector
• linked list
Stack in Assembly Language
• The stack segment register holds the starting address of the stack segment
in the memory. Majorly SS is used for the following purposes namely:
1.To hold the temporary results.
2.To hold the return address of the subroutine.
3.Finally to handle the interrupts
• SS (Stack Segment) Register: holds stack Segment Address
• SP (Stack Pointer) Register: initialized to the value specified with the .STACK
directive, represents empty stack position
• When stack is not empty, SP represents the top of the Stack
Stack (cont ..)
• In order to save the contents of a register during the execution, so that it
can be used later for purposes.
• To do so, the microprocessor has a area of memory where the contents of
specified registers or memory location can be saved temporarily, and is
called STACK.
• It is a top-down data structure whose elements are accessed using the
pointer that is implemented using the SP and SS registers.
• As we go on storing the data words onto the stack, the pointer goes on
decrementing.
PUSH And PUSHF
• PUSH: Used to add a new source (16-bit register or memory word) on stack
Syntax:
PUSH source
• Execution of PUSH causes:
SP is decreased by 2
A copy of source contents is moved to the address specified by SS:SP.
Source remains unchanged
• PUSHF has no operand and it pushes the contents of FLAG register onto
the stack.
• Usually this is done whenever the processor is interrupted
Syntax: PUSHF
Stack and its usage in assembly language
POP And POPF
• POP: Used to remove top item from stack to destination (i.e. a 16-bit register
or memory word).
Syntax:
POP destination
• Execution of POP causes:
The contents of SS:SP (top of the stack) is moved to the destination.
SP is increased by 2
• POPF has no operand and pops the top of the stack into FLAG register.
• SP is incremented by 2 after executing this instant.
Syntax: POPF
Stack and its usage in assembly language
Stack and its usage in assembly language
Stack and its usage in assembly language

Contenu connexe

Tendances

Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptxLecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptxVikasMahor3
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionBadrul Alam
 
Stack organization
Stack organizationStack organization
Stack organizationchauhankapil
 
INTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORINTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORGurudev joshi
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Anwar Hasan Shuvo
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer languageSanjeev Patel
 
Program control instructions
Program control instructionsProgram control instructions
Program control instructionsDr. Girish GS
 
Addressing modes of 80386
Addressing modes of 80386Addressing modes of 80386
Addressing modes of 80386PDFSHARE
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
Stack Operations
Stack Operations Stack Operations
Stack Operations RidaZaman1
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.NA000000
 
8086 pin diagram description
8086 pin diagram description8086 pin diagram description
8086 pin diagram descriptionAkhil Singal
 
Addressing modes (detailed data path)
Addressing modes (detailed data path)Addressing modes (detailed data path)
Addressing modes (detailed data path)Mahesh Kumar Attri
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Bilal Amjad
 
Assembly language (addition and subtraction)
Assembly language (addition and subtraction)Assembly language (addition and subtraction)
Assembly language (addition and subtraction)Muhammad Umar Farooq
 

Tendances (20)

Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptxLecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
Lecture 28 , 29 & 30(instruction set & addressing mode of 8086.pptx
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate Instruction
 
Stack organization
Stack organizationStack organization
Stack organization
 
INTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSORINTERRUPTS OF 8086 MICROPROCESSOR
INTERRUPTS OF 8086 MICROPROCESSOR
 
Register & flags
Register & flagsRegister & flags
Register & flags
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer language
 
Program control instructions
Program control instructionsProgram control instructions
Program control instructions
 
Interrupts and types of interrupts
Interrupts and types of interruptsInterrupts and types of interrupts
Interrupts and types of interrupts
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Addressing modes of 80386
Addressing modes of 80386Addressing modes of 80386
Addressing modes of 80386
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
Lecture 3 instruction set
Lecture 3  instruction setLecture 3  instruction set
Lecture 3 instruction set
 
Stack Operations
Stack Operations Stack Operations
Stack Operations
 
8086 String Instructions.pdf
8086 String Instructions.pdf8086 String Instructions.pdf
8086 String Instructions.pdf
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
8086 pin diagram description
8086 pin diagram description8086 pin diagram description
8086 pin diagram description
 
Addressing modes (detailed data path)
Addressing modes (detailed data path)Addressing modes (detailed data path)
Addressing modes (detailed data path)
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
 
Assembly language (addition and subtraction)
Assembly language (addition and subtraction)Assembly language (addition and subtraction)
Assembly language (addition and subtraction)
 

Similaire à Stack and its usage in assembly language

Central processing unit
Central processing unitCentral processing unit
Central processing unitHeman Pathak
 
What is Stack? Application of Stack
What is Stack? Application of StackWhat is Stack? Application of Stack
What is Stack? Application of StackShahzeb Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Bilal Amjad
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfGirT2
 
(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memoryNico Ludwig
 
7BCEE2A - UNIT V - STACK ORGANIZATION.pdf
7BCEE2A - UNIT V - STACK ORGANIZATION.pdf7BCEE2A - UNIT V - STACK ORGANIZATION.pdf
7BCEE2A - UNIT V - STACK ORGANIZATION.pdfRajendranSheeba
 
Execution of functions
Execution of functionsExecution of functions
Execution of functionsShashank Singh
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stackAsif Iqbal
 
Microprocessor & assembly language
Microprocessor & assembly languageMicroprocessor & assembly language
Microprocessor & assembly languageJames Absalem Lintu
 
Stack and; parameters passing through stack
Stack and; parameters passing through stackStack and; parameters passing through stack
Stack and; parameters passing through stackAshfaq Hussain
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory ManagementRahul Jamwal
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxprakashvs7
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operationSenthil Kumar
 

Similaire à Stack and its usage in assembly language (20)

Central processing unit
Central processing unitCentral processing unit
Central processing unit
 
What is Stack? Application of Stack
What is Stack? Application of StackWhat is Stack? Application of Stack
What is Stack? Application of Stack
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
5.-Stacks.pptx
5.-Stacks.pptx5.-Stacks.pptx
5.-Stacks.pptx
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Data structure
Data structureData structure
Data structure
 
(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory
 
7BCEE2A - UNIT V - STACK ORGANIZATION.pdf
7BCEE2A - UNIT V - STACK ORGANIZATION.pdf7BCEE2A - UNIT V - STACK ORGANIZATION.pdf
7BCEE2A - UNIT V - STACK ORGANIZATION.pdf
 
Execution of functions
Execution of functionsExecution of functions
Execution of functions
 
Stacks
StacksStacks
Stacks
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stack
 
Microprocessor & assembly language
Microprocessor & assembly languageMicroprocessor & assembly language
Microprocessor & assembly language
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
Stack and; parameters passing through stack
Stack and; parameters passing through stackStack and; parameters passing through stack
Stack and; parameters passing through stack
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 
Chapter 4 stack
Chapter 4 stackChapter 4 stack
Chapter 4 stack
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
class-Stacks.pptx
class-Stacks.pptxclass-Stacks.pptx
class-Stacks.pptx
 

Plus de Usman Bin Saad

Plus de Usman Bin Saad (12)

financial statement analysis
financial statement analysisfinancial statement analysis
financial statement analysis
 
Unit costing
Unit costing Unit costing
Unit costing
 
Biochem
BiochemBiochem
Biochem
 
Calculas
CalculasCalculas
Calculas
 
Hybrid Cars , Autonomous Cars and future trends and Technologies
Hybrid Cars , Autonomous Cars and future trends and Technologies Hybrid Cars , Autonomous Cars and future trends and Technologies
Hybrid Cars , Autonomous Cars and future trends and Technologies
 
Critical Systems
Critical SystemsCritical Systems
Critical Systems
 
Software Processes
Software Processes Software Processes
Software Processes
 
Project management
Project managementProject management
Project management
 
Hybrid Cars
Hybrid Cars Hybrid Cars
Hybrid Cars
 
Presentation of se
Presentation of sePresentation of se
Presentation of se
 
Environment
EnvironmentEnvironment
Environment
 
Top 10 Innovations of 2015
Top 10 Innovations of 2015Top 10 Innovations of 2015
Top 10 Innovations of 2015
 

Dernier

Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Incrobinwilliams8624
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native BuildpacksVish Abrams
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 

Dernier (20)

Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Inc
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native Buildpacks
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 

Stack and its usage in assembly language

  • 2. Stacks Usman Bin Saad FA14-BSE-4C-118 Shahid Iqbal FA14-BSE-4C-160 Haseeb Ahmad FA14-BSE-4C-129 Submitted to Miss Arubah
  • 3. Stack • A stack is a data structure that stores data in such a way that the last piece of data stored, is the first one retrieved i.e. Last in, First out LIFO / First in Last out FILO • Only access to the stack is the top element • Anything added to the stack goes on the “top” of the stack • Anything removed from the stack is taken from the “top” of the stack • Things are removed in the reverse order from that in which they were inserted
  • 5. Basic Stack Operations • There are three Basic Stack Operations which are discussed below • Push • Pop • Stack Top
  • 6. Push • The operation to place a new item at the top of the stack
  • 7. Pop • The operation to remove the next item from the top of the stack
  • 9. Implementing a Stack • At least three different ways to implement a stack • array • vector • linked list
  • 10. Stack in Assembly Language • The stack segment register holds the starting address of the stack segment in the memory. Majorly SS is used for the following purposes namely: 1.To hold the temporary results. 2.To hold the return address of the subroutine. 3.Finally to handle the interrupts • SS (Stack Segment) Register: holds stack Segment Address • SP (Stack Pointer) Register: initialized to the value specified with the .STACK directive, represents empty stack position • When stack is not empty, SP represents the top of the Stack
  • 11. Stack (cont ..) • In order to save the contents of a register during the execution, so that it can be used later for purposes. • To do so, the microprocessor has a area of memory where the contents of specified registers or memory location can be saved temporarily, and is called STACK. • It is a top-down data structure whose elements are accessed using the pointer that is implemented using the SP and SS registers. • As we go on storing the data words onto the stack, the pointer goes on decrementing.
  • 12. PUSH And PUSHF • PUSH: Used to add a new source (16-bit register or memory word) on stack Syntax: PUSH source • Execution of PUSH causes: SP is decreased by 2 A copy of source contents is moved to the address specified by SS:SP. Source remains unchanged • PUSHF has no operand and it pushes the contents of FLAG register onto the stack. • Usually this is done whenever the processor is interrupted Syntax: PUSHF
  • 14. POP And POPF • POP: Used to remove top item from stack to destination (i.e. a 16-bit register or memory word). Syntax: POP destination • Execution of POP causes: The contents of SS:SP (top of the stack) is moved to the destination. SP is increased by 2 • POPF has no operand and pops the top of the stack into FLAG register. • SP is incremented by 2 after executing this instant. Syntax: POPF