What happens internally when I compile my C program? Please explain in depth.

C Language makes hardware connections based on the statements.
 Let us see this through the following example
 char a,b,c;
 a = 20;
 b = 30;
 c = a + b;
 The compiler convert the above program into Assembly language as follows. Assembly language varies between Microprocessor to Microprocessor. Let us assume some general Microprocessor'
 First the Compiler allocate 3 memory locations for variables a,b and c. Since a,b and c are char data type, system allocates 1 byte for each.
 a -> 3000
 b -> 3001
 c -> 3002
 This is called Symbol Table. 3000, 3001 and 3002 are address of the memory. This storage is physical. Then the compiler converts the other C code as follows
 MOV R0, 20
 ST R0,3000
 MOV R0,30
 ST R0,3001
 LD R0,3000
 LD R1,3001
 ADD R0,R1, R2
 ST R2, 3002
 R0,R1,R2 are also physical memory (register) inside the Microprocessor. Now the Assembler converts the above Assembly Language program into machine code. The Machine code varies between Microprocessor to Microprocessor. Now let us assume the code for the instructions as follows.
 MOV R0 -> 75
 ST R0 -> 65
 ST R1 -> 66
 ST R2 -> 67
 LD R0 -> 45
 LD R1 -> 46
 ADD R0,R1,R2 -> 35
 This is also called Instructions Set.
 Now let us see the the output of the assembler by replacing the Assembly code by Machine code (opcode).
 75 20
 65 30 00
 75 30
 65 30 01
 45 30 00
 46 30 01
 35
 67 30 02
 The opcodes are stored in Memory as binary. The Microprocessor read the above code and perform the operation based on the code. The operations performed by the Microprocessor are connecting various components based on the requirements.
 Let us see how some of the above codes are executed by the Microprocessor.
 First Microprocessor fetches 75 from Memory. Then the control unit inside the microprocessor understand the function of opcode 75. So the control unit make the connection between external memory (3000) to internal memory R0 (Register R0).
 How these connections are made? The connections are made by controlling the Tri state switches. The Microprocessor manufacturer have already designed the control unit for what instruction which switches should be on.
 If the microprocessor executes the opcode 35 (ADD R0, R1 , R2). The control unit connects Register R0 and Register R1 to the inputs or Adder and connects R2 to the output of Adder.
————————————————————————————————-
C language is a Hardware. Every statement makes a
 Temporary circuit connection inside Microprocessor
C Language is nothing but Hardware. Every statement of C language makes few connections inside Microprocessor. Instead of a Soldering Technician, Microprocessor. Microprocessor connect the components based on a Code. That code is in Binary. So make thing simple for Electronic engineers, C language was created. The C compiler will convert the C language statements to Binary code, which Microprocessor understands.
In Electronics everything is circuit. Based on how we connect, they are classified as,
Fixed Circuit – Hardware – ASIC
Configurable Circuit – VLSI – FPGA
Programmable Circuit – Embedded – Microprocessor
Fixed Circuit – Implemented by the Manufacturer
Configurable Circuit – Connections are made before operation
Programmable Circuit – Temporary connections are made during operation.
Microprocessor is nothing but a collection of functional blocks kept inside an IC, which are not connected.Temporary connections are made by the programmer for every operation.
The answer to the following questions may be useful
 How can I make my c language basics strong?
How assignment work in C language?
What is the difference between float and double in C language? How is it stored in the memory?
 I hope this helps. If you need more detailed explanation write a comment.

Answer by Balajee Seshadri:

    I have already written answer for the following question.
                                           I have copied the answer below
   ———————————————————————————————
C Language makes hardware connections based on the statements.
Let us see this through the following example
char a,b,c;
a = 20;
b = 30;
c = a + b;
The compiler convert the above program into Assembly language as follows. Assembly language varies between Microprocessor to Microprocessor. Let us assume some general Microprocessor'
First the Compiler allocate 3 memory locations for variables a,b and c. Since a,b and c are char data type, system allocates 1 byte for each.
a -> 3000
b -> 3001
c -> 3002
This is called Symbol Table. 3000, 3001 and 3002 are address of the memory. This storage is physical. Then the compiler converts the other C code as follows
MOV R0, 20
ST R0,3000
MOV R0,30
ST R0,3001
LD R0,3000
LD R1,3001
ADD R0,R1, R2
ST R2, 3002
R0,R1,R2 are also physical memory (register) inside the Microprocessor. Now the Assembler converts the above Assembly Language program into machine code. The Machine code varies between Microprocessor to Microprocessor. Now let us assume the code for the instructions as follows.
MOV R0 -> 75
ST R0 -> 65
ST R1 -> 66
ST R2 -> 67
LD R0 -> 45
LD R1 -> 46
ADD R0,R1,R2 -> 35
This is also called Instructions Set.
Now let us see the the output of the assembler by replacing the Assembly code by Machine code (opcode).
75 20
65 30 00
75 30
65 30 01
45 30 00
46 30 01
35
67 30 02
The opcodes are stored in Memory as binary. The Microprocessor read the above code and perform the operation based on the code. The operations performed by the Microprocessor are connecting various components based on the requirements.
Let us see how some of the above codes are executed by the Microprocessor.
First Microprocessor fetches 75 from Memory. Then the control unit inside the microprocessor understand the function of opcode 75. So the control unit make the connection between external memory (3000) to internal memory R0 (Register R0).
How these connections are made? The connections are made by controlling the Tri state switches. The Microprocessor manufacturer have already designed the control unit for what instruction which switches should be on.
If the microprocessor executes the opcode 35 (ADD R0, R1 , R2). The control unit connects Register R0 and Register R1 to the inputs or Adder and connects R2 to the output of Adder.
————————————————————————————————-
C language is a Hardware. Every statement makes a
Temporary circuit connection inside Microprocessor
C Language is nothing but Hardware. Every statement of C language makes few connections inside Microprocessor. Instead of a Soldering Technician, Microprocessor. Microprocessor connect the components based on a Code. That code is in Binary. So make thing simple for Electronic engineers, C language was created. The C compiler will convert the C language statements to Binary code, which Microprocessor understands.
In Electronics everything is circuit. Based on how we connect, they are classified as,
Fixed Circuit – Hardware – ASIC
Configurable Circuit – VLSI – FPGA
Programmable Circuit – Embedded – Microprocessor
Fixed Circuit – Implemented by the Manufacturer
Configurable Circuit – Connections are made before operation
Programmable Circuit – Temporary connections are made during operation.
Microprocessor is nothing but a collection of functional blocks kept inside an IC, which are not connected.Temporary connections are made by the programmer for every operation.
The answer to the following questions may be useful
I hope this helps. If you need more detailed explanation write a comment.
Everything should be made as simple as possible, but not simpler.

What happens internally when I compile my C program? Please explain in depth.

Advertisements

Leave a comment

Filed under Life

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s