Miscellaneous Topics.

Slides:



Advertisements
Similar presentations
Assembly Language Programming Chapter 8
Advertisements

Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 8:Advanced Procedures (c) Pearson Education, All rights reserved. You may modify.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
Assembly Language for Intel-Based Computers Chapter 8: Advanced Procedures Kip R. Irvine.
University of Washington Last Time For loops  for loop → while loop → do-while loop → goto version  for loop → while loop → goto “jump to middle” version.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 8:Advanced Procedures (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
– 1 – , F’02 ICS05 Instructor: Peter A. Dinda TA: Bin Lin Recitation 4.
CS2422 Assembly Language & System Programming October 26, 2006.
Semantics of Calls and Returns
Kip Irvine: Assembly Language for Intel-Based Computers
INVOKE Directive The INVOKE directive is a powerful replacement for Intel’s CALL instruction that lets you pass multiple arguments Syntax: INVOKE procedureName.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
CS2422 Assembly Language and System Programming High-Level Language Interface Department of Computer Science National Tsing Hua University.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Universal Concepts of Programming Creating and Initializing local variables on the stack Variable Scope and Lifetime Stack Parameters Stack Frames Passing.
Instruction Set Design by Kip R. Irvine (c) Kip Irvine, All rights reserved. You may modify and copy this slide show for your personal use,
Assembly Language for x86 Processors 6th Edition Chapter 8: Advanced 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 Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Today's topics Multi-dimensional arrays Multi-dimensional arrays String processing String processing Macros Macros.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Today’s topics Procedures Procedures Passing values to/from procedures Passing values to/from procedures Saving registers Saving registers Documenting.
Procedures – Generating the Code Lecture 21 Mon, Apr 4, 2005.
Sahar Mosleh California State University San MarcosPage 1 Stack operations, Applications and defining procedures.
CSC 221 Computer Organization and Assembly Language
Assembly Language for x86 Processors 7th Edition
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Machine-level Programming III: Procedures Topics –IA32 stack discipline –Register saving conventions –Creating pointers to local variables.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
Compiler Construction Code Generation Activation Records
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Chapter 8:Advanced Procedures. 2 Chapter Overview Local Variables Stack Parameters Stack Frames Recursion Creating Multimodule Programs.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Chapter 7 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Assembly Language for Intel-Based Computers, 4 th Edition Week 12: Advanced Procedures Modified by Dr. Osama Younes.
Procedures Dr. Hadi Al Saadi Large problems can be divided into smaller tasks to make them more manageable A procedure is the ASM equivalent of a Java.
Lecture 15 Advanced Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Chapter 14 Functions.
Assembly Language for x86 Processors 7th Edition
Assembly Lab 3.
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Language for x86 Processors 6th Edition
Microprocessor and Assembly Language
Introduction to Compilers Tim Teitelbaum
Assembly Language for x86 Processors 6th Edition
Machine-Level Programming 4 Procedures
Stack Frames and Advanced Procedures
Procedures – Overview Lecture 19 Mon, Mar 28, 2005.
Assembly Language for Intel-Based Computers, 4th Edition
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Computer Organization and Assembly Languages Yung-Yu Chuang 2008/12/22
Microprocessor and Assembly Language
Machine-Level Programming III: Procedures Sept 18, 2001
Multi-modules programming
Assembly Language for Intel-Based Computers, 5th Edition
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/4
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/24
Computer Organization and Assembly Language
CSC 497/583 Advanced Topics in Computer Security
Assembly Language for Intel-Based Computers, 4th Edition
Procedures and Macros.
Presentation transcript:

Miscellaneous Topics

Miscellaneous Topics Recursion Invoke Directive Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Recursion The process created when . . . A procedure calls itself Procedure A calls procedure B, which in turn calls procedure A Using a graph in which each node is a procedure and each edge is a procedure call, recursion forms a cycle: Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Calculating a Factorial (1 of 3) This function calculates the factorial of integer n. A new value of n is saved in each stack frame: int function factorial(int n) { if(n == 0) return 1; else return n * factorial(n-1); } As each call instance returns, the product it returns is multiplied by the previous value of n. Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Calculating a Factorial (2 of 3) Factorial PROC push ebp mov ebp,esp mov eax,[ebp+8] ; get n cmp eax,0 ; n < 0? ja L1 ; yes: continue mov eax,1 ; no: return 1 jmp L2 L1: dec eax push eax ; Factorial(n-1) call Factorial ; Instructions from this point on execute when each ; recursive call returns. ReturnFact: mov ebx,[ebp+8] ; get n mul ebx ; eax = eax * ebx L2: pop ebp ; return EAX ret 4 ; clean up stack Factorial ENDP See the program listing Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Calculating a Factorial (3 of 3) Suppose we want to calculate 12! This diagram shows the first few stack frames created by recursive calls to Factorial Each recursive call uses 12 bytes of stack space. Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

INVOKE Directive In 32-bit mode (not 64), the INVOKE directive is a powerful replacement for Intel’s CALL instruction that lets you pass multiple arguments Syntax: INVOKE procedureName [, argumentList] ArgumentList is an optional comma-delimited list of procedure arguments Arguments can be: immediate values and integer expressions variable names address and ADDR expressions register names Note: ADDR is like OFFSET – creates a pointer Can only be used with assembly time constants Illegal: Invoke mySub, ADDR [ebp+12] Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

INVOKE Examples .data byteVal BYTE 10 wordVal WORD 1000h .code ; direct operands: INVOKE Sub1,byteVal,wordVal ; address of variable: INVOKE Sub2,ADDR byteVal ; register name, integer expression: INVOKE Sub3,eax,(10 * 20) ; address expression (indirect operand): INVOKE Sub4,[ebx] Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

PROTO Example: ArraySumInvoke In order to use INVOKE, a prototype must be created first similar to C++ Syntax: procedureName PROTO [, argumentList] ArgumentList must match the PROC parameters Example: ArraySumInvoke Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.