SlideShare a Scribd company logo
2
Most read
3
Most read
7
Most read
Stack & Subroutines
                      Company
                        LOGO
The stack
   The stack is a group of memory location in the
    R/W memory that is used for temporary storage
    of binary information during the execution of a
    program
   The stack is a LIFO structure.
     – Last In First Out.
   The starting location of the stack is defined by
    loading a 16 bit address into the stack pointer
    that spaced is reserved, usually at the top of
    the memory map.


www.themeart.com                                       2
The stack
   The stack normally grows backwards into
    memory.
   The stack can be initialized anywhere in the
    user memory map , but stack is initialized at the
    highest memory location so that there will not
    be any interface with the program.
   In 8085 microprocessor system the beginning of
    the stack is defined in the program by using the
    instruction
    LXI SP,16 bit.
   The LXI SP,a 16 bit state that load the 16 bit
    address into the stack pointer register.
www.themeart.com                                        3
Information is stored and retrieved
          from the stack
•The 8085 provide two instruction PUSH & POP for storing infor
mation on the stack and retrieving it back.

•Information in the register pairs stored on the stack in reverse
order by using the instruction PUSH.

• Information retrieved from the stack by using the instruction
POP.

•PUSH & POP both instruction works with register pairs only.
•The storage and retrieval of the content of registers on the
stack fallows the LIFO(Last-In-First-Out) sequence.

•Information in the stack location may not be destroyed until
new information is stored in that memory location
www.themeart.com                                                    4
The PUSH Instruction

2000 LXI SP,2099H    Load the stack pointer register with the addre
                     ss 2099.
2003 LXI H ,42F2H    Loads data in the HL register pair.

2006 PUSH H          The content of the HL register pair pushed int
                     o stack.
2007 DELAY COUNTER
200F
2010 POP H           Saved data in stack pointer register to HL regi
                     ster pair.




 www.themeart.com                                                      5
PUSH H
   The stack pointer is decremented by one to 2098 H
    , and the contents of the h register are copied to
    memory location 2098H.                         8085 Register
                                                                      F
                                               A
   The stack pointer register is again        B                      C
                                                                      E
                                               D
     decremented by one to 2097H,and H 42                    F2       L
                                              SP        2097
     the contents of the L register are                Memory
    copied to memory location 2097H.
   The contents of the register pair                    F2     2097
                                                         42     2098
     HL are not destroyed ; however                       X     2099

     HL is made available for delay
     counter.                        Contents on the stack &in the register
                                          after the PUSH instruction
www.themeart.com                                                              6
POP H
   The contents of the top of the stack location shown by
    the stack pointer are copied in the L register and the
    stack pointer register is incremented by one to 2098
    H.                                             8085 Register

   The contents of the top of the stack A    B
                                                                       F
                                                                       C
     (now it is 2098H) are copied in the D                             E
                                              H    42         F2       L
     H register,and the stack pointer is SP            2099

     incremented by one.                              MEMORY
   The contents of memory location
                                                          F2       2097
    2097H and 2098 are not destroyed                      42      2098
    until some other data bytes are                       X       2099

    stored in these location. Contentsafterthe stack and in the registers
                                       on
                                            the POP instruction
www.themeart.com                                                            7
Operation of the stack
   During pushing, the stack operates in a “decrement
    then store” style.
    The stack pointer is decremented first, then the
    information is placed on the stack.
    During poping, the stack operates in a “use then
    increment” style.
    The information is retrieved from the top of the
    stack and then the pointer is incremented.
    The SP pointer always points to “the top of the
      stack’’.


www.themeart.com                                         8
PUSH PSW Register Pair
     PUSH PSW (1 Byte Instruction)          A        Flag
      Decrement SP
      Copy the contents of
                                         12           80
       register A to the memory
       location pointed to by SP
     Decrement SP
     Copy the contents of
      Flag register to the memory     FFFB
                                      FFFC
       location pointed to by SP
                                      FFFD       80
                                      FFFE       12
                                      FFFF


