About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Wednesday, September 4, 2013

C Program to Write inline assembly language code in C Program

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”

No comments: