Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, 2015. All rights reserved. You may modify.

Slides:



Advertisements
Similar presentations
Assembly Language for x86 Processors 6 th Edition Chapter 1: Introduction to ASM (c) Pearson Education, All rights reserved. You may modify and copy.
Advertisements

CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
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.
Chapter 8: Programming the Microprocessor. Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 12: High-Level Language Interface (c) Pearson Education, All rights reserved.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 12: High-Level Language Interface (c) Pearson Education, All rights reserved.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Accessing parameters from the stack and calling functions.
Chapter 12: High-Level Language Interface. Chapter Overview Introduction Inline Assembly Code C calls assembly procedures Assembly calls C procedures.
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, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Guide To UNIX Using Linux Third Edition
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 12: High-Level Language Interface (c) Pearson Education, All rights reserved. You.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
ICS312 Set 11 Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External.
CS2422 Assembly Language and System Programming High-Level Language Interface Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming November 7, 2006.
CS2422 Assembly Language & System Programming September 26, 2006.
Assembly Language for x86 Processors 6th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
High-Level Language Interface Chapter 17 S. Dandamudi.
Chapter 2 Software Tools and Assembly Language Syntax.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 2: IA-32 Processor Architecture (c) Pearson Education, All rights reserved. You.
Assembly Language for x86 Processors 7th Edition
Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External 2. The type.
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.
Lecture 18 Structures and Macros Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
High-Level Language Interface Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/15 with slides by Kip Irvine.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 12: High-Level Language Interface (c) Pearson Education, All rights reserved.
Chapter 12: High-Level Language Interface. 2 Why Link ASM and HLL Programs? Use high-level language for overall project development Relieves programmer.
Today’s topics Procedures Procedures Passing values to/from procedures Passing values to/from procedures Saving registers Saving registers Documenting.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Sahar Mosleh California State University San MarcosPage 1 Stack operations, Applications and defining procedures.
CSC 221 Computer Organization and Assembly Language
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Assembly Language for x86 Processors 7th Edition
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 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
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.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language.
NASM ASSEMBLER & COMPILE WITH GCC 어셈러브 refered to ‘PC Assembly Language’ by Paul A. Carter
Suffolk County Community College Mathematics and Computer Science Ammerman Campus CST 121Spring 2013 Section 151CRN: Computer Organization And System.
CSC 221 Computer Organization and Assembly Language
Writing Functions in Assembly
Assembly Language for x86 Processors 6th Edition
Chapter7 Structure & C++
Assembly Language for x86 Processors 6th Edition
Writing Functions in Assembly
High-Level Language Interface
Assembly Language for Intel-Based Computers, 5th Edition
Stack Frames and Advanced Procedures
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Multi-modules programming
Assembly Language for Intel-Based Computers, 4th Edition
Other Processors Having learnt MIPS, we can learn other major processors. Not going to be able to cover everything; will pick on the interesting aspects.
Computer Architecture and System Programming Laboratory
Presentation transcript:

Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (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. Slide show prepared by the author Revision date: 1/15/2014 Kip R. Irvine

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Chapter Overview Introduction Inline Assembly Code Linking 32-Bit Assembly Language Code to C/C++

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Why Link ASM and HLL Programs? Use high-level language for overall project development Relieves programmer from low-level details Use assembly language code Speed up critical sections of code Access nonstandard hardware devices Write platform-specific code Extend the HLL's capabilities

Irvine, Kip R. Assembly Language for x86 Processors 7/e, General Conventions Considerations when calling assembly language procedures from high-level languages: Both must use the same naming convention (rules regarding the naming of variables and procedures) Both must use the same memory model, with compatible segment names Both must use the same calling convention

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Calling Convention Identifies specific registers that must be preserved by procedures Determines how arguments are passed to procedures: in registers, on the stack, in shared memory, etc. Determines the order in which arguments are passed by calling programs to procedures Determines whether arguments are passed by value or by reference Determines how the stack pointer is restored after a procedure call Determines how functions return values

Irvine, Kip R. Assembly Language for x86 Processors 7/e, External Identifiers An external identifier is a name that has been placed in a module’s object file in such a way that the linker can make the name available to other program modules. The linker resolves references to external identifiers, but can only do so if the same naming convention is used in all program modules.

Irvine, Kip R. Assembly Language for x86 Processors 7/e, What's Next Introduction Inline Assembly Code Linking 32-Bit Assembly Language Code to C/C++

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Inline Assembly Code Assembly language source code that is inserted directly into a HLL program. Compilers such as Microsoft Visual C++ and Borland C++ have compiler-specific directives that identify inline ASM code. Efficient inline code executes quickly because CALL and RET instructions are not required. Simple to code because there are no external names, memory models, or naming conventions involved. Decidedly not portable because it is written for a single platform.

Irvine, Kip R. Assembly Language for x86 Processors 7/e, _asm Directive in Microsoft Visual C++ Can be placed at the beginning of a single statement Or, It can mark the beginning of a block of assembly language statements Syntax: __asm statement __asm { statement-1 statement-2... statement-n }

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Commenting Styles mov esi,buf ; initialize index register mov esi,buf // initialize index register mov esi,buf /* initialize index register */ All of the following comment styles are acceptable, but the latter two are preferred:

Irvine, Kip R. Assembly Language for x86 Processors 7/e, You Can Do the Following... Use any instruction from the Intel instruction set Use register names as operands Reference function parameters by name Reference code labels and variables that were declared outside the asm block Use numeric literals that incorporate either assembler-style or C-style radix notation Use the PTR operator in statements such as inc BYTE PTR [esi] Use the EVEN and ALIGN directives Use LENGTH, TYPE, and SIZE directives

Irvine, Kip R. Assembly Language for x86 Processors 7/e, You Cannot Do the Following... Use data definition directives such as DB, DW, or BYTE Use assembler operators other than PTR Use STRUCT, RECORD, WIDTH, and MASK Use the OFFSET operator (but LEA is ok) Use macro directives such as MACRO, REPT, IRC, IRP Reference segments by name. (You can, however, use segment register names as operands.)

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Register Usage In general, you can modify EAX, EBX, ECX, and EDX in your inline code because the compiler does not expect these values to be preserved between statements Conversely, always save and restore ESI, EDI, and EBP. See the Inline Test demonstration programSee the Inline Test demonstration program.

Irvine, Kip R. Assembly Language for x86 Processors 7/e, File Encryption Example Reads a file, encrypts it, and writes the output to another file. The TranslateBuffer function uses an __asm block to define statements that loop through a character array and XOR each character with a predefined value. View the Encode2.cpp program listing

Irvine, Kip R. Assembly Language for x86 Processors 7/e, What's Next Introduction Inline Assembly Code Linking 32-Bit Assembly Language Code to C/C++

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Linking Assembly Language to Visual C++ Basic Structure - Two Modules The first module, written in assembly language, contains the external procedure The second module contains the C/C++ code that starts and ends the program The C++ module adds the extern qualifier to the external assembly language function prototype. The "C" specifier must be included to prevent name decoration by the C++ compiler: extern "C" functionName( parameterList );

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Name Decoration HLL compilers do this to uniquely identify overloaded functions. A function such as: int ArraySum( int * p, int count ) would be exported as a decorated name that encodes the return type, function name, and parameter types. For example: int_ArraySum_pInt_int The problem with name decoration is that the C++ compiler assumes that your assembly language function's name is decorated. The C++ compiler tells the linker to look for a decorated name. C++ compilers vary in the way they decorate function names.

Irvine, Kip R. Assembly Language for x86 Processors 7/e, Summary Use assembly language top optimize sections of applications written in high-level languages inline asm code linked procedures Naming conventions, name decoration Calling convention determined by HLL program OK to call C functions from assembly language

Irvine, Kip R. Assembly Language for x86 Processors 7/e, The End