www.themeart.com                                             9
Pop PSW Register Pair
     POP PSW (1 Byte Instruction)    A   FLAG
     Copy the contents of the       12    80
      memory location pointed to
      by the SP to Flag register
     Increment SP
     Copy the contents of the
                                   FFFB
      memory location pointed to   FFFC
      by the SP to register A      FFFD   80
                                   FFFE   12
     Increment SP                 FFFF


www.themeart.com                                 10
Subroutines
     A subroutine is group of instruction written sepa
      rately from the main program to perform a func
      tion that occurs repeatedly in the main program
      .
     When a main program calls a subroutine the pro
      gram execution is transferred to the subroutine
      after the completion of the subroutine ,the prog
      ram execution returns to the main program.
     The microprocessor uses the stack to store the r
      eturn address of the subroutine.


www.themeart.com                                          11
Subroutines
   The 8085 has two instructions for dealing
    with subroutines.
   – The CALL instruction is used to redirect
    program execution to the subroutine.
   – The RET instruction is used to return to t
    he main program at the end of the subro
    utine .




www.themeart.com                                  12
The CALL instruction
   CALL ,16 bit
   Call subroutine in conditionally located at
    the memory address specified by the 16
    bit operand.
   This instruction places the address of the
    next instruction on the stack and transfer
    the program execution to the subroutine
    address.


www.themeart.com                                  13
The RET instruction
   Return unconditionally from the subrouti
    ne.
   This instruction locates the return addre
    ss on the top of the stack and transfers t
    he program execution back to the calling
    program.




www.themeart.com                                 14
General characteristics of CALL
       & RTE instruction
  1. The CALL instructions are 3-byte instruc
     tion; the second byte specifies the low
     order byte ,and the third byte specifies
     the high order byte of the subroutine
     address.
  2. The return instruction are 1-byte instruc
     tions.
  3. A CALL instruction must be used in
     conjunction with a return instruction in
     the subroutine .
www.themeart.com                                 15
Necessary steps to implement
          a subroutine

   The stack pointer register must be initiali
    zed ,preferably at the highest memory lo
    cation of the R/W memory.
   The call instruction should be used in the
    main program accompanied by the RET i
    nstruction in the subroutine.




www.themeart.com                                  16
Conditional CALL and RTE Instructions
      The 8085 supports conditional CALL and co
       nditional RTE instructions.
      – The same conditions used with conditional
       JUMP instructions can be used.
      – CC, call subroutine if Carry flag is set.
      – CNC, call subroutine if Carry flag is not set
      – RC, return from subroutine if Carry flag is
       set
      – RNC, return from subroutine if Carry flag
         is not set.
www.themeart.com                                        17
www.themeart.com   18

More Related Content

PPTX
Interrupts of microprocessor 8085
PPTX
4.programmable dma controller 8257
PPTX
3.programmable interrupt controller 8259
PPT
Interfacing 8255
PPT
Architecture of 8086 Microprocessor
PPTX
ARITHMETIC OPERATIONS IN 8085 MICROPROCESSOR
PDF
itft-Instruction set-of-8085
PPTX
Pentium processor
Interrupts of microprocessor 8085
4.programmable dma controller 8257
3.programmable interrupt controller 8259
Interfacing 8255
Architecture of 8086 Microprocessor
ARITHMETIC OPERATIONS IN 8085 MICROPROCESSOR
itft-Instruction set-of-8085
Pentium processor

What's hot (20)

PPT
Data transfer instruction set of 8085 micro processor
PPT
Memory & I/O interfacing
PPTX
Salient featurs of 80386
PPTX
Instruction set of 8085 microprocessor
PDF
8085 branching instruction
PPTX
Architecture of 8051
PPTX
Addressing Modes of 8085 Microprocessor
PPTX
Presentation on 8086 microprocessor
DOCX
8086 pin diagram description
PPT
8086 pin details
PPTX
Stack in 8085 microprocessor
PPTX
Stack and subroutine
PPTX
8237 dma controller
PPTX
Floating point arithmetic operations (1)
DOCX
8085 interfacing with memory chips
PPTX
8255 PPI
PPT
8251 universal synchronous asynchronous receiver transmitter
PPTX
Pin diagram 8085
PPT
Interrupt programming with 8051 microcontroller
PPTX
memory organi.pptx
Data transfer instruction set of 8085 micro processor
Memory & I/O interfacing
Salient featurs of 80386
Instruction set of 8085 microprocessor
8085 branching instruction
Architecture of 8051
Addressing Modes of 8085 Microprocessor
Presentation on 8086 microprocessor
8086 pin diagram description
8086 pin details
Stack in 8085 microprocessor
Stack and subroutine
8237 dma controller
Floating point arithmetic operations (1)
8085 interfacing with memory chips
8255 PPI
8251 universal synchronous asynchronous receiver transmitter
Pin diagram 8085
Interrupt programming with 8051 microcontroller
memory organi.pptx
Ad

