Chapter 11 Interfacing C and Assembly Code

Slides:



Advertisements
Similar presentations
Chapter 19 Fast Fourier Transform (FFT) (Theory and Implementation)
Advertisements

Chapter 7 Linear Assembly
Chapter 14 Finite Impulse Response (FIR) Filters
Chapter 15 Infinite Impulse Response (IIR) Filters
Introduction to C++ An object-oriented language Unit - 01.
Chapter 9 Bootloader.
Chapter 20 This chapter provides a series of applications. There is no daughter cards with the DSK6713 and DSK6416 Part 1: Applications using the PCM3003.
Chapter 18 Discrete Cosine Transform. Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter 18, Slide 2 Learning Objectives  Introduction.
Chapter 20 This chapter provides a series of applications. There is no daughter cards with the DSK6713 and DSK6416 Part 1: Applications using the PCM3003.
Chapter 16 Adaptive Filters
OPTIMIZING C CODE FOR THE ARM PROCESSOR Optimizing code takes time and reduces source code readability Usually done for functions that are critical for.
Details.L and.S units TMS320C6000 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004.
TMS320C6000 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Architectural Overview.
TMS320C6713 Assembly Language (cont’d). Module 1 Exam (solution) 1. Functional Units a. How many can perform an ADD? Name them. a. How many can perform.
Assembly and Linear Assembly Evgeny Kirshin, 05/10/2011
Chapter 5 Enhanced Direct Memory Access (EDMA). Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter 5, Slide 2 Learning Objectives.
Introduction to Assembly language
Carnegie Mellon Lecture 7 Instruction Scheduling I. Basic Block Scheduling II.Global Scheduling (for Non-Numeric Code) Reading: Chapter 10.3 – 10.4 M.
TMS320C6000 Architectural and Programming Overview.
Chapter 14 Finite Impulse Response (FIR) Filters.
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
Chapter 6 Multi-channel Buffered Serial Port (McBSP)
TMS320C6000 Architectural Overview.  Describe C6000 CPU architecture.  Introduce some basic instructions.  Describe the C6000 memory map.  Provide.
Loops, and sub-routines Interrupts Can be very useful in control applications particularly when the microprocessor must perform two tasks apparently.
Review of Blackfin Syntax Moves and Adds 1) What we already know and have to remember to apply 2) What we need to learn.
Chapter 17 Goertzel Algorithm Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 17, Slide 2 Learning Objectives  Introduction.
Chapter 9 Bootloader. Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 9, Slide 2 Learning Objectives  Need for a bootloader.
Chapter 15 Infinite Impulse Response (IIR) Filters.
Chapter 12: High-Level Language Interface. Chapter Overview Introduction Inline Assembly Code C calls assembly procedures Assembly calls C procedures.
Chapter 2.3 : Interprocess Communication
Chapter 19 Fast Fourier Transform (FFT) (Theory and Implementation)
Chapter 11 Interfacing C and Assembly Code. Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 2 Learning Objectives 
Introduction to Code Generation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Chapter 7 Linear Assembly. Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 7, Slide 2 Learning Objectives  Comparison of programming.
Chapter 10 Interrupts. Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 10, Slide 2 Learning Objectives  Introduction to interrupts.
Inner Classes. Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class Inner classes.
CS2422 Assembly Language & System Programming November 7, 2006.
High-Level Language Interface Chapter 13 S. Dandamudi.
Storage Classes.
Chapter 2 Practice.
Mex. Introduction to MEX MEX = Matlab EXecutable – Dynamically Linked Libraries – Used like a.m function – Written in C (or Fortran)
Microprocessor and Interfacing PIC Code Execution
1 GCC Inline Assembly (asm) Example 1 : assignment System oriented Programming, B. Hirsbrunner, diuf.unifr.ch/pai/spSession 14 – 26 May 2015 Ref: B. Hirsbrunner:
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
CE-2810 Dr. Mark L. Hornick 1 Mixing C and assembly Safety goggles on!
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
ECSE436 Tutorial Assembly and Linear Assembly Laurier Boulianne.
Chapter 4 DSP/BIOS. DSP/BIOS Part 1 - Introduction.
Chapter 8 Exercises.
Chapter 7 Linear Assembly
Overview of Compilation The Compiler BACK End
High-Level Language Interface
L7 – Assembler Directives
Sample Presentation. Slide 1 Info Slide 2 Info.
In this lecture Global variables Local variables System stack
Chapter 4 Procedural Methods.
Introduction to the C Language
Chapter 11 Interfacing C and Assembly Code
Overview of Compilation The Compiler BACK End
Unit-1 Introduction to Java
Chapter 1: Introduction
EECE.3170 Microprocessor Systems Design I
Assembly Language Review
EECE.3170 Microprocessor Systems Design I
Chapter 7 Procedural Methods.
Inner Classes.
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
The ‘asm’ construct An introduction to the GNU C/C++ compiler’s obscure syntax for doing inline assembly language.
Presentation transcript:

Chapter 11 Interfacing C and Assembly Code

Learning Objectives Different methods exist for interfacing C and assembly code: Calling assembly from C. Interrupt calling assembly routine. Intrinsics. Programming requirements when interfacing code.

Introduction This chapter shows how to interface C and assembly and how to use intrinsics. As a general rule the code written in C is used for initialisation and for non-critical (in terms of speed or size) code. Critical code (in terms of speed/size) can be written in assembly or linear assembly. There are three different ways to interface C and assembly code: (1) C code call to the assembly function. (2) An interrupt can call an assembly function. (3) Call an assembly instruction using intrinsics.

Calling Assembly from C main () { y = asmFunction (a, b); } _asmFunction b b3 The C and assembly functions share the same resources (e.g. registers). The C and assembly functions may exchange data. Therefore code interfacing requires a means of handing-off data and control info and some rules of handling shared registers.

Calling Assembly from C main_c.c int asm_Function (short, short); short x = 0x4000, y = 0x2000; int z; void main (void) { z = asm_Function (x, y); } Use “_” underscore in assembly for all variables or functions declared in C. Labels also need to be global. asm_Function.c int asm_Function (short a, short b) { int y; y = (a * b) << 1; return y; } asm_Function.asm .global _asm_Function

Passing Arguments between C and Assembly arg1/r_val arg3 arg5 arg7 arg9 ret addr arg2 arg4 arg6 arg8 arg10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 The following registers are used to pass and return variables when calling an assembly routine from C.

Passing Arguments between C and Assembly 0x4000 0x2000 4 5 6 7 8 A B Before assembly call. After return from assembly call. 0x8000 0x2000 4 5 6 7 8

Passing Arguments between C and Assembly Problem: The C code will use some or all of the registers. The assembly code may also require the use of some or all registers. If nothing is done then on return to the C code some of the values may have been destroyed by the assembly code.

Passing Arguments between C and Assembly Solution: Both the C code and assembly code are responsible for saving some registers if they need to use them. A B 1 2 3 C code automatically saves these registers 4 5 6 7 8 9 Assembly code must save these registers - responsibility of the programmer 10 11 12 13 14 15

Interfacing C and Assembly Examples Setup code written in C and interfaced with critical code written in assembly can be found in the following chapters: \Code\Chapter 14 - Finite Impulse Response Filters \Code\Chapter 16 - Adaptive Filters Setup code written in C and interfaced with critical code written in linear assembly can be found in the following chapters: \Code\Chapter 15 - Infinite Impulse Response Filters \Code\Chapter 17 - Goertzel Algorithm

Chapter 11 Interfacing C and Assembly Code - End -