In this blog we will learn how to convert c program to assembly language. To convert a c or c++ program to assembly language is a simple task. We will use gcc compiler to convert c program to assembly language on Linux based operating system like Ubuntu. Let see step by step instructions.

how to convert c program to assembly language ( Step by step )

Step 1) Open vim editor in Linux terminal

We can use any text editor but try to practice with vim Linux editor tool.

bosch@bosch-Inspiron-N5050:~$ vi sample.c

Step 2) Write C or c++ code in vim editor

how to convert c program to assembly language

Step 3) Save your c program on current working directory

When vi or vim editor opens it is in command mode. To change from command mode to insert mode press i button from keyboard. After writing your code you can save the code we have to press following sequence of button press.

  • Press Esc button. It will change the vi or vim editor from insert mode to command mode.
  • Press Shif + : ( it will open vim internal command prompt )
  • Type wq at vim command (:) and hit Enter button. it will save the code to the open file.

Step 4) Convert c program to assembly by following command

bosch@bosch-Inspiron-N5050:~$ gcc -S sample.c

After running command “gcc -S sample.c” we will get a new file named as sample.s which is assembly language program equivalent to sample.c source code. Let us see the contents of sample.s

bosch@bosch-Inspiron-N5050:~$ cat sample.s ( its output would be as below )

Video How to

Related Contents to follow