Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 1 Stack Operations Runtime Stack PUSH Operation POP.

Slides:



Advertisements
Similar presentations
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Advertisements

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Conditional Loop Instructions LOOPZ and LOOPE LOOPNZ.
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.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
Computer Organization And Assembly Language
Assembly Language for Intel-Based Computers Chapter 8: Advanced Procedures Kip R. Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
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.
Assembly Language for Intel-Based Computers
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.
Assembly Language Basic Concepts IA-32 Processor Architecture.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
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.
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,
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Stack Operations LIFO structure (last-in,first-out) –The last value put into the stack is the first value taken out Runtime stack –A memory array that.
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.
Assembly Language for Intel-Based Computers, 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for x86 Processors 7th Edition
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
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.
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
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
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.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
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 15: STACK Related Instructions.
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 Week 10: Conditional Processing Slides modified by Dr. Osama Younes.
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.
3/10/2003 Lecture 9: Procedures Assembly Language for Intel-Based Computers 4th edition Kip R. Irvine.
Stack Operations Dr. Hadi AL Saadi.
Computer Architecture and Assembly Language
Assembly Language for x86 Processors 6th Edition
Chapter 5: Procedures.
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:

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP Operation PUSH and POP Instructions Using PUSH and POP Example: Reversing a String Related Instructions

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Runtime Stack Imagine a stack of plates... plates are only added to the top plates are only removed from the top LIFO structure

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Runtime Stack Managed by the CPU, using two registers SS (stack segment) ESP (stack pointer) * * SP in Real-address mode

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, PUSH Operation (1 of 2) A 32-bit push operation decrements the stack pointer by 4 and copies a value into the location pointed to by the stack pointer.

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, PUSH Operation (2 of 2) Same stack after pushing two more integers: The stack grows downward. The area below ESP is always available (unless the stack has overflowed).

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, 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

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, PUSH and POP Instructions PUSH syntax: PUSH r/m16 PUSH r/m32 PUSH imm32 POP syntax: POP r/m16 POP r/m32

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, 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 call DumpMem 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.

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, 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:

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Example: Reversing a String Use a loop with indexed addressing Push each character on the stack Start at the beginning of the string, pop the stack in reverse order, insert each character back into the string Source code Q: Why must each character be put in EAX before it is pushed? Because only word (16-bit) or doubleword (32-bit) values can be pushed on the stack.

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Your turn... Using the String Reverse program as a starting point, #1: Modify the program so the user can input a string containing between 1 and 50 characters. #2: Modify the program so it inputs a list of 32-bit integers from the user, and then displays the integers in reverse order.

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, 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

Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Your Turn... Write a program that does the following: Assigns integer values to EAX, EBX, ECX, EDX, ESI, and EDI Uses PUSHAD to push the general-purpose registers on the stack Using a loop, your program should pop each integer from the stack and display it on the screen