Review: how the program compilation process works

This is what happens when you compile a high level language program:

Compile-time versus run-time events

Compile-time events happen during the translation of a source program (Java, C, etc) to machine code:

Translation of constants used inside source program is a compile-time event

Recall: the compiler will translate all integer constants (represented in ASCII code) in the source program into 2s complement representation:

Review of DEMO: The compiler will translate all integer numbers to their 2s complement code !!

Example C program:

   int x;
    
   int main( )
   {
      x = 15;
      x = x + 7;                     
   }
   

Compile the program and do a hex dump of the compiled code with these UNIX commands:

   gcc -c  prog.c

   objdump  -d  prog.o
   

DEMO: /home/cs255001/demo/c-asm/2s-compl.c

Review: The compiler will translate all integer numbers to their 2s complement code !!

Example C program:

   int x;
    
   int main( )
   {
      x = 15;    // ASCII code string "15"
      x = x + 7;                     
   }
   

The hex-dump shows that the ASCII string "15" is translated into the 2s complement code 00000000 00000000 00000000 00001111:

   4:	c7 05 00 00 00 00 0f 	movl   $0xf,0x0(%rip) 
   b:	00 00 00 
   

DEMO: /home/cs255001/demo/c-asm/2s-compl.c