Hello guys.

I currently code in C++.But I want to gain knowledge of internals of C++.So , I want to analyse my each and every program in ASM.

I use Windows 7 platform and code::blocks.Please provide necessary information or tools , which can help me in this regard.

Thanks!

Dani AI

Generated

Short primer that pulls the pieces together and adds a practical workflow.

As suggested, the compiler can emit assembly; as noted, Code::Blocks accepts extra compiler flags in Project → Build options → Compiler settings → Other options. For a repeatable workflow, put the flags you want there (per-configuration) and rebuild the whole project so every translation unit is recompiled with the new flags. ()

Recommended iterative workflow: (1) build a debug-friendly version so the assembly maps to your source (enable debug info and use minimal/no optimization); (2) inspect that assembly; (3) then rebuild with optimization enabled to see what real-world code looks like. Use -g and a low optimization level (or the debugging-friendly -Og) to get the best correspondence; later compare against -O2/-O3 to study inlining, register allocation and other transforms. Rebuilding after changing flags is essential. (gcc.gnu.org)

Tools and quick commands to try from a developer prompt: use the GNU objdump family to disassemble object files and executables and switch to Intel syntax if you prefer (-M intel), or ask the tool to intermix source lines when debug info is present. On Windows with MSVC you can ask the compiler to emit a listing (/FA) or use dumpbin /DISASM to disassemble a PE; both approaches are useful when you cannot or do not want to produce raw .s files. These let you inspect per-unit assembly or the final linked code. (sourceware.org)

For fast experimentation, paste small functions into Compiler Explorer (Godbolt) to compare compilers, flags and assembly side-by-side. For deeper static analysis and decompilation of linked binaries try Ghidra or a commercial disassembler when you need call-graph, cross-references and higher-level views. Watch out for optimizations (inlining, tail calls, constant folding) that make one-to-one mapping to source impossible — so compare both unoptimized and optimized builds to learn what the compiler actually does. (assembly.godbolt.org)

Troubleshooting tip: if line numbers or source intermixing are missing, confirm the binary contains debug symbols (do not strip them) and rebuild from a clean build.

Recommended Answers

All 3 Replies

g++ -S foo.cpp will produce a foo.s file, which is the ASM code corresponding to your source code.

If you use custom makefiles in c::b, you might be able to generate them automatically.

Thanks for reply.But please explain how I produce asm code through that command.I mean where to put that command in c::b , as I always use "run and build" button.

Thanks for reply.But please explain how I produce asm code through that command.I mean where to put that command in c::b , as I always use "run and build" button.

"Project" menu > "Build Options..." item > "Compiler settings" tab > "Other options" sub-tab > Add compiler options to the text area.

What you type in depends on your compiler. If you're using GCC, try "-save-temps"--it will both compile your program and preserve the generated assembly files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.