raashid bhatt wrote:
i am compiling my c program with MSVC its just a simple program
int main()
{
int a;
++a; // INC assembly instruction
return 0; // RET instruction
}
then i compile it
cl /O1 /c sample.c
link /SUBSYSTEM:CONSOLE /ENTRY:main /NODEFAULTLIB sample.obj
i compiled the program with the removal of libc but when i disassemble
the program i dont get the INC instruction
i only get this
XOR EAX,EAX
RET
Rather than
INC ADDRESS_OF_VAR
RET
The compiler detects that the increment of 'i' has no effect whatsoever
and optimises it away. C compilers have become so good these days that
expecting them to produce the same sort of output that an assembler
beginner might produce is unrealistic. If you want to learn assembler
then do so with a proper assembler and necessary pedagogic material.
Examining the output of modern C compilers will quickly get *very*
confusing, even with optimisations disabled. Compiler assembler output
is not meant for beginners.
Anyway, to get the compiler to actually increment 'i' qualify it as
volatile. This will suppress all optimisations on it.
volatile int i;
int main(void) {
i++;
return 0;
}