#include "dump.h" int main ( int argc, char* argv[] ) { __asm { mov eax, 1// init eax to 1 mov ebx, esp; keep a copy of esp mov ecx, 3/* init ecx to 3.

Slides:



Advertisements
Similar presentations
Mohamed. M. Saad.  Java Virtual Machine Prototype based on Jikes RVM  Targets  Code profiling/visualization using execution flow  Utilize large number.
Advertisements

Mohamed M. Saad & Mohamed A. Mohamedin.  Static Execution Graph  Nodes; can be either ▪ Basic Blocks; a sequence of non-branching instructions ▪ Variables.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
CS 153: Concepts of Compiler Design November 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code.
1 Homework / Exam Turn in mp2 at start of class today Reading –PAL, pp 3-6, Exam #1 next class –Open Book / Open Notes –NO calculators or other.
Lab6 – Debug Assembly Language Lab
Lab 9 Java Bytecode & The Jasmin Assembler
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
Accessing parameters from the stack and calling functions.
IPT Readings on Instrumentation, Profiling, and Tracing Seminar presentation by Alessandra Gorla University of Lugano December 7, 2006.
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.
Position Independent Code self sufficiency of combining program.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Code Generation Introduction. Compiler (scalac, gcc) Compiler (scalac, gcc) machine code (e.g. x86, arm, JVM) efficient to execute i=0 while (i < 10)
Chapter 2 Software Tools and Assembly Language Syntax.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Application Security Tom Chothia Computer Security, Lecture 14.
CSCI 273: Processing An Introduction. Programming Languages –An abstract "human understandable" language for telling the computer what to do –The abstract.
The Java Virtual Machine 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
CSE 219 Computer Science III Performance & Optimization.
1 Introduction to JVM Based on material produced by Bill Venners.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
1 CPSC 185 Introduction to Computing The course home page
Comparing and Branching ifs and loops part A. JMP instruction Consider the forever loop: for ( ; ; ) { … } How can we accomplish this in Assembler?
CSCI Processing CSCI Introduction to Algorithm Design An Introduction.
Introduction to Information Security מרצים : Dr. Eran Tromer: Prof. Avishai Wool: מתרגלים : Itamar Gilad
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
CS Software Studio Java Lab 1 Meng-Ting Wang PLLAB, Computer Science Department, National Tsing-Hua University.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 22: Unconventional.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?
Runtime System CS 153: Compilers. Runtime System Runtime system: all the stuff that the language implicitly assumes and that is not described in the program.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 18: Code Safety and Virtual Machines
CS 153: Concepts of Compiler Design November 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design November 18 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Compiler Construction Code Generation Activation Records
20-Feb-16 javap. Bytecode Java is compiled into bytecode, which is intermediate between Java and a “real” assembly language To implement Java, it is only.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Inline Assembly 井民全. Accessing C or C++ Data in __asm Blocks An __asm block can refer to any symbols Including variable name Ex: __asm mov eax, var Store.
Review on Program Challenge CSc3210 Yuan Long.
Recap: Printing Trees into Bytecodes To evaluate e 1 *e 2 interpreter –evaluates e 1 –evaluates e 2 –combines the result using * Compiler for e 1 *e 2.
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Debugging Survival Guide (x86-DSG) Divyanand Kutagulla
Computer Architecture and Assembly Language
CS216: Program and Data Representation
Other Processors.
Exploiting & Defense Day 2 Recap
Homework In-line Assembly Code Machine Language
High-Level Language Interface
Assembly Language Programming V: In-line Assembly Code
Introduction to Algorithm Design
Assembly Language Programming II: C Compiler Calling Sequences
Lecture 19: 0xCAFEBABE (Java Byte Codes) CS201j: Engineering Software
Byte Code Verification
Course Overview PART I: overview material PART II: inside a compiler
CS 153: Concepts of Compiler Design November 6 Class Meeting
CSC235 - Visual Studio Tutorial
CMPE 152: Compiler Design April 16 Class Meeting
ICS51 Introductory Computer Organization
CMPE 152: Compiler Design April 18 Class Meeting
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
The ‘asm’ construct An introduction to the GNU C/C++ compiler’s obscure syntax for doing inline assembly language.
Presentation transcript:

#include "dump.h" int main ( int argc, char* argv[] ) { __asm { mov eax, 1// init eax to 1 mov ebx, esp; keep a copy of esp mov ecx, 3/* init ecx to 3 */ mov edx, 4; init edx to 4 } dump(); //show reg contents return 0; } provided by me, your kind professor

The VC++ inline Assembler is only a small subset of MASM. What's allowed: 1. line labels must always end with : 2. instruction opcodes and operands 3. comments (both ; and C-style) 4. align and even simply inserts NOPs, if necessary 5. length, size, and type 6. references to C variables & functions

The VC++ inline Assembler is only a small subset of MASM. What's not allowed: 1. data definitions(use C++ instead) 2. macros(use C++ instead) 3. conditional assembly(use C++ instead) 4. local line labels 5. and much, much more

While debugging...  We can view our inline Assembler!  We can also see the Assembler code generated by the compiler corresponding to our C code!

 Assembler generated from the same C/C++ source code is different for Debug and Release versions!  Release version is optimized but doesn’t contain any debugging information.  Check size of debug and release.exe’s. (They are different!)  Turn on generation of Assembler listing (.cod) files and take a look.

 This is very instructive: 1. for learning Assembler 2. as a starting point for improvement (optimization)

 In Microsoft Visual C Express, 1. Turn on expert mode. Tools  Settings  Expert settings 2. Set a breakpoint in your program. 3. Start debugging your program. 4. View disassembly and registers. Debug  Windows  Disassembly Debug  Windows  Registers To display f.p. or XMM registers, right-click in Registers window.

#include clock_t start = clock(); for (int i=0; i<N; i++) { __asm { ; do something useful } clock_t delta = clock() - start; double elapsed = ((double)delta) / CLOCKS_PER_SEC; printf( "elapsed = %f sec (%d ticks) \n", elapsed, delta ); printf( " " ); getchar();

 AMD CodeAnalyst ( /Pages/default.aspx)  ats-the-best-free-c-profiler-for-windows-if- there-are

 javap (javap.exe)  JDK program used to disassemble.class files.  Steps: 1. Compile first (using javac) to produce.class file(s). 2. Then javap –verbose Test (to disassemble Test.class).

 javap example class Test { public static void main ( String[] args ) { for (int i=0; i<10; i++) { System.out.printf( "i = %d \n", i ); } … public static void main(java.lang.String[]); Code: Stack=6, Locals=2, Args_size=1 0:iconst_0 1:istore_1 2:iload_1 3:bipush10 5:if_icmpge34 8:getstatic#2; //Field java/lang/System.out:Ljava/io/PrintStream; 11:ldc#3; //String i = %d \n 13:iconst_1 14:anewarray#4; //class java/lang/Object 17:dup 18:iconst_0 19:iload_1 20:invokestatic#5; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 23:aastore 24:invokevirtual#6; //Method java/io/PrintStream.printf:(Ljava/lang/String;[Ljava/lang/Object;)Ljava/io/PrintStream; 27:pop 28:iinc1, 1 31:goto2 34:return …

 use System class for timing:  System.currentTimeMillis() returns (a long) the current time in milliseconds  System.nanoTime() returns (a long) the current value of the most precise available system timer, in nanoseconds but may be wrong for timing longer algorithms (Why?)

 utilties.asm contains:  call dump shows the contents of registers  call rand8 returns a random number in eax in the range [0..255]  call resetTime sets elapsed time timer back to zero  call reportTime reports elapsed time in milliseconds