CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.

Slides:



Advertisements
Similar presentations
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Advertisements

Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Irvine, Kip R. Assembly Language For Intel-Based Computers TYPE and SIZE Operators TYPE –returns the size, in bytes of a single element of a data label.
Computer Organization And Assembly Language
Assembly Language for Intel-Based Computers Chapter 8: Advanced Procedures Kip R. Irvine.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
Runtime Stack Managed by the CPU, using two registers
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Accessing parameters from the stack and calling functions.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language and System Programming Procedures Department of Computer Science National Tsing Hua University.
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
CS2422 Assembly Language & System Programming October 24, 2006.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
Prof. Muhammad Saeed III. 1/27/2015Computer Architecture & Assembly Language2 Assembly Language Instructions.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 2: IA-32 Processor Architecture (c) Pearson Education, All rights reserved. You.
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
CSC 221 Computer Organization and Assembly Language Lecture 12: Addressing Modes in Assembly.
Assembly Language for Intel-Based Computers, 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Today’s topics Procedures Procedures Passing values to/from procedures Passing values to/from procedures Saving registers Saving registers Documenting.
Sahar Mosleh California State University San MarcosPage 1 Nested Procedure calls and Flowcharts.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
Sahar Mosleh California State University San MarcosPage 1 Stack operations, Applications and defining procedures.
Stack and Procedures Dr Adnan Gutub aagutub ‘at’ uqu.edu.sa
CSC 221 Computer Organization and Assembly Language
The x86 Instruction Set Lecture 16 Mon, Mar 14, 2005.
Computer Organization and Assembly Languages Yung-Yu Chuang 2006/11/13
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CHAPTER 5: PROCEDURES ASSEMBLY LANGUAGE FOR INTEL- BASED COMPUTERS, 5 TH EDITION (c) Pearson Education, All rights reserved. You may modify and copy.
Compiler Construction Code Generation Activation Records
1 The Stack and Procedures Chapter 5. 2 A Process in Virtual Memory  This is how a process is placed into its virtual addressable space  The code is.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 18 Linking to External Library The Book’s Link Library Stack Operations.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Procedure Computer Organization and Assembly Languages Yung-Yu Chuang 2005/10/27 with slides by Kip Irvine.
1 Assembly Language: Function Calls Jennifer Rexford.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
CSC 221 Computer Organization and Assembly Language Lecture 20: Conditional and Block Structures.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Assembly Language Addressing Modes. Introduction CISC processors usually supports more addressing modes than RISC processors. –RISC processors use the.
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
3/10/2003 Lecture 9: Procedures Assembly Language for Intel-Based Computers 4th edition Kip R. Irvine.
Stack Operations Dr. Hadi AL Saadi.
Assembly Language for x86 Processors 6th Edition
Chapter 5: Procedures.
C function call conventions and the stack
Chapter 4 Data Movement Instructions
Introduction to Compilers Tim Teitelbaum
Stack Frames and Advanced Procedures
Practical Session 4.
Assembly Language for Intel-Based Computers, 4th Edition
Computer Architecture CST 250
The Stack and Procedures
Computer Organization and Assembly Language
Presentation transcript:

CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions

Lecture 14: Review Instruction Execution in Assembly Assembly Language Examples: Control Flow –JMP Instruction –LOOP Instruction –LOOP Example –Summing an Integer Array

Lecture Outline STACK Operations –Runtime Stack –PUSH Operation –POP Operation –PUSH and POP Instructions –Using PUSH and POP –Related Instructions

Runtime Stack Imagine a stack of Plates... –Plates are only added/removed to/from the top –LIFO (Last In First Out) structure Top Bottom

Runtime Stack Managed by the CPU, using two registers –SS (stack segment) –ESP (stack pointer) * * SP in Real-address mode FFC 00000FF FF FF0 Memory Stack ESP

PUSH Operation (1 of 3) A 32-bit push operation decrements the stack pointer by 4 and copies a value into the location pointed to by the stack pointer FFC 00000FF FF FF0 Memory Stack ESP A FFC 00000FF FF FF0 ESP AFTER BEFORE

PUSH Operation (1 of 3) A 32-bit push operation decrements the stack pointer by 4 and copies a value into the location pointed to by the stack pointer A FFC 00000FF FF FF0 ESP AFTER

PUSH Operation (1 of 3) A 32-bit push operation decrements the stack pointer by 4 and copies a value into the location pointed to by the stack pointer A FFC 00000FF FF FF0 ESP AFTER

PUSH Operation (2 of 3) Same stack after pushing one more integer: A FFC 00000FF FF FF0 ESP

PUSH Operation (3 of 3) Same stack after pushing one more integer: The area in the direction ESP grows, is always available (unless the stack has overflowed) A FFC 00000FF FF FF0 ESP

POP Operation Copies value at stack[ESP] into a register or variable. Adds n to ESP, where n is either 2 or 4. –value of n depends on the attribute of the operand receiving the data A FFC 00000FF FF FF0 ESP AFTER ESP BEFORE A FFC 00000FF FF FF0

PUSH and POP Instructions PUSH syntax: –PUSH r/m16 –PUSH r/m32 –PUSH imm32 POP syntax: –POP r/m16 –POP r/m32

Using PUSH and POP push esi; push registers push ecx push ebx mov esi,OFFSET dwordVal ; display some memory mov ecx,LENGTHOF dwordVal mov ebx,TYPE dwordVal ……… pop ebx; restore registers pop ecx pop esi Save and restore registers when they contain important values. PUSH and POP instructions occur in the opposite order.

Example: Nested Loop mov ecx,100; set outer loop count L1:; begin the outer loop push ecx; save outer loop count mov ecx,20; set inner loop count L2:; begin the inner loop ; loop L2; repeat the inner loop pop ecx; restore outer loop count loop L1; repeat the outer loop Remember the nested loop we created on page 129? It's easy to push the outer loop counter before entering the inner loop:

Related Instructions PUSHFD and POPFD –push and pop the EFLAGS register PUSHAD pushes the 32-bit general-purpose registers on the stack –order: EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI POPAD pops the same registers off the stack in reverse order –PUSHA and POPA do the same for 16-bit registers

Summary STACK Operations –Runtime Stack –PUSH Operation: Decrement n bytes from ESP and store n bytes –POP Operation: Read n bytes from location (ESP) and Increment n –PUSH and POP Instructions –Using PUSH and POP –Related Instructions

Reference Most of the Slides are taken from Presentation: Chapter 5 Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.