I\'m currently working on a homework problem that asks me to find out the number of machine code instructions that are executed when running a short program I wrote in C.
You can use Godbolt's Compiler Explorer to compile your program and display the assembly code for various compilers and options.
Then count the number of instructions for every fragment, ie: sequence of statements upto and including the first test.
Then instrument you code: add a global variable instruction_count
, initialized to the number of instructions in the main
function epilog and increment this variable at the beginning of each fragment by the number of instructions you counted in the previous step. and print this number just before returning from the main
function.
You will get the number of instructions that would be executed by the uninstrumented program for whatever input is provided to the program, for a given combination of architecture, compiler and options, but not including instructions executed in library functions nor during the startup and exit phases.