High-Level Language Interface Chapter 13 S. Dandamudi.

Slides:



Advertisements
Similar presentations
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#3) By Dr. Syed Noman.
Advertisements

1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Azir ALIU 1 What is an assembly language?. Azir ALIU 2 Inside the CPU.
Chapter 8: Programming the Microprocessor. Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel.
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.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Chapter 12: High-Level Language Interface. Chapter Overview Introduction Inline Assembly Code C calls assembly procedures Assembly calls C procedures.
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.
High-Level Language Interface Chapter 17 S. Dandamudi.
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Introduction Chapter 1 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
An Introduction to 8086 Microprocessor.
Procedures and the Stack Chapter 10 S. Dandamudi.
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Universal Concepts of Programming Creating and Initializing local variables on the stack Variable Scope and Lifetime Stack Parameters Stack Frames Passing.
The Pentium Processor Chapter 3 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
The Pentium Processor Chapter 3 S. Dandamudi.
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.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Implementing function/ procedure calls (in Pascal and C)
5-1 Chapter 5 - Languages and the Machine Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of Computer.
Objective At the conclusion of this chapter you will be able to:
Introduction Chapter 1 S. Dandamudi. Outline A user’s view of computer systems What is assembly language? – Relationship to machine language Advantages.
Overview of Assembly Language Chapter 4 S. Dandamudi.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Strings, Procedures and Macros
Lecture 7 A closer look at procedures Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
ECE291 Lecture 6 Procedures and macros. ECE 291 Lecture 6Page 2 of 36 Lecture outline Procedures Procedure call mechanism Passing parameters Local variable.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
CE-2810 Dr. Mark L. Hornick 1 Mixing C and assembly Safety goggles on!
Overview of Assembly Language Chapter 4 S. Dandamudi.
Multi-module programming. Requirements of an assembly language module when it is linked with another module PUBLIC directive - it exports to other modules.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
ECE291 Computer Engineering II Lecture 8 Josh Potts University of Illinois at Urbana- Champaign.
Programming Fundamentals Enumerations and Functions.
Recursion Chapter 16 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language.
NASM ASSEMBLER & COMPILE WITH GCC 어셈러브 refered to ‘PC Assembly Language’ by Paul A. Carter
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Assembly language programming
Chapter 8: Programming the Microprocessor
Format of Assembly language
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
High-Level Language Interface
(The Stack and Procedures)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
CS 301 Fall 2002 Control Structures
Introduction to Assembly Language
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
LHO 15 C with assembly language
8086 Registers Module M14.2 Sections 9.2, 10.1.
(The Stack and Procedures)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Introduction Chapter 1 S. Dandamudi. Outline  A user’s view of computer systems  What is assembly language?  Relationship to machine language  Advantages.
Computer Architecture CST 250
(The Stack and Procedures)
Chapter 8: Instruction Set 8086 CPU Architecture
Presentation transcript:

High-Level Language Interface Chapter 13 S. Dandamudi

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 2 High-Level Language Interface Why program in mixed- mode?  Focus on C and assembly Overview of compiling mixed-mode programs Calling assembly procedures from C  Parameter passing  Returning values  Preserving registers  Publics and externals  Examples Calling C functions from assembly Inline assembly code

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 3 Why Program in Mixed-Mode? Pros and cons of assembly language programming  Advantages: »Access to hardware »Time-efficiency »Space-efficiency  Problems: »Low productivity »High maintenance cost »Lack of portability As a result, some programs are written in mixed- modem (e.g., system software)

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 4 Compiling Mixed-Mode Programs We use C and assembly mixed-mode programming  Our emphasis is on the principles Can be generalized to any type of mixed-mode programming To compile bcc sample1.c sample.asm

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 5 Calling Assembly Procedures from C Parameter Passing Stack is used for parameter passing Two ways of pushing arguments onto the stack  Left-to-right »Most languages including Basic, Fortran, Pascal use this method »These languages are called left-pusher languages  Right-to-left »C uses this method »These languages are called right-pusher languages

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 6 Calling Assembly Procedures from C (cont’d) Example: sum(a,b,c,d)

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 7 Calling Assembly Procedures from C (cont’d) Returning Values Registers are used to return values Return value typeRegister used char, short, intAX (signed/unsigned) longDX:AX (signed/unsigned) near pointerAX far pointerDX:AX

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 8 Calling Assembly Procedures from C (cont’d) Preserving Registers The following registers must be preserved BP, SP, CS, DS, SS In addition, if register variables are enabled, SI and DI should also be preserved. Since we never know whether register variables are enabled or not, it is a good practice to preserve BP, SP, CS, DS, SS, SI and DI

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 9 Calling Assembly Procedures from C (cont’d) Publics and External Mixed-mode programming involves at least two program modules »One C module and one assembly module We have to declare those functions and procedures that are not defined in the same module as external »extern in c »extrn in assembly Those procedures that are accessed by another modules as public

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 10 Calling Assembly Procedures from C (cont’d) Underscores In C, all external labels start with an underscore »C and C++ compilers automatically append the required underscore on all external functions and variables You must make sure that all assembly references to C functions and variables begin with underscores  Also, you should begin all assembly functions and variables that are made public and referenced by C code with underscores

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 11 Calling C Functions from Assembly Stack is used to pass parameters (as in our previous discussion)  Similar mechanism is used to pass parameters and to return values C makes the calling procedure responsible for clearing the stack of the parameters  Make sure to clear the parameters after the call instruction as in add SP,4 on line 45 in the example program

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 12 Inline Assembly Code Assembly language statements are embedded into the C code »Separate assembly module is not necessary Assembly statements are identified by placing the keyword asm asm xor AX,AX; mov AL,DH We can use braces to compound several assembly statements asm { xor AX,AX mov AL,DH }

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 13 Inline Assembly Code (cont’d) Example Get date interrupt service  Uses interrupt 21H service  Details: Input: AH = 2AH Returns: AL = day of the week (0=Sun, 1=Mon,…) CX = year ( ) DH = month (1=Jan, 2=Feb, …) DL = day of the month (1-31)

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 14 Inline Assembly Code (cont’d) Compiling inline Assembly Programs  TASM method »Convert C code into assembly language and then invoke TASM to produce.OBJ file »Can use -B compiler option to generate assembly file »Alternatively, can include #pragma inline at the beginning of the C file to instruct the compiler to use the -B option  BASM method »Uses the built-in assembler (BASM) to assemble asm statements »Restricted to 16-bit instructions (i.e., cannot use 486 or Pentium instructions)

2003 To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi Chapter 13: Page 15 Inline Assembly Code (cont’d) Last slide