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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Harisha M GEngineerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Assembly

From novice to tech pro — start learning today.