Download presentation
Presentation is loading. Please wait.
Published byCori Warren Modified over 9 years ago
2
#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
3
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
4
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
5
While debugging... We can view our inline Assembler! We can also see the Assembler code generated by the compiler corresponding to our C code!
9
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.
10
This is very instructive: 1. for learning Assembler 2. as a starting point for improvement (optimization)
11
In Microsoft Visual C++ 2010 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.
13
#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();
17
AMD CodeAnalyst (http://developer.amd.com/CPU/CODEANALYST /Pages/default.aspx) http://stackoverflow.com/questions/67554/wh ats-the-best-free-c-profiler-for-windows-if- there-are
19
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).
20
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 …
21
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?)
23
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.