How to write inline assembly language code inside C Program ?

January 11, 2025 No Comments » Hits : 288





Add Two Numbers Using Inline Assembly Language ???

#include<stdio.h>
void main()
{
int a=3,b=3,c;
   asm {
       mov ax,a
       mov bx,a
       add ax,bx
       mov c,ax
      }
printf("%d",c);
}

  1. Assembly Language can be Written in C .
  2. C Supports Assembly as well as Higher Language Features so called “Middle Level Language”.
  3. As shown in above Program , “asm” Keyword is written to indicate that “next followed instruction is from Assembly Language”.
asm mov ax,a
  1. Opening Curly brace after “asm” keyword tells that it is the “Start of Multiple Line Assembly Statements” i.e “We want to Write Multiple Instructions”
  2. Above Program Without “Opening and Closing Brace” can be written as - ["asm" keyword before every Instruction ]
asm mov ax,a
asm mov bx,a
asm add ax,bx
asm mov c,ax

What above Program Actually Does ?

  1. In 8086 Assembly Program for Storing Values AX,BX,CX,DX registers are used called General Purpose Registers .
asm mov ax,a
  1. Move Instruction Copies content of Variable “a” into Register “AX”
  2. Add Instruction adds Content of two specified Registers and Stores Result in “ax” in above example.
  3. Copy Result into Variable “c”

Incoming search terms: