SlideShare a Scribd company logo
1 of 17
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
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
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
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

More Related Content

What's hot

Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
Ashim Saha
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
sheetal singh
 

What's hot (20)

Interfacing With High Level Programming Language
Interfacing With High Level Programming Language Interfacing With High Level Programming Language
Interfacing With High Level Programming Language
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
 
Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registers
 
Interrupts
InterruptsInterrupts
Interrupts
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
 
register
registerregister
register
 
Introduction to Debuggers
Introduction to DebuggersIntroduction to Debuggers
Introduction to Debuggers
 
Registers
RegistersRegisters
Registers
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086
 
File system structure
File system structureFile system structure
File system structure
 
Stack organization
Stack organizationStack organization
Stack organization
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
 
Addressing modes of 8086 - Binu Joy
Addressing modes of 8086 - Binu JoyAddressing modes of 8086 - Binu Joy
Addressing modes of 8086 - Binu Joy
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stack
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference Instructions
 
Subroutine
SubroutineSubroutine
Subroutine
 

Similar to Stack and its usage in assembly language

Microprocessor & assembly language
Microprocessor & assembly languageMicroprocessor & assembly language
Microprocessor & assembly language
James Absalem Lintu
 

Similar to 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
 
Stack
StackStack
Stack
 
(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
 
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
 

More from Usman Bin Saad

More from 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
 

Recently uploaded

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Recently uploaded (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 

Stack and its usage in assembly language

  • 1.
  • 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
  • 4.
  • 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
  • 8.
  • 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
  • 13.
  • 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