Assembly program in C


We can write assembly program code inside c language program. In such case, all the assembly code must be placed inside asm{} block.

Let's see a simple assembly program code to add two numbers in c program.

  1. #include<stdio.h>  
  2. void main() {  
  3.    int a = 10, b = 20, c;  
  4.    
  5.    asm {  
  6.       mov ax,a  
  7.       mov bx,b  
  8.       add ax,bx  
  9.       mov c,ax  
  10.    }  
  11.    
  12.    printf("c= %d",c);  
  13. }  

Output:

c = 30

Note: We have executed this program on TurboC.

Previous Post Next Post