473,411 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

assembly in a C language program

hi
I recently came across a C program, a snippet of which is as follows:

unsigned long get_sp(void)
{
__asm__("movl %esp,%eax");
}

int main(int argc,char **argv)
{

unsigned long sp;
sp=get_sp();
........
}

Is __asm__(...) a standard routine for calling assembly language
instructions in a C language program?

Thanks

Nov 14 '05 #1
3 2153


ca********@yahoo.com wrote:
hi
I recently came across a C program, a snippet of which is as follows:

unsigned long get_sp(void)
{
__asm__("movl %esp,%eax");
}

int main(int argc,char **argv)
{

unsigned long sp;
sp=get_sp();
........
}

Is __asm__(...) a standard routine for calling assembly language
instructions in a C language program?


No, not in standard C.
As __asm__ starts with leading underscores, it is in the
implementation's namespace, i.e. it is an identifier you should
not use. The implementation may do whatever non-standard things
it needs in order to get its job done (that is, compiling your
standard compliant code into an executable) and sometimes it
lets you access these things, too.

The C99 standard mentions the use of an "asm" keyword as common
extension, so you also might encounter
asm(....)
instead of the above -- or anything else.

All that is not portable and not standard C.
Cheers
Michae
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #2
ca********@yahoo.com wrote:

Is __asm__(...) a standard routine for calling assembly language
instructions in a C language program?


No.

C offers no support for inline assembly language, but it permits
implementations to offer such support as an extension. There is
no universally recognised agreement amongst implementors about
how, or indeed whether, to provide such an extension.
Nov 14 '05 #3
ca********@yahoo.com wrote:
hi
I recently came across a C program, a snippet of which is as follows:

unsigned long get_sp(void)
{
__asm__("movl %esp,%eax");
}

int main(int argc,char **argv)
{

unsigned long sp;
sp=get_sp();
........
}

Is __asm__(...) a standard routine for calling assembly language
instructions in a C language program?

Thanks


This small assembly snippet takes the current value of
the stack pointer (%esp) and moves it to the eax register.

Since the eax register holds the result of all functions,
this returns the value of the stack pointer as an unsigned
long.

This way of in-line assembly is commonly used in many
compilers, and allows you to do things that can't be done
in the C language. There is no standard for it but:
_asm(literal string);
__asm__(literal string);
asm(literal string);
are commonly used.

Microsoft compilers uses also
_asm {
assembly statements
}

This extension is one of the common extensions mentioned
in the C standard.

jacob
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code...
72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
26
by: nospam | last post by:
Just wondering, What do you think the difference in performance would be between (1.) Compiled C# (2.) Compiled C++ (3.) and Assembly Language And how would the mix be if some if any of...
7
by: alice | last post by:
hi all, Can anybody please tell me that how an assembly language code can be called from a program written in C?I mean what is the syntax for doing this thing? Thanks, Alice
6
by: RoSsIaCrIiLoIA | last post by:
d_0=32.000000 d_1=38.000000 Test success d_0=34.000000 d_1=42.000000 Test success d_0=1.000000 d_1=0.000000 Test success
2
by: CK | last post by:
Hi Everybody, Please construe me to embody assembly language program into c programming . Please give some conception or construe me. By CK
85
by: fermineutron | last post by:
Some compilers support __asm{ } statement which allows integration of C and raw assembly code. A while back I asked a question about such syntax and was told that __asm is not a part of a C...
2
by: Jan Althaus | last post by:
Mostly for testing reasons I'd like to see if it makes sense to chose the following approach for just-in-time compilation of shaders for a renderer: Seeing as the shaders themsefs consist mostly...
13
by: Robert Cloud | last post by:
Is it possible to include assembly language routines in C if I'm using a compiler which has an assembler such as gcc? could I include them in a main function or would I have to write a seperate...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.