[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

assembly with in C

Posted on 2006-03-23
4
Medium Priority
?
384 Views
Last Modified: 2006-11-18
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?
0
Comment
Question by:aeltech
2 Comments
 
LVL 11

Accepted Solution

by:
DeanHorak earned 100 total points
ID: 16271989
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
 
LVL 37

Assisted Solution

by:Harisha M G
Harisha M G earned 100 total points
ID: 16273572
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question