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.

Slides:



Advertisements
Similar presentations
Chapter 9 Technicalities: Classes, etc. Bjarne Stroustrup
Advertisements

C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
Passing by-value vs. by-reference in ARM by value C code equivalent assembly code int a;.section since a is not assigned an a:.skip initial.
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
LCS Non-Dynamic Version int function lcs (x, y, i, j) begin if (i = 0) or (j = 0) return 0; else if (x[i] = y[j]) return lcs(x, y, i-1, j-1)+1; else return.
Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands.
Lab 8 User Defined Function.
Win32 Programming Lesson 4: Classes and Structures.
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
IP high IP low IP high IP low BP high BP low IP high IP low BP high BP low FL high FL low CS high CS low IP high IP low _TEXTsegment byte public ‘CODE’
How to create your library 井民全製作. Select a library type  Win32 Dynamic-Link Library  Win32 Static Library 1 2.
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.
Position Independent Code self sufficiency of combining program.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
Apache Exploits
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.
PC-technology MASM and Inline Code in C. PC-Teknik © CAAK2 MASM and Inline Code in C Some things to think about –Which size has the register you use AX,
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Copyright  Hannu Laine C++-programming Part 2 Hannu Laine.
C Functions Pepper. Objectives Create functions Function prototypes Parameters – Pass by value or reference – Sending a reference Return values Math functions.
Recitation 6 – 2/26/01 Outline Linking Exam Review –Topics Covered –Your Questions Shaheen Gandhi Office Hours: Wednesday.
ICS312 Set 14 MACROS. Macros The program structure is similar to that for procedures. As for procedure names, macro names represent a group of instructions.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 22: Unconventional.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
#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.
LOW vs. HIGH Level Languages
1 MIPS Assembly Language Programming CDA 3101 Discussion Section 04.
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
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.
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
Binary Context-Sensitive Recognizer (BCSR) Hong Pham December 4, 2007.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Practical Session 3.
Assembly function call convention
Instruction Set Architecture
Ex-1 #include <stdio.h> struct sample { int a=0; char b='A';
Assembly Language Lab 9.
C function call conventions and the stack
“Studying C programming excluding pointers is meaningless.” d0m3z
Exploiting & Defense Day 2 Recap
Chapter7 Structure & C++
Structs versus Classes
High-Level Language Interface
Computer Architecture and Assembly Language
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Stack Memory 2 (also called Call Stack)
Memory Segments Code (.code) Data (.data) Stack Heap
Assembly Language Programming II: C Compiler Calling Sequences
EECE.3170 Microprocessor Systems Design I
Introduction to Programming
Multi-modules programming
Lecture 2 SCOPE – Local and Global variables
EECE.3170 Microprocessor Systems Design I
Introduction to Programming
X86 Assembly Review.
In C Programming Language
Low-Level Thread Dispatching on the x86
Displaying Memory/Files
“Way easier than when we were students”
ICS51 Introductory Computer Organization
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

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 the value of var in EAX

Accessing C or C++ Data in __asm Blocks Structure struct first_type { char *weasel; int same_name; }; struct second_type { int wonton; long same_name; }; struct first_type hal; struct second_type oat; void main(){ __asm{ mov ebx,offset hal mov eax,[ebx] weasel mov ebx,hal.same_name } // 狡滑的人 See AccessStructure.docAccessStructure.doc

Accessing C or C++ Data in __asm Blocks class See 03AccessClassDataMember.doc03AccessClassDataMember.doc

Calling C Function An __asm block can call C functions, including C library routines printf("%s %s\n","Hello","world"); See: Example1.cppExample1.cpp

Calling the User Defined Function int max(int a, int b) void main() { int a=1,b=2; int result; __asm{ push b push a call max pop ebx } int max(int a, int b) { return (a>b)?a:b; } But, how to get the return value ?

How to get the return value? int test(); void main() { __asm{ call test } int test() { int a=0x12; return a; } What ’ s happen in assembly Language?

Calling User Defined Function Observing the assembly The disassembly window

int max(int a, int b) void main() { int a=1,b=2; int result; __asm{ push b push a call max pop ebx mov result, eax } printf( “ result =%d ”,result); } int max(int a, int b) { return (a>b)?a:b; } Call_UserDefinedFunction.cpp

Calling C++ Function __asm block can only call global C++ functions that are not overloaded Cann ’ t call c++ member function