
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What are the 4 steps to convert C program to Machine code?
Process of Creating and Running Programs
A program contains a set of instructions which was written in a programming language.
The programmer’s job is to write and test the program.
The 4 steps to convert a ‘C’ program into machine language are &miuns;
- Writing and editing the program
- Compiling the program
- Linking the program
- Executing the program
Writing and editing the program
‘Text editors’ are used to write programs.
With the help of text editors, users can enter, change and store character data.
All special text editors are often included with a compiler.
After writing the program, the file is saved to disk.
It is known as ‘source file’.
This file is input to the compiler.
Compiling the program
“Compiler” is a software that translates the source program into machine language.
The ‘C’ compiler is divided into two separate programs.
- Preprocessor
- Translator
Let us first see about Preprocessor −
Preprocessor
Preprocessor reads the source code and then prepares it for translator.
Preprocessor commands start with ‘#’ symbol.
They tell the preprocessor to look for special code libraries and make substitutions.
The result of preprocessing is known as ‘translation’ unit.
Translator
Translator’s work is to convert the program into machine language.
It reads the translation unit and results in ‘object module’.
But it is not completely executable file because it does not have the ‘C’ and other functions included.
Linking programs
‘Linker’ assembles I/O functions, some library functions and the functions that are part of source program into final executable program.
Executing Programs
‘Loader’ is the software that is ready for program execution into the memory.
In the process of execution, the program reads the data from the user, processes the data and prepares the output.
Example1
Following example is to find the average of 3 numbers −
#include<stdio.h> int main(){ int a,b,c,d; //declaring 4 variables float e; printf("Enter values of a,b,c:"); scanf("%d,%d,%d",&a,&b,&c); //read 3 input values from keyboard d=a+b+c; e=d/3; printf("Average=%f",e); // printing the result return 0; }
Output
Enter values of a,b,c :2,4,5 Average=3.000000
Example2
The following is to compute circumference of a circle −
#include <stdio.h> #define PI 3.1415 // defining PI value main (){ float c,r; printf("Enter radius of circle r="); scanf("%f",&r); c=2*PI*r; printf("Circumference of circle c=%f", c); }
Output
Enter radius of circle r=5.6 Circumference of circle c=35.184799
- Related Articles
- Convert C/C++ program to Preprocessor code\n
- C++ Program to convert the Binary number to Gray code using recursion
- Java Program to convert ASCII code to String
- 8086 program to convert binary to Grey code
- Python Program to Convert Gray Code to Binary
- Python Program to Convert Binary to Gray Code
- C++ code to count steps to reach final position by robot
- What are the different steps involved to execute a Java program?
- Convert C/C++ code to assembly language
- Haskell Program to convert the Binary number to Gray code using recursion
- 8085 code to convert binary number to ASCII code
- What are the steps involved to use a CURSOR in any COBOL-DB2 program?
- 8085 program to convert 8 bit BCD number into ASCII Code
- Program to convert gray code for a given number in python
- What are the steps to rename a file in Git?
