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
function? what kind of privilege level would be required to execute
a program with assembly in it? how would I denote that the following
code is assembly and thus shouldn't be checked for syntax errors?
------------------------------
Robert Cloud http://www.dpo.uab.edu/~rcloud rc****@uab.edu 13 2152
Robert Cloud wrote:
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
function? what kind of privilege level would be required to execute
a program with assembly in it? how would I denote that the following
code is assembly and thus shouldn't be checked for syntax errors?
maybe difficult to find out, if your search facility is broken. http://tldp.org/HOWTO/Assembly-HOWTO/gcc.html
et al.
Also, consider things like SSE intrinsics, or equivalent for your targets.
Then, if you have questions, sign up for gcc-help mailing list.
Robert Cloud wrote:
Is it possible to include assembly language routines in
C
Yes. You have just to know exactly the calling conventions of
your compiler and operating system. Do not forget that C is translated
directly into assembly in most cases.
if I'm using a compiler which has an assembler such as gcc?
You can use another assembler or gas, as you wish. All assemblers
should generate the same code.
could I
include them in a main function or would I have to write a seperate
function?
You can call your assembly routines from anywhere. Suppose you have
just wrote an assembly file with
int myAdditionFunct ion(int a,int b)
You just call it with
int result = myAdditionFunct ion(2,2);
In some compilers (such as gcc) you can also add
inline assembler with the asm() pseudo function.
Read your compiler documentation to know how to do
this. You will have to learn the gcc inline assembler
language something that is far beyond my failing
neurons :-)
what kind of privilege level would be required to execute
a program with assembly in it?
None. Unless you use processor instructions that are privileged.
If you use those, you will have to write a device driver to
run your program.
how would I denote that the following
code is assembly and thus shouldn't be checked for syntax errors?
Use the asm() pseudo instruction in the C code. But beware... it is
not very easy because you will want to avoid destroying the assembler
code that the compiler generates, so you can't just add instructions
like that withing a function, unless you save all the registers
and restore them later before leaving.
------------------------------
Robert Cloud http://www.dpo.uab.edu/~rcloud rc****@uab.edu
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32
>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
You can write an assembly-language code file, often with a name of
the form *.s or *.asm, so the front end will pass it directly to
the assembler, and then link it to C code. The details are highly
system-specific, if it's possible at all.
Or you could try to use the highly system-specific asm() extension
of your compiler, if there is one. Note that the answers to questions
like "How do I get the value of this local variable into a register?"
and "What register do I return the return value in to have C see
it?" are highly system-specific.
>include them in a main function or would I have to write a seperate function?
Why would the function have to have a specific name? *IF* you can
add assembly language to a function, you can probably add it to any
function you have source code for.
>what kind of privilege level would be required to execute a program with assembly in it?
Compiled programs (C or otherwise) have assembly in them.
Probably the same privilege level you need to execute C. The two
are about equally dangerous. On some machines you can write machine
code into an array, put the address of it into a function pointer,
and call it as though it were a function, using only C but unportable
C. Buffer overflow attacks tend to work similarly to this.
>how would I denote that the following code is assembly and thus shouldn't be checked for syntax errors?
Assembly language needs to be checked for syntax errors (just different
syntax).
jacob navia wrote:
Have you time travelled?
From: jacob navia <ja***@nospam.c om>
Newsgroups: comp.lang.c
Subject: Re: including assembly language routines in c
Date: Sun, 20 Jul 2008 22:18:57 +0200
--
Ian Collins.
Ian Collins wrote:
jacob navia wrote:
Have you time travelled?
From: jacob navia <ja***@nospam.c om>
Newsgroups: comp.lang.c
Subject: Re: including assembly language routines in c
Date: Sun, 20 Jul 2008 22:18:57 +0200
Changed my motherboard... MMMMM
I think I just forgot something :-)
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32
In article <g5**********@a ioe.org>, jacob navia <ja***@nospam.o rgwrote:
>Do not forget that C is translated directly into assembly in most cases.
What is "most cases" ??
It's been a couple of decades since I used a C compiler that translated
directly into assembly. My experience since then has been with
compilers that translate into a language-independant intermediate code
representation, the results of which were optimized. Assembly was
generated after that stage for some of the (older) compilers but
optimized intermediate code directly to object code is what I see these
days.
Working with manipulated C as an intermediate form is rather clumsy,
and by the time you have reached assembly you have lost a lot of
the opportunities for intra-procedural optimization, so an
intermediate form is common, especially in companies that make
multiple compilers, the more so if the compilers can be targetted
to multiple architectures. For example gcc goes through GENERIC and
GIMPLE on its way to RTL (Register Transfer Language).
--
"He wove a great web of knowledge, linking everything together,
and sat modestly at a switchboard at the center, eager to help."
-- Walter Kerr
Robert Cloud wrote:
>
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 function? what kind of privilege level would be
required to execute a program with assembly in it? how would I
denote that the following code is assembly and thus shouldn't
be checked for syntax errors?
Remember that the C language runs on many different machines, cpus,
operating systems, etc. However assembly code is automatically cpu
(and system) specific, and thus is not compatible. Some compilers
have an 'asm' instruction to make generating cpu/system specific
code easy, but this is NOT portable. Therefore you should ignore
anyone who tells you just to use it.
The appropriate mechanism is to have a separate module, which is to
be compiled (or assembled) for the actual destination system. This
isolates the non-portable code, and makes porting to another system
easier (just write the appropriate module). Some systems include
such a module written in portable C (and thus probably considerably
slower) so that the program can be installed anywhere, and then
optimized.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
jacob navia wrote:
Robert Cloud wrote:
>Is it possible to include assembly language routines in C
Yes. You have just to know exactly the calling conventions of
No. The results will not be C, but something cpu/system specific.
However, the point of this answer is to correct your clock. Your
message was dated 2008-07-20 22:18 +0200 and was received here on
2008-07-18 before 0600 -0400. I suspect you have am/pm misset.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
jacob navia <ja***@nospam.c omwrites:
[...]
You can call your assembly routines from anywhere. Suppose you have
just wrote an assembly file with
int myAdditionFunct ion(int a,int b)
You just call it with
int result = myAdditionFunct ion(2,2);
"int myAdditionFunct ion(int a,int b)" is assembly language? What
assembler are you using?
In any case, the ability to call routines written in other languages
is very common, but still system-specific.
[...]
Use the asm() pseudo instruction in the C code.
*If* your compiler happens to have that non-standard feature.
But beware... it is
not very easy because you will want to avoid destroying the assembler
code that the compiler generates, so you can't just add instructions
like that withing a function, unless you save all the registers
and restore them later before leaving.
Again, this is entirely system-specific, and it may not even be
possible. (Perhaps jacob didn't emphasize that point because he knew
the rest of us would do so.)
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 (intermediate language and so
on). Is there any page on internet, which makes me clear?
Thanx
|
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 these languages had to hit
against a SQL Server database
|
by: john smith |
last post by:
Hi,
If I have a large constants file and include that in a .cpp file will the
executable become large?
That is if I include a file with a bunch of constants does the executable
include all of the constants or just
the constants that are used in the .cpp file?
I am wanting a way so that only the constants that are used are included in
|
by: Stanley Sinclair |
last post by:
Has the promise of stored procedures written in VB6 been fulfilled in 8.2?
If there special syntax, and where do I find it, and where are samples?
Would it be as efficient as, say, SQL?
|
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
| |
by: Sachin |
last post by:
Hi All,
I am working on MIPS architecture and I am
compiling my project using GHS tool chain.
I want to call a assembly routine into c function.
My code is like that:
..globl asm
..ent asm
|
by: Chin Fui |
last post by:
I am writting a CD-ROM Emulator application using assembly language and link
with the VB.NET interface. But, I am not sure whether assembly language is
linkable with VB.NET.
Another question is I am now stuck in the coding, not much idea in
implementing this application. I hope to get some hints on that...
Thank you.
Chin Fui
|
by: volvox |
last post by:
hi, is it possible to access protected mode registers (EAX ,
EBX,ECX...) via assembly in C .
|
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 standard. My
question now is:
Is there a chance that such statement will become a part of C standard
in the future? In some cases using asm language is the best way to
acomplish some small task, hence integration of C and asm would greatly
enhence C,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |