EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

Slides:



Advertisements
Similar presentations
Week 8 Stack and Subroutines. Stack  The stack is a section of data memory (or RAM) that is reserved for storage of temporary data  The data may represent.
Advertisements

CPU Review and Programming Models CT101 – Computing Systems.
8085 Architecture & Its Assembly language programming
Processor System Architecture
TK 2633 Microprocessor & Interfacing
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
EECC250 - Shaaban #1 Lec # 5 Winter Stacks A stack is a First In Last Out (FILO) buffer containing a number of data items usually implemented.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Room: Timbalan Pengarah Pusat Komputer Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 4: Introduction.
TK 2633 Microprocessor & Interfacing
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Rabel Talpur:12BME#025.  40-pin chip  Developed by Motorola in 1975  16 address lines and 8 data lines  Used only +5V.
INSTRUCTION SET OF MICROPROCESSOR 8085
Stacks and Subroutines ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Computer Architecture Lecture 13 – part 2 by Engineer A. Lecturer Aymen Hasan AlAwady 7/4/2014 University of Kufa - Information Technology Research and.
Objective At the conclusion of this chapter you will be able to:
Computer Architecture Lecture 13 – part 1 by Engineer A. Lecturer Aymen Hasan AlAwady 31/3/2014 University of Kufa - Information Technology Research and.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8.
Ass Prof Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 6: Control Instructions.
Assembly Language Programming of 8085 BY Prof. U. V. THETE Dept. of Computer Science YMA.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Subroutines and Stacks. Stack The stack is a special area in memory used by the CPU to store register information or general data information during program.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
1 Stack Advanced Programming. 2 The Stack It is a special area of memory used as temporary storage A stack is a LIFO data structure Putting data into.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Index What is an Interface Pins of 8085 used in Interfacing Memory – Microprocessor Interface I/O – Microprocessor Interface Basic RAM Cells Stack Memory.
8085 Microprocessor Architecture
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Gursharan Singh Tatla INSTRUCTION SET OF 8085 Gursharan Singh Tatla Gursharan Singh Tatla
Unit 1 Instruction set M.Brindha AP/EIE
PROGRAMMING OF 8085 PROCESSOR
BLOCK DIAGRAM OF INTEL 8085.
Gunjeet Kaur Dronacharya Group of institutions
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
The Stack.
Detailed Review of the 8085 Instruction Set.
3.Instruction Set of 8085 Consists of 74 operation codes, e.g. MOV
Subroutines and the Stack
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Introduction to 8085 Instructions
TAO1221 COMPUTER ARCHITECTURE AND ORGANIZATION LAB 3 & 4 Part 2
Microcomputer Programming
Chapter 3 Addressing Modes
Arithmetic using a stack
Symbolic Instruction and Addressing
Additional data transfer and 16 bit arithmetic instruction Lecture 1
EMT 245: lecture 4: assembly language
Stack and Subroutines Module M17.1 Section 11.2.
Number Representations and Basic Processor Architecture
Programming 8086 – Part IV Stacks, Macros
Detailed Review of the 8085 Instruction Set.
Registers in the CPU Inside the CPU.
Subroutines and the Stack
8085 MICROPROCESSOR 8085 CPU Registers and Status Flags S Z AC P C A B
Symbolic Instruction and Addressing
Chapter 6 - Procedures and Macros
Open Education Resource-OER on Microprocessor 8085 Instruction Set By Dr. S. N. Sampat, Team leader Ms. R. P. Merchant, Member Mr. A. K. Bilakhia, Member.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Subroutines and the Stack
Some Assembly (Part 2) set.html.
Computer Organization and Assembly Language
Computer Operation 6/22/2019.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE511: Digital System & Microprocessor
Presentation transcript:

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR Stack and Subroutines EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR 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. EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR 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. EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

Information is stored and retrieved from the stack The 8085 provide two instruction PUSH & POP for storing information 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 EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR The PUSH Instruction 2000 LXI SP,2099H 2003 LXI H ,42F2H 2006 PUSH H 2007 DELAY COUNTER 200F 2010 POP H Load the stack pointer register with the address 2099. Loads data in the HL register pair. The content of the HL register pair pushed into stack. Saved data in stack pointer register to HL register pair. EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR 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. The stack pointer register is again decremented by one to 2097H,and the contents of the L register are copied to memory location 2097H. The contents of the register pair HL are not destroyed ; however HL is made available for delay counter. 8085 Register F C E L A B D H SP 42 F2 2097 Memory F2 42 X 2097 2098 2099 Contents on the stack &in the register after the PUSH instruction EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR 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. The contents of the top of the stack (now it is 2098H) are copied in the H register,and the stack pointer is incremented by one. MEMORY The contents of memory location 2097H and 2098 are not destroyed until some other data bytes are stored in these location. 8085 Register A B D H SP F C E L 42 F2 2099 F2 2097 2098 X 2099 Contents on the stack and in the registers after the POP instruction EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR 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’’. EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR PUSH PSW Register Pair PUSH PSW (1 Byte Instruction) A Flag Decrement SP Copy the contents of register A to the memory location pointed to by SP Flag register to the memory 12 80 FFFB FFFC FFFD FFFE FFFF 80 12 EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR Pop PSW Register Pair POP PSW (1 Byte Instruction) A FLAG Copy the contents of the memory location pointed to by the SP to Flag register Increment SP by the SP to register A 12 80 FFFB FFFC FFFD FFFE FFFF 80 12 EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR Subroutines A subroutine is group of instruction written separately from the main program to perform a function that occurs repeatedly in the main program. When a main program calls a subroutine the program execution is transferred to the subroutine after the completion of the subroutine ,the program execution returns to the main program. The microprocessor uses the stack to store the return address of the subroutine. 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 the main program at the end of the subroutine . EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR 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. EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR The RET instruction Return unconditionally from the subroutine. This instruction locates the return address on the top of the stack and transfers the program execution back to the calling program. EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

General characteristics of CALL & RTE instruction The CALL instructions are 3-byte instruction; the second byte specifies the low order byte ,and the third byte specifies the high order byte of the subroutine address. The return instruction are 1-byte instructions. A CALL instruction must be used in conjunction with a return instruction in the subroutine . EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

Necessary steps to implement a subroutine The stack pointer register must be initialized ,preferably at the highest memory location of the R/W memory. The call instruction should be used in the main program accompanied by the RET instruction in the subroutine. EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR

Conditional CALL and RTE Instructions The 8085 supports conditional CALL and conditional 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. EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR