Is there a C/C++ code --> ASM code chart ???
Hi,
I have seen a chart in this website, http://www.keil.com/support/man/docs...51_le_ptrs.htm which shows Assembly language equivalent of C code. In this case, it is for the 8051 CPU. Is there any such list available for the x86 based CPUs ??? for all C instructions ... |
I should think it would depend on how the compiler writer implemented the compiler, eh?
If you're using gcc, just look at the source code (most likely the parser) to see how the code is converted into CPU instructions. Of course, the actual conversion depends on the target CPU(s). That's why most compilers first compile to an "intermediate" code, then convert that to the actual hardware instructions. The first part can usually be done without reference to the target CPU. (I think that MS has done this with their C# compiler even more explicitly, making the first stage code exportable so the final implementation can be done "on the fly" by different CPUs as needed. [That, of course, is so they can "protect" the "Intelectual Property" of "owners" of the source code. But that's an issue for some other thread.]) |
There is no single list because the code generated is dependant on (at least), the compiler, the compiler version, optimization flags used, the processor being compiled for (486, pentium, athlon etc), and probably a number of other things that don't come to mind offhand. Compiling lists for all possible permutations would be a huge and pointless task. If you want to see the assembler for some specific code, then assemble it with gcc -S.
|
Quote:
...Then it has calls to "printf", for which the code is not present. How can I make see them too :scratch: Code:
#include <stdio.h> [HTML] Quote:
|
Quote:
1. Get the source for glibc and assemble it. 2. Compile your program and run it under gdb, linking to a glibc with debugging symbols, put a breakpoint on printf, then disassemble it. |
you can also just link it with -static and run objdump -d on your executable
|
Doh! Fumbled it (again). Why do I always forget about objdump? :o
OK, you have 3 choices, and counting.... Good catch, aluser. |
RipClaw -
Book recommendation: Professional Assembly Language, Richard Blum http://www.bookpool.com/sm/0764579010 It covers all the basics of x86 assembler, has some great insights into "less travelled" roads like FPU instructions and MMX extensions ... and does it all from a Linux perspective. Among other things, you'll learn how "printf" (a call into the standard C library) and actual system calls (like the "int 0x80" that corresponds to "open()" or "fork()") work surprisingly early on. Blum has written both a great primer, and a great reference text. I think you might like it. IMHO .. PSM |
All times are GMT -5. The time now is 05:38 AM. |