Similar to Stack in microprocessor 8085(presantation) (20)

PPT
7. Stacks and subroutine.pptfor engineering student
PPTX
Stacks & subroutines 1
PPTX
B sc e 5.2 mp unit 2 soft ware(alp)
PDF
Lecture 05 NOP and Stack Group of Instructions
PPT
Chapter 9
PDF
Stack and subroutine
PPTX
Microprocessor and Microcontroller lec4
PPSX
03 addr mode & instructions
PPTX
Embedded C programming session10
PPTX
Stacks & Subroutines.ppt.pptx
PDF
C programming session10
PPTX
PPTX
PDF
Instructionset8085
PPTX
Basic programming of 8085
PPT
8085 instruction set
PDF
8085 is details
PPTX
UNIT II.pptx
PPTX
8051 Programming (1).pptx
PPTX
4. Instruction Set Of MP 8085.pptx
7. Stacks and subroutine.pptfor engineering student
Stacks & subroutines 1
B sc e 5.2 mp unit 2 soft ware(alp)
Lecture 05 NOP and Stack Group of Instructions
Chapter 9
Stack and subroutine
Microprocessor and Microcontroller lec4
03 addr mode & instructions
Embedded C programming session10
Stacks & Subroutines.ppt.pptx
C programming session10
Instructionset8085
Basic programming of 8085
8085 instruction set
8085 is details
UNIT II.pptx
8051 Programming (1).pptx
4. Instruction Set Of MP 8085.pptx
Ad

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Dropbox Q2 2025 Financial Results & Investor Presentation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Mobile App Security Testing_ A Comprehensive Guide.pdf
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.

Stack in microprocessor 8085(presantation)

  • 1. Stack & Subroutines Company LOGO
  • 2. The stack  The stack is a group of memory location in the R/W memory that is used for temporary storage of binary information during the execution of a program  The stack is a LIFO structure. – Last In First Out.  The starting location of the stack is defined by loading a 16 bit address into the stack pointer that spaced is reserved, usually at the top of the memory map. www.themeart.com 2
  • 3. The stack  The stack normally grows backwards into memory.  The stack can be initialized anywhere in the user memory map , but stack is initialized at the highest memory location so that there will not be any interface with the program.  In 8085 microprocessor system the beginning of the stack is defined in the program by using the instruction  LXI SP,16 bit.  The LXI SP,a 16 bit state that load the 16 bit address into the stack pointer register. www.themeart.com 3
  • 4. Information is stored and retrieved from the stack •The 8085 provide two instruction PUSH & POP for storing infor mation on the stack and retrieving it back. •Information in the register pairs stored on the stack in reverse order by using the instruction PUSH. • Information retrieved from the stack by using the instruction POP. •PUSH & POP both instruction works with register pairs only. •The storage and retrieval of the content of registers on the stack fallows the LIFO(Last-In-First-Out) sequence. •Information in the stack location may not be destroyed until new information is stored in that memory location www.themeart.com 4
  • 5. The PUSH Instruction 2000 LXI SP,2099H Load the stack pointer register with the addre ss 2099. 2003 LXI H ,42F2H Loads data in the HL register pair. 2006 PUSH H The content of the HL register pair pushed int o stack. 2007 DELAY COUNTER 200F 2010 POP H Saved data in stack pointer register to HL regi ster pair. www.themeart.com 5
  • 6. PUSH H  The stack pointer is decremented by one to 2098 H , and the contents of the h register are copied to memory location 2098H. 8085 Register F A  The stack pointer register is again B C E D decremented by one to 2097H,and H 42 F2 L SP 2097 the contents of the L register are Memory copied to memory location 2097H.  The contents of the register pair F2 2097 42 2098 HL are not destroyed ; however X 2099 HL is made available for delay counter. Contents on the stack &in the register after the PUSH instruction www.themeart.com 6
  • 7. POP H  The contents of the top of the stack location shown by the stack pointer are copied in the L register and the stack pointer register is incremented by one to 2098 H. 8085 Register  The contents of the top of the stack A B F C (now it is 2098H) are copied in the D E H 42 F2 L H register,and the stack pointer is SP 2099 incremented by one. MEMORY  The contents of memory location F2 2097 2097H and 2098 are not destroyed 42 2098 until some other data bytes are X 2099 stored in these location. Contentsafterthe stack and in the registers on the POP instruction www.themeart.com 7
  • 8. Operation of the stack  During pushing, the stack operates in a “decrement then store” style.  The stack pointer is decremented first, then the information is placed on the stack.  During poping, the stack operates in a “use then increment” style.  The information is retrieved from the top of the stack and then the pointer is incremented.  The SP pointer always points to “the top of the stack’’. www.themeart.com 8
  • 9. PUSH PSW Register Pair  PUSH PSW (1 Byte Instruction) A Flag  Decrement SP  Copy the contents of 12 80 register A to the memory location pointed to by SP  Decrement SP  Copy the contents of Flag register to the memory FFFB FFFC location pointed to by SP FFFD 80 FFFE 12 FFFF www.themeart.com 9
  • 10. Pop PSW Register Pair  POP PSW (1 Byte Instruction) A FLAG  Copy the contents of the 12 80 memory location pointed to by the SP to Flag register  Increment SP  Copy the contents of the FFFB memory location pointed to FFFC by the SP to register A FFFD 80 FFFE 12  Increment SP FFFF www.themeart.com 10
  • 11. Subroutines  A subroutine is group of instruction written sepa rately from the main program to perform a func tion that occurs repeatedly in the main program .  When a main program calls a subroutine the pro gram execution is transferred to the subroutine after the completion of the subroutine ,the prog ram execution returns to the main program.  The microprocessor uses the stack to store the r eturn address of the subroutine. www.themeart.com 11
  • 12. Subroutines  The 8085 has two instructions for dealing with subroutines. – The CALL instruction is used to redirect program execution to the subroutine. – The RET instruction is used to return to t he main program at the end of the subro utine . www.themeart.com 12
  • 13. The CALL instruction  CALL ,16 bit  Call subroutine in conditionally located at the memory address specified by the 16 bit operand.  This instruction places the address of the next instruction on the stack and transfer the program execution to the subroutine address. www.themeart.com 13
  • 14. The RET instruction  Return unconditionally from the subrouti ne.  This instruction locates the return addre ss on the top of the stack and transfers t he program execution back to the calling program. www.themeart.com 14
  • 15. General characteristics of CALL & RTE instruction 1. The CALL instructions are 3-byte instruc tion; the second byte specifies the low order byte ,and the third byte specifies the high order byte of the subroutine address. 2. The return instruction are 1-byte instruc tions. 3. A CALL instruction must be used in conjunction with a return instruction in the subroutine . www.themeart.com 15
  • 16. Necessary steps to implement a subroutine  The stack pointer register must be initiali zed ,preferably at the highest memory lo cation of the R/W memory.  The call instruction should be used in the main program accompanied by the RET i nstruction in the subroutine. www.themeart.com 16
  • 17. Conditional CALL and RTE Instructions  The 8085 supports conditional CALL and co nditional RTE instructions. – The same conditions used with conditional JUMP instructions can be used. – CC, call subroutine if Carry flag is set. – CNC, call subroutine if Carry flag is not set – RC, return from subroutine if Carry flag is set – RNC, return from subroutine if Carry flag is not set. www.themeart.com 17