assembly with in C

Is it possible to use assembly(ALP) code with in the C program?,if Yes ,give me the proceduer to do the same And whether there will be any problem with the exicution time,exicution time will be same as the ALP exicution time or it will be greater than that?
aeltechAsked:
Who is Participating?
 
DeanHorakCommented:
Placing inline assembler in your C program is non-standard and will vary depending on the C compiler you are using.

For Visual C++ the syntax is something like
int asmFunc() {
   /* Inline assembler */
  __asm {
                         MOV EAX,10h  
MYLABEL:   XOR ECX,ECX
  }
   return 0;
}

or alternatively

  __asm                        MOV EAX,10h
  __asm MYLABEL: XOR ECX,ECX

If you specify the C compiler you are usiing I can point you to further reference information.
0
 
Harisha M GCommented:
Hi,
> And whether there will be any problem with the exicution time,exicution
> time will be same as the ALP exicution time or it will be greater than that?

Only that part of the code, which is written in assembly will be faster. The other parts will take normal speed.


In Turbo C, you use

asm{
    // ALP code
}

or

asm statement1;
asm statement2;


Note:
asm and the following { should be on the same line, or else the Turbo C compiler gives error ! This is the only place where whitespaces are not ignored inside C code.

etc... and as DeanHorak said, VC++ uses __asm instead of asm. So it is highly compiler dependent and achitecture dependent. ie., you may not be able to run the same code on another Operatin System.

So use it when you really want to :)


---
Harish
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.