Chapter 11 Interfacing C and Assembly Code. Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 2 Learning Objectives 

Slides:



Advertisements
Similar presentations
Chapter 7 Linear Assembly
Advertisements

Chapter 11 Interfacing C and Assembly Code
Chapter 14 Finite Impulse Response (FIR) Filters
Chapter 15 Infinite Impulse Response (IIR) Filters
Chapter 9 Bootloader.
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Chapter 16 Adaptive Filters
Subroutines – parameter passing passing data to/from a subroutine can be done through the parameters and through the return value of a function subroutine.
Details.L and.S units TMS320C6000 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004.
The University of Adelaide, School of Computer Science
Templates in C++. Generic Programming Programming/developing algorithms with the abstraction of types The uses of the abstract type define the necessary.
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.
TMS320C6000 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Architectural Overview.
MIPS Calling Convention Chapter 2.7 Appendix A.6.
TMS320C6000 Architectural and Programming Overview.
Chapter 14 Finite Impulse Response (FIR) Filters.
Computer Architecture CSCE 350
TMS320C6000 Architectural Overview.  Describe C6000 CPU architecture.  Introduce some basic instructions.  Describe the C6000 memory map.  Provide.
Functions Functions and Parameters. History A function call needs to save the registers in use The called function will use the registers The registers.
Loops, and sub-routines Interrupts Can be very useful in control applications particularly when the microprocessor must perform two tasks apparently.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Constructors & An Introduction to Methods. Defining Constructor – Car Example Public class car { String Model; double speed; String colour; { Public Car.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
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.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
Chapter 19 Fast Fourier Transform (FFT) (Theory and Implementation)
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.
High-Level Language Interface Chapter 13 S. Dandamudi.
C++ for Engineers and Scientists Third Edition
Universal Concepts of Programming Creating and Initializing local variables on the stack Variable Scope and Lifetime Stack Parameters Stack Frames Passing.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Chapter 7 Evaluating the Instruction Set Architecture of H1: Part 1.
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.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 7 – Subroutines These are lecture notes to accompany the book SPARC Architecture,
Topic 9: Procedures CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Subroutines, parameters and the stack Bryan Duggan.
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!
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
CS1201: Programming Language 2 Function I By: Nouf Aljaffan Edited by : Nouf Almunyif.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Chapter 4 DSP/BIOS. DSP/BIOS Part 1 - Introduction.
Assembly Language with GCC
Chapter 8 Exercises.
Chapter 7 Linear Assembly
Chapter 7 Subroutines Dr. A.P. Preethy
Stack Memory 2 (also called Call Stack)
Chapter 11 Interfacing C and Assembly Code
Assembly Language Programming II: C Compiler Calling Sequences
Chapter 10 Interrupts.
EECE.3170 Microprocessor Systems Design I
by Richard P. Paul, 2nd edition, 2000.
Subroutines – parameter passing
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Subroutines … passing data
CHAPTER 2 Arrays and Vectors.
CHAPTER 2 Arrays and Vectors.
The C Language: Intro.
Chapter 9: Pointers and String
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
Presentation transcript:

Chapter 11 Interfacing C and Assembly Code

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 2 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.

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 3Introduction  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.

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 4 Calling Assembly from C  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. main () { y = asmFunction (a, b); } _asmFunction bb3

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

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 6 Passing Arguments between C and Assembly  The following registers are used to pass and return variables when calling an assembly routine from C. AB arg1/r_val arg3 arg5 arg7 arg9 ret addr arg2 arg4 arg6 arg8 arg

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 7 Passing Arguments between C and Assembly  Before assembly call. 0x40000x AB 0x80000x  After return from assembly call.

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 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.

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 9 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 AB C code automatically saves these registers Assembly code must save these registers - responsibility of the programmer

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2002 Chapter 11, Slide 10 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